@Override public Object afterDecode(mxCodec dec, Node node, Object obj) { Object cell = getFieldValue(obj, "cell"); if (cell instanceof Node) { setFieldValue(obj, "cell", dec.decodeCell((Node) cell, false)); } setFieldValue(obj, "previous", getFieldValue(obj, fieldname)); return obj; }
/** * Encodes the value of each member in then given obj * into the given node using {@link #encodeFields(mxCodec, Object, Node)} * and {@link #encodeElements(mxCodec, Object, Node)}. * * @param enc Codec that controls the encoding process. * @param obj Object to be encoded. * @param node XML node that contains the encoded object. */ protected void encodeObject(mxCodec enc, Object obj, Node node) { mxCodec.setAttribute(node, "id", enc.getId(obj)); encodeFields(enc, obj, node); encodeElements(enc, obj, node); }
/** * Calls decodeAttributes and decodeChildren for the given node. */ protected void decodeNode(mxCodec dec, Node node, Object obj) { if (node != null) { decodeAttributes(dec, node, obj); decodeChildren(dec, node, obj); } }
/** * Writes the given value into node using writePrimitiveAttribute * or writeComplexAttribute depending on the type of the value. */ protected void writeAttribute(mxCodec enc, Object obj, String attr, Object value, Node node) { value = convertValueToXml(value); if (isPrimitiveValue(value)) { writePrimitiveAttribute(enc, obj, attr, value, node); } else { writeComplexAttribute(enc, obj, attr, value, node); } }
@Override public Node afterEncode(mxCodec enc, Object obj, Node node) { if (obj instanceof mxChildChange) { mxChildChange change = (mxChildChange) obj; Object child = change.getChild(); if (isReference(obj, "child", child, true)) { // Encodes as reference (id) mxCodec.setAttribute(node, "child", enc.getId(child)); } else { // At this point, the encoder is no longer able to know which cells // are new, so we have to encode the complete cell hierarchy and // ignore the ones that are already there at decoding time. Note: // This can only be resolved by moving the notify event into the // execute of the edit. enc.encodeCell((mxICell) child, node, true); } } return node; }
/** * Returns the name used for the nodenames and lookup of the codec when * classes are encoded and nodes are decoded. For classes to work with * this the codec registry automatically adds an alias for the classname * if that is different than what this returns. The default implementation * returns the classname of the template class. * * Here is an example on how to use this for renaming mxCell nodes: * <code> * mxCodecRegistry.register(new mxCellCodec() * { * public String getName() * { * return "anotherName"; * } * }); * </code> */ public String getName() { return mxCodecRegistry.getName(getTemplate()); }
/** * Decodec all children of the given node using decodeChild. */ protected void decodeChildren(mxCodec dec, Node node, Object obj) { Node child = node.getFirstChild(); while (child != null) { if (child.getNodeType() == Node.ELEMENT_NODE && !processInclude(dec, child, obj)) { decodeChild(dec, child, obj); } child = child.getNextSibling(); } }
/** * Decodes the given XML node using {@link #decode(Node, Object)}. * * @param node XML node to be decoded. * @return Returns an object that represents the given node. */ public Object decode(Node node) { return decode(node, null); }
/** * Parses the given node into the object or returns a new object * representing the given node. * * @param dec Codec that controls the encoding process. * @param node XML node to be decoded. * @return Returns the resulting object that represents the given XML node. */ public Object decode(mxCodec dec, Node node) { return decode(dec, node, null); }
@Override public Node afterEncode(mxCodec enc, Object obj, Node node) { if (obj instanceof mxRootChange) { enc.encodeCell((mxICell) ((mxRootChange) obj).getRoot(), node, true); } return node; }
/** * Encodes the value of each member in then given obj * into the given node using {@link #encodeFields(mxCodec, Object, Node)} * and {@link #encodeElements(mxCodec, Object, Node)}. * * @param enc Codec that controls the encoding process. * @param obj Object to be encoded. * @param node XML node that contains the encoded object. */ protected void encodeObject(mxCodec enc, Object obj, Node node) { mxCodec.setAttribute(node, "id", enc.getId(obj)); encodeFields(enc, obj, node); encodeElements(enc, obj, node); }
/** * Writes the given value into node using writePrimitiveAttribute * or writeComplexAttribute depending on the type of the value. */ protected void writeAttribute(mxCodec enc, Object obj, String attr, Object value, Node node) { value = convertValueToXml(value); if (isPrimitiveValue(value)) { writePrimitiveAttribute(enc, obj, attr, value, node); } else { writeComplexAttribute(enc, obj, attr, value, node); } }
@Override public Node afterEncode(mxCodec enc, Object obj, Node node) { if (obj instanceof mxChildChange) { mxChildChange change = (mxChildChange) obj; Object child = change.getChild(); if (isReference(obj, "child", child, true)) { // Encodes as reference (id) mxCodec.setAttribute(node, "child", enc.getId(child)); } else { // At this point, the encoder is no longer able to know which cells // are new, so we have to encode the complete cell hierarchy and // ignore the ones that are already there at decoding time. Note: // This can only be resolved by moving the notify event into the // execute of the edit. enc.encodeCell((mxICell) child, node, true); } } return node; }
@Override public Object afterDecode(mxCodec dec, Node node, Object obj) { Object cell = getFieldValue(obj, "cell"); if (cell instanceof Node) { setFieldValue(obj, "cell", dec.decodeCell((Node) cell, false)); } setFieldValue(obj, "previous", getFieldValue(obj, fieldname)); return obj; }
/** * Calls decodeAttributes and decodeChildren for the given node. */ protected void decodeNode(mxCodec dec, Node node, Object obj) { if (node != null) { decodeAttributes(dec, node, obj); decodeChildren(dec, node, obj); } }
/** * Returns the name used for the nodenames and lookup of the codec when * classes are encoded and nodes are decoded. For classes to work with * this the codec registry automatically adds an alias for the classname * if that is different than what this returns. The default implementation * returns the classname of the template class. * * Here is an example on how to use this for renaming mxCell nodes: * <code> * mxCodecRegistry.register(new mxCellCodec() * { * public String getName() * { * return "anotherName"; * } * }); * </code> */ public String getName() { return mxCodecRegistry.getName(getTemplate()); }
/** * Decodes the given XML node using {@link #decode(Node, Object)}. * * @param node XML node to be decoded. * @return Returns an object that represents the given node. */ public Object decode(Node node) { return decode(node, null); }
/** * Parses the given node into the object or returns a new object * representing the given node. * * @param dec Codec that controls the encoding process. * @param node XML node to be decoded. * @return Returns the resulting object that represents the given XML node. */ public Object decode(mxCodec dec, Node node) { return decode(dec, node, null); }
@Override public Node afterEncode(mxCodec enc, Object obj, Node node) { if (obj instanceof mxRootChange) { enc.encodeCell((mxICell) ((mxRootChange) obj).getRoot(), node, true); } return node; }