1 package demo.yext.graphml;
2
3 import org.graphdrawing.graphml.reader.GraphMLParseContext;
4 import org.graphdrawing.graphml.writer.GraphMLWriteContext;
5 import org.graphdrawing.graphml.writer.XmlWriter;
6 import org.w3c.dom.NamedNodeMap;
7 import org.w3c.dom.Node;
8 import y.view.NodeRealizer;
9 import yext.graphml.graph2D.ShapeNodeRealizerSerializer;
10
11
25 public class CustomNodeRealizerSerializer extends ShapeNodeRealizerSerializer
26 {
27
30 public String getName() {
31 return "CustomNode";
32 }
33
34
35 public String getNamespaceURI() {
36 return "demo.yext.graphml.CustomNodeRealizerSerializer";
37 }
38
39
40
43 public Class getRealizerClass()
44 {
45 return CustomNodeRealizer.class;
46 }
47
48
53 public void write(NodeRealizer realizer, XmlWriter writer, GraphMLWriteContext context)
54 {
55 super.write(realizer, writer, context);
56 CustomNodeRealizer fnr = (CustomNodeRealizer)realizer;
57 writer.writeStartElement("CustomElement",getNamespaceURI())
58 .writeAttribute("value", fnr.customValue )
59 .writeEndElement();
60 }
61
62
67 public void writeAttributes(NodeRealizer realizer, XmlWriter writer, GraphMLWriteContext context)
68 {
69 super.writeAttributes(realizer, writer, context);
70 CustomNodeRealizer fnr = (CustomNodeRealizer)realizer;
71 writer.writeAttribute("customAttribute",fnr.customAttribute);
72 }
73
74
77 public void parse(NodeRealizer realizer, Node domNode, GraphMLParseContext context)
78 {
79 super.parse(realizer, domNode, context);
80
81 CustomNodeRealizer result = (CustomNodeRealizer)realizer;
82
83 NamedNodeMap nm = domNode.getAttributes();
85 Node a = nm.getNamedItem("customAttribute");
86 if (a != null) {
87 result.customAttribute = a.getNodeValue();
88 }
89
90 for(Node child = domNode.getFirstChild(); child != null; child = child.getNextSibling())
92 {
93 if (child.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE &&
94 "CustomElement".equals(child.getLocalName()))
95 {
96 nm = child.getAttributes();
97 a = nm.getNamedItem("value");
98 if (a != null)
99 {
100 result.customValue = Integer.parseInt(a.getNodeValue());
101 }
102 }
103 }
104 }
105 }
106