Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Alpha version of the GexfWriter

  • Loading branch information...
commit c5fd84cffecebfe77a1041a5a9d02756a64e31af 1 parent f4a9981
Javier Campanini authored

Showing 39 changed files with 573 additions and 321 deletions. Show diff stats Hide diff stats

  1. +1 1  pom.xml
  2. +3 0  src/main/java/com/ojn/gexf4j/core/Gexf.java
  3. +3 2 src/main/java/com/ojn/gexf4j/core/Graph.java
  4. +2 2 src/main/java/com/ojn/gexf4j/core/Node.java
  5. +6 0 src/main/java/com/ojn/gexf4j/core/data/AttributeList.java
  6. +10 0 src/main/java/com/ojn/gexf4j/core/data/AttributeValueList.java
  7. +1 3 src/main/java/com/ojn/gexf4j/core/data/Datum.java
  8. +12 0 src/main/java/com/ojn/gexf4j/core/impl/GexfImpl.java
  9. +8 16 src/main/java/com/ojn/gexf4j/core/impl/GraphImpl.java
  10. +21 6 src/main/java/com/ojn/gexf4j/core/impl/NodeImpl.java
  11. +5 7 src/main/java/com/ojn/gexf4j/core/impl/SliceableDatumBase.java
  12. +5 20 src/main/java/com/ojn/gexf4j/core/impl/StaxGraphReader.java
  13. +2 2 src/main/java/com/ojn/gexf4j/core/impl/data/AttributeImpl.java
  14. +30 0 src/main/java/com/ojn/gexf4j/core/impl/data/AttributeListImpl.java
  15. +1 0  src/main/java/com/ojn/gexf4j/core/impl/data/AttributeValueImpl.java
  16. +34 0 src/main/java/com/ojn/gexf4j/core/impl/data/AttributeValueListImpl.java
  17. +1 1  src/main/java/com/ojn/gexf4j/core/impl/dynamic/DynamicBase.java
  18. +2 8 src/main/java/com/ojn/gexf4j/core/impl/reader/EdgeEntityParser.java
  19. +2 8 src/main/java/com/ojn/gexf4j/core/impl/reader/EdgesEntityParser.java
  20. +2 6 src/main/java/com/ojn/gexf4j/core/impl/reader/GexfEntityParser.java
  21. +4 9 src/main/java/com/ojn/gexf4j/core/impl/reader/GraphEntityParser.java
  22. +2 11 src/main/java/com/ojn/gexf4j/core/impl/reader/MetaEntityParser.java
  23. +1 1  src/main/java/com/ojn/gexf4j/core/impl/viz/NodeShapeImpl.java
  24. +5 1 src/main/java/com/ojn/gexf4j/core/impl/writer/AbstractEntityWriter.java
  25. +14 7 src/main/java/com/ojn/gexf4j/core/impl/writer/GexfEntityWriter.java
  26. +7 2 src/main/java/com/ojn/gexf4j/core/impl/writer/GraphEntityWriter.java
  27. +4 11 src/main/java/com/ojn/gexf4j/core/impl/writer/NodeEntityWriter.java
  28. +17 11 src/test/java/com/ojn/gexf4j/core/GraphWriterTest.java
  29. +2 2 src/test/java/com/ojn/gexf4j/core/impl/StaxGraphWriterTest.java
  30. +12 15 src/test/java/com/ojn/gexf4j/core/testgraphs/BasicGraphBuilder.java
  31. +49 45 src/test/java/com/ojn/gexf4j/core/testgraphs/DataGraphBuilder.java
  32. +100 71 src/test/java/com/ojn/gexf4j/core/testgraphs/DynamicGraphBuilder.java
  33. +26 0 src/test/java/com/ojn/gexf4j/core/testgraphs/GexfBuilder.java
  34. +0 10 src/test/java/com/ojn/gexf4j/core/testgraphs/GraphBuilder.java
  35. +52 0 src/test/java/com/ojn/gexf4j/core/testgraphs/HierarchyInlineBuilder.java
  36. +60 0 src/test/java/com/ojn/gexf4j/core/testgraphs/HierarchyPIDBuilder.java
  37. +0 43 src/test/java/com/ojn/gexf4j/core/testgraphs/MetaDataGraphBuilder.java
  38. +31 0 src/test/java/com/ojn/gexf4j/core/testgraphs/PhylogenyBuilder.java
  39. +36 0 src/test/java/com/ojn/gexf4j/core/testgraphs/VisualizationBuilder.java
2  pom.xml
@@ -3,7 +3,7 @@
3 3 <modelVersion>4.0.0</modelVersion>
4 4 <groupId>com.ojn.gexf4j</groupId>
5 5 <artifactId>gexf4j-core</artifactId>
6   - <version>0.1.0</version>
  6 + <version>0.2.0-ALPHA</version>
7 7 <name>gexf4j-core</name>
8 8 <build>
9 9 <plugins>
3  src/main/java/com/ojn/gexf4j/core/Gexf.java
@@ -12,4 +12,7 @@
12 12 Metadata getMetadata();
13 13
14 14 Graph getGraph();
  15 +
  16 + boolean hasVisualization();
  17 + Gexf setVisualization(boolean viz);
15 18 }
5 src/main/java/com/ojn/gexf4j/core/Graph.java
... ... @@ -1,5 +1,7 @@
1 1 package com.ojn.gexf4j.core;
2 2
  3 +import java.util.List;
  4 +
3 5 import com.ojn.gexf4j.core.data.AttributeList;
4 6 import com.ojn.gexf4j.core.dynamic.Dynamic;
5 7 import com.ojn.gexf4j.core.dynamic.TimeType;
@@ -18,6 +20,5 @@
18 20 TimeType getTimeType();
19 21 Graph setTimeType(TimeType timeType);
20 22
21   - AttributeList getNodeAttributes();
22   - AttributeList getEdgeAttributes();
  23 + List<AttributeList> getAttributeLists();
23 24 }
4 src/main/java/com/ojn/gexf4j/core/Node.java
@@ -43,6 +43,6 @@
43 43
44 44 boolean hasPID();
45 45 Node clearPID();
46   - Node getPID();
47   - Node setPID(Node pid);
  46 + String getPID();
  47 + Node setPID(String pid);
48 48 }
6 src/main/java/com/ojn/gexf4j/core/data/AttributeList.java
@@ -11,4 +11,10 @@
11 11
12 12 Mode getMode();
13 13 AttributeList setMode(Mode mode);
  14 +
  15 + Attribute createAttribute(AttributeType type, String title);
  16 + Attribute createAttribute(String id, AttributeType type, String title);
  17 +
  18 + AttributeList addAttribute(AttributeType type, String title);
  19 + AttributeList addAttribute(String id, AttributeType type, String title);
14 20 }
10 src/main/java/com/ojn/gexf4j/core/data/AttributeValueList.java
... ... @@ -0,0 +1,10 @@
  1 +package com.ojn.gexf4j.core.data;
  2 +
  3 +import java.util.List;
  4 +
  5 +public interface AttributeValueList extends List<AttributeValue> {
  6 +
  7 + AttributeValueList addValue(Attribute attribute, String value);
  8 +
  9 + AttributeValue createValue(Attribute attribute, String value);
  10 +}
4 src/main/java/com/ojn/gexf4j/core/data/Datum.java
... ... @@ -1,8 +1,6 @@
1 1 package com.ojn.gexf4j.core.data;
2 2
3   -import java.util.List;
4   -
5 3 public interface Datum {
6 4
7   - List<AttributeValue> getAttributeValues();
  5 + AttributeValueList getAttributeValues();
8 6 }
12 src/main/java/com/ojn/gexf4j/core/impl/GexfImpl.java
@@ -13,6 +13,7 @@
13 13 private String variant = null;
14 14 private Graph graph = null;
15 15 private Metadata meta = null;
  16 + private boolean viz = false;
16 17
17 18 public GexfImpl() {
18 19 graph = new GraphImpl();
@@ -58,4 +59,15 @@ public Gexf setVariant(String variant) {
58 59 this.variant = variant;
59 60 return this;
60 61 }
  62 +
  63 + @Override
  64 + public boolean hasVisualization() {
  65 + return viz;
  66 + }
  67 +
  68 + @Override
  69 + public Gexf setVisualization(boolean viz) {
  70 + this.viz = viz;
  71 + return this;
  72 + }
61 73 }
24 src/main/java/com/ojn/gexf4j/core/impl/GraphImpl.java
@@ -12,25 +12,21 @@
12 12 import com.ojn.gexf4j.core.IDType;
13 13 import com.ojn.gexf4j.core.Mode;
14 14 import com.ojn.gexf4j.core.Node;
15   -import com.ojn.gexf4j.core.data.AttributeClass;
16 15 import com.ojn.gexf4j.core.data.AttributeList;
17 16 import com.ojn.gexf4j.core.dynamic.TimeType;
18   -import com.ojn.gexf4j.core.impl.data.AttributeListImpl;
19 17 import com.ojn.gexf4j.core.impl.dynamic.DynamicBase;
20 18
21 19 public class GraphImpl extends DynamicBase<Graph> implements Graph {
22 20
23 21 private EdgeType edgeType = EdgeType.UNDIRECTED;
24   - private AttributeList edgeAttributeList = null;
25   - private AttributeList nodeAttributeList = null;
  22 + private List<AttributeList> attributeLists = null;
26 23 private IDType idType = IDType.STRING;
27 24 private Mode mode = Mode.STATIC;
28 25 private List<Node> nodes = null;
29 26 private TimeType timeType = TimeType.DATE;
30 27
31 28 public GraphImpl() {
32   - edgeAttributeList = new AttributeListImpl(AttributeClass.EDGE);
33   - nodeAttributeList = new AttributeListImpl(AttributeClass.NODE);
  29 + attributeLists = new ArrayList<AttributeList>();
34 30 nodes = new ArrayList<Node>();
35 31 }
36 32
@@ -45,11 +41,6 @@ public EdgeType getDefaultEdgeType() {
45 41 }
46 42
47 43 @Override
48   - public AttributeList getEdgeAttributes() {
49   - return edgeAttributeList;
50   - }
51   -
52   - @Override
53 44 public IDType getIDType() {
54 45 return idType;
55 46 }
@@ -60,11 +51,6 @@ public Mode getMode() {
60 51 }
61 52
62 53 @Override
63   - public AttributeList getNodeAttributes() {
64   - return nodeAttributeList;
65   - }
66   -
67   - @Override
68 54 public TimeType getTimeType() {
69 55 return timeType;
70 56 }
@@ -114,6 +100,7 @@ public Node createNode(String id) {
114 100
115 101 for (Node n : nodes) {
116 102 rv.addAll(n.getEdges());
  103 + rv.addAll(n.getAllEdges());
117 104 }
118 105
119 106 return rv;
@@ -123,4 +110,9 @@ public Node createNode(String id) {
123 110 public List<Node> getNodes() {
124 111 return nodes;
125 112 }
  113 +
  114 + @Override
  115 + public List<AttributeList> getAttributeLists() {
  116 + return attributeLists;
  117 + }
126 118 }
27 src/main/java/com/ojn/gexf4j/core/impl/NodeImpl.java
@@ -9,7 +9,9 @@
9 9
10 10 import com.ojn.gexf4j.core.Edge;
11 11 import com.ojn.gexf4j.core.Node;
  12 +import com.ojn.gexf4j.core.impl.viz.NodeShapeImpl;
12 13 import com.ojn.gexf4j.core.viz.Color;
  14 +import com.ojn.gexf4j.core.viz.NodeShape;
13 15 import com.ojn.gexf4j.core.viz.NodeShapeEntity;
14 16 import com.ojn.gexf4j.core.viz.Position;
15 17
@@ -18,7 +20,7 @@
18 20 private String id = "";
19 21 private String label = "";
20 22 private Color color = null;
21   - private Node pid = null;
  23 + private String pid = null;
22 24 private Position position = null;
23 25 private NodeShapeEntity shape = null;
24 26 private float size = Float.MIN_VALUE;
@@ -38,6 +40,7 @@ public NodeImpl(String id) {
38 40 this.nodes = new ArrayList<Node>();
39 41 this.edges = new ArrayList<Edge>();
40 42 this.parentForList = new ArrayList<Node>();
  43 + this.shape = new NodeShapeImpl();
41 44 }
42 45
43 46 @Override
@@ -109,7 +112,7 @@ public String getLabel() {
109 112 }
110 113
111 114 @Override
112   - public Node getPID() {
  115 + public String getPID() {
113 116 checkState(hasPID(), "PID has not been set.");
114 117 return pid;
115 118 }
@@ -127,7 +130,6 @@ public Position getPosition() {
127 130
128 131 @Override
129 132 public NodeShapeEntity getShapeEntity() {
130   - checkState(hasShape(), "Shape has not been set.");
131 133 return shape;
132 134 }
133 135
@@ -149,7 +151,7 @@ public boolean hasPosition() {
149 151
150 152 @Override
151 153 public boolean hasShape() {
152   - return (shape != null);
  154 + return (shape.getNodeShape() != NodeShape.NOTSET);
153 155 }
154 156
155 157 @Override
@@ -165,8 +167,9 @@ public Node setLabel(String label) {
165 167 }
166 168
167 169 @Override
168   - public Node setPID(Node pid) {
  170 + public Node setPID(String pid) {
169 171 checkArgument(pid != null, "PID cannot be null.");
  172 + checkArgument(!pid.trim().isEmpty(), "PID cannot be empty or blank.");
170 173 this.pid = pid;
171 174 return this;
172 175 }
@@ -240,9 +243,21 @@ public Node createNode(String id) {
240 243 List<Edge> rv = new ArrayList<Edge>();
241 244
242 245 for (Node n : getNodes()) {
243   - rv.addAll(n.getEdges());
  246 + _getEdges(rv, n);
244 247 }
245 248
246 249 return rv;
247 250 }
  251 +
  252 + private List<Edge> _getEdges(List<Edge> soFar, Node n) {
  253 + // add the nodes' edges
  254 + soFar.addAll(n.getEdges());
  255 +
  256 + // call this function on all of the sub nodes
  257 + for (Node subNode : n.getNodes()) {
  258 + _getEdges(soFar, subNode);
  259 + }
  260 +
  261 + return soFar;
  262 + }
248 263 }
12 src/main/java/com/ojn/gexf4j/core/impl/SliceableDatumBase.java
... ... @@ -1,22 +1,20 @@
1 1 package com.ojn.gexf4j.core.impl;
2 2
3   -import java.util.ArrayList;
4   -import java.util.List;
5   -
6 3 import com.ojn.gexf4j.core.SlicableDatum;
7   -import com.ojn.gexf4j.core.data.AttributeValue;
  4 +import com.ojn.gexf4j.core.data.AttributeValueList;
  5 +import com.ojn.gexf4j.core.impl.data.AttributeValueListImpl;
8 6 import com.ojn.gexf4j.core.impl.dynamic.SlicableBase;
9 7
10 8 public abstract class SliceableDatumBase<T extends Object> extends SlicableBase<T> implements SlicableDatum<T> {
11 9
12   - private List<AttributeValue> attributes = null;
  10 + private AttributeValueList attributes = null;
13 11
14 12 public SliceableDatumBase() {
15   - attributes = new ArrayList<AttributeValue>();
  13 + attributes = new AttributeValueListImpl();
16 14 }
17 15
18 16 @Override
19   - public List<AttributeValue> getAttributeValues() {
  17 + public AttributeValueList getAttributeValues() {
20 18 return attributes;
21 19 }
22 20 }
25 src/main/java/com/ojn/gexf4j/core/impl/StaxGraphReader.java
@@ -3,30 +3,15 @@
3 3 import java.io.IOException;
4 4 import java.io.InputStream;
5 5
6   -import javax.xml.stream.XMLInputFactory;
7   -import javax.xml.stream.XMLStreamException;
8   -import javax.xml.stream.XMLStreamReader;
9   -
10   -import com.ojn.gexf4j.core.Graph;
  6 +import com.ojn.gexf4j.core.Gexf;
11 7 import com.ojn.gexf4j.core.GexfReader;
12   -import com.ojn.gexf4j.core.impl.reader.GexfEntityParser;
13 8
14 9 public class StaxGraphReader implements GexfReader {
15 10
16 11 @Override
17   - public Graph readFromStream(InputStream in) throws IOException {
18   -
19   - try {
20   - XMLInputFactory inputFactory = XMLInputFactory.newInstance();
21   - XMLStreamReader reader = inputFactory.createXMLStreamReader(in);
22   -
23   - GexfEntityParser gexfParser = new GexfEntityParser(reader);
24   -
25   - return gexfParser.getGraph();
26   -
27   - } catch (XMLStreamException e) {
28   - e.printStackTrace();
29   - return null;
30   - }
  12 + public Gexf readFromStream(InputStream in) throws IOException {
  13 + // TODO Auto-generated method stub
  14 + return null;
31 15 }
  16 +
32 17 }
4 src/main/java/com/ojn/gexf4j/core/impl/data/AttributeImpl.java
@@ -20,9 +20,9 @@
20 20
21 21 public AttributeImpl(String id, AttributeType type, String title) {
22 22 checkArgument(id != null, "ID cannot be null.");
23   - checkArgument(id.trim().isEmpty(), "ID cannot be null or blank.");
  23 + checkArgument(!id.trim().isEmpty(), "ID cannot be empty or blank.");
24 24 checkArgument(title != null, "Title cannot be null.");
25   - checkArgument(title.trim().isEmpty(), "Title cannot be null or blank.");
  25 + checkArgument(!title.trim().isEmpty(), "Title cannot be null or blank.");
26 26
27 27 this.id = id;
28 28 this.type = type;
30 src/main/java/com/ojn/gexf4j/core/impl/data/AttributeListImpl.java
@@ -5,11 +5,13 @@
5 5
6 6 import java.util.ArrayList;
7 7 import java.util.Date;
  8 +import java.util.UUID;
8 9
9 10 import com.ojn.gexf4j.core.Mode;
10 11 import com.ojn.gexf4j.core.data.Attribute;
11 12 import com.ojn.gexf4j.core.data.AttributeClass;
12 13 import com.ojn.gexf4j.core.data.AttributeList;
  14 +import com.ojn.gexf4j.core.data.AttributeType;
13 15
14 16 public class AttributeListImpl extends ArrayList<Attribute> implements AttributeList {
15 17 private static final long serialVersionUID = 8240096318919688740L;
@@ -90,4 +92,32 @@ public AttributeList setStartDate(Date startDate) {
90 92 this.endDate = startDate;
91 93 return this;
92 94 }
  95 +
  96 + @Override
  97 + public Attribute createAttribute(AttributeType type, String title) {
  98 + return createAttribute(UUID.randomUUID().toString(), type, title);
  99 + }
  100 +
  101 + @Override
  102 + public Attribute createAttribute(String id, AttributeType type, String title) {
  103 + checkArgument(id != null, "ID cannot be null.");
  104 + checkArgument(!id.trim().isEmpty(), "ID cannot be empty or blank.");
  105 + checkArgument(title != null, "Title cannot be null.");
  106 + checkArgument(!title.trim().isEmpty(), "Title cannot be empty or blank.");
  107 +
  108 + Attribute rv = new AttributeImpl(id, type, title);
  109 + this.add(rv);
  110 + return rv;
  111 + }
  112 +
  113 + @Override
  114 + public AttributeList addAttribute(AttributeType type, String title) {
  115 + return addAttribute(UUID.randomUUID().toString(), type, title);
  116 + }
  117 +
  118 + @Override
  119 + public AttributeList addAttribute(String id, AttributeType type, String title) {
  120 + createAttribute(id, type, title);
  121 + return this;
  122 + }
93 123 }
1  src/main/java/com/ojn/gexf4j/core/impl/data/AttributeValueImpl.java
@@ -34,6 +34,7 @@ public String getValue() {
34 34 @Override
35 35 public AttributeValue setValue(String value) {
36 36 checkArgument(value != null, "Value cannot be null.");
  37 + this.value = value;
37 38 return this;
38 39 }
39 40 }
34 src/main/java/com/ojn/gexf4j/core/impl/data/AttributeValueListImpl.java
... ... @@ -0,0 +1,34 @@
  1 +package com.ojn.gexf4j.core.impl.data;
  2 +
  3 +import static com.google.common.base.Preconditions.checkArgument;
  4 +
  5 +import java.util.ArrayList;
  6 +
  7 +import com.ojn.gexf4j.core.data.Attribute;
  8 +import com.ojn.gexf4j.core.data.AttributeValue;
  9 +import com.ojn.gexf4j.core.data.AttributeValueList;
  10 +
  11 +public class AttributeValueListImpl extends ArrayList<AttributeValue> implements AttributeValueList {
  12 + private static final long serialVersionUID = 7730475001078826140L;
  13 +
  14 + public AttributeValueListImpl() {
  15 + // do nothing
  16 + }
  17 +
  18 + @Override
  19 + public AttributeValueList addValue(Attribute attribute, String value) {
  20 + createValue(attribute, value);
  21 + return this;
  22 + }
  23 +
  24 + @Override
  25 + public AttributeValue createValue(Attribute attribute, String value) {
  26 + checkArgument(value != null, "Value cannot be null.");
  27 +
  28 + AttributeValue rv = new AttributeValueImpl(attribute);
  29 + rv.setValue(value);
  30 + add(rv);
  31 +
  32 + return rv;
  33 + }
  34 +}
2  src/main/java/com/ojn/gexf4j/core/impl/dynamic/DynamicBase.java
@@ -61,7 +61,7 @@ public T setEndDate(Date endDate) {
61 61 @Override
62 62 public T setStartDate(Date startDate) {
63 63 checkArgument(startDate != null, "Start Date cannot be null.");
64   - this.endDate = startDate;
  64 + this.startDate = startDate;
65 65 return getSelf();
66 66 }
67 67 }
10 src/main/java/com/ojn/gexf4j/core/impl/reader/EdgeEntityParser.java
... ... @@ -1,13 +1,7 @@
1 1 package com.ojn.gexf4j.core.impl.reader;
2 2
3   -import javax.xml.stream.XMLStreamReader;
4 3
5   -import com.ojn.gexf4j.core.Edge;
6   -import com.ojn.gexf4j.core.EdgeType;
7   -import com.ojn.gexf4j.core.Graph;
8   -import com.ojn.gexf4j.core.Node;
9   -
10   -public class EdgeEntityParser extends AbstractEntityParser<Edge> {
  4 +public class EdgeEntityParser { /*extends AbstractEntityParser<Edge> {
11 5 private static final String ATTRIB_ID = "id";
12 6 private static final String ATTRIB_LABEL = "label";
13 7 private static final String ATTRIB_SOURCE = "source";
@@ -76,5 +70,5 @@ protected void onEndElement() {
76 70 e.setEdgeType(type);
77 71 e.setLabel(label);
78 72 e.setWeight(weight);
79   - }
  73 + }*/
80 74 }
10 src/main/java/com/ojn/gexf4j/core/impl/reader/EdgesEntityParser.java
... ... @@ -1,13 +1,7 @@
1 1 package com.ojn.gexf4j.core.impl.reader;
2 2
3   -import java.util.List;
4 3
5   -import javax.xml.stream.XMLStreamReader;
6   -
7   -import com.ojn.gexf4j.core.Edge;
8   -import com.ojn.gexf4j.core.Graph;
9   -
10   -public class EdgesEntityParser extends AbstractEntityParser<List<Edge>> {
  4 +public class EdgesEntityParser { /*extends AbstractEntityParser<List<Edge>> {
11 5 private static final String ENTITY_EDGE = "edge";
12 6
13 7 private Graph graph = null;
@@ -43,5 +37,5 @@ protected void onOther(XMLStreamReader reader, int eventType) {
43 37 @Override
44 38 protected void onEndElement() {
45 39 // do nothing
46   - }
  40 + }*/
47 41 }
8 src/main/java/com/ojn/gexf4j/core/impl/reader/GexfEntityParser.java
... ... @@ -1,11 +1,7 @@
1 1 package com.ojn.gexf4j.core.impl.reader;
2 2
3   -import javax.xml.stream.XMLStreamReader;
4 3
5   -import com.ojn.gexf4j.core.Graph;
6   -import com.ojn.gexf4j.core.impl.GraphImpl;
7   -
8   -public class GexfEntityParser extends AbstractEntityParser<Graph> {
  4 +public class GexfEntityParser { /*extends AbstractEntityParser<Graph> {
9 5 private static final String ATTRIB_VERSION = "version";
10 6 private static final String ENTITY_META = "meta";
11 7 private static final String ENTITY_GRAPH = "graph";
@@ -52,5 +48,5 @@ protected void onOther(XMLStreamReader reader, int eventType) {
52 48 @Override
53 49 protected void onEndElement() {
54 50 // do nothing
55   - }
  51 + } */
56 52 }
13 src/main/java/com/ojn/gexf4j/core/impl/reader/GraphEntityParser.java
... ... @@ -1,12 +1,7 @@
1 1 package com.ojn.gexf4j.core.impl.reader;
2 2
3   -import javax.xml.stream.XMLStreamReader;
4 3
5   -import com.ojn.gexf4j.core.EdgeType;
6   -import com.ojn.gexf4j.core.Graph;
7   -import com.ojn.gexf4j.core.Mode;
8   -
9   -public class GraphEntityParser extends AbstractEntityParser<Graph> {
  4 +public class GraphEntityParser { /*extends AbstractEntityParser<Graph> {
10 5 private static final String ATTRIB_EDGETYPE = "defaultedgetype";
11 6 private static final String ATTRIB_MODE = "mode";
12 7 private static final String ENTITY_ATTRIBUTES = "attributes";
@@ -34,12 +29,12 @@ protected void onAttribute(String name, String value) {
34 29 @Override
35 30 protected void onStartElement(XMLStreamReader reader) {
36 31 if (ENTITY_ATTRIBUTES.equalsIgnoreCase(reader.getLocalName())) {
37   - /*AttributesEntityParser aep = new AttributesEntityParser(reader);
  32 + AttributesEntityParser aep = new AttributesEntityParser(reader);
38 33 if (aep.getAttClass() == AttributeClass.NODE) {
39 34 attribsNodes = aep.getEntity();
40 35 } else if (aep.getAttClass() == AttributeClass.EDGE) {
41 36 attribsEdges = aep.getEntity();
42   - }*/
  37 + }
43 38
44 39 } else if (ENTITY_NODES.equalsIgnoreCase(reader.getLocalName())) {
45 40 new NodesEntityParser(reader, graph);
@@ -62,5 +57,5 @@ protected void onOther(XMLStreamReader reader, int eventType) {
62 57 @Override
63 58 protected void onEndElement() {
64 59 // do nothing
65   - }
  60 + } */
66 61 }
13 src/main/java/com/ojn/gexf4j/core/impl/reader/MetaEntityParser.java
... ... @@ -1,16 +1,7 @@
1 1 package com.ojn.gexf4j.core.impl.reader;
2 2
3   -import java.text.ParseException;
4   -import java.text.SimpleDateFormat;
5 3
6   -import javax.xml.stream.XMLStreamReader;
7   -
8   -import com.google.common.base.Splitter;
9   -import com.google.common.collect.Iterables;
10   -import com.ojn.gexf4j.core.Graph;
11   -import com.ojn.gexf4j.core.Metadata;
12   -
13   -public class MetaEntityParser extends AbstractEntityParser<Metadata> {
  4 +public class MetaEntityParser { /*extends AbstractEntityParser<Metadata> {
14 5 private static final String ENTITY_CREATOR = "creator";
15 6 private static final String ENTITY_DESCRIPTION = "description";
16 7 private static final String ENTITY_KEYWORDS = "keywords";
@@ -73,5 +64,5 @@ protected void onCharacters(XMLStreamReader reader) {
73 64 @Override
74 65 protected void onOther(XMLStreamReader reader, int eventType) {
75 66 // do nothing
76   - }
  67 + } */
77 68 }
2  src/main/java/com/ojn/gexf4j/core/impl/viz/NodeShapeImpl.java
@@ -7,7 +7,7 @@
7 7
8 8 public class NodeShapeImpl implements NodeShapeEntity {
9 9
10   - private NodeShape shape = NodeShape.DISC;
  10 + private NodeShape shape = NodeShape.NOTSET;
11 11 private String uri = null;
12 12
13 13 public NodeShapeImpl() {
6 src/main/java/com/ojn/gexf4j/core/impl/writer/AbstractEntityWriter.java
@@ -35,7 +35,7 @@ public AbstractEntityWriter(XMLStreamWriter writer, T entity) {
35 35
36 36 protected void write() {
37 37 try {
38   - writer.writeStartElement(getElementName());
  38 + writeStartElement();
39 39
40 40 writeAttributes();
41 41 writeElements();
@@ -46,4 +46,8 @@ protected void write() {
46 46 e.printStackTrace();
47 47 }
48 48 }
  49 +
  50 + protected void writeStartElement() throws XMLStreamException {
  51 + writer.writeStartElement(getElementName());
  52 + }
49 53 }
21 src/main/java/com/ojn/gexf4j/core/impl/writer/GexfEntityWriter.java
@@ -9,9 +9,10 @@
9 9 private static final String ENTITY = "gexf";
10 10 private static final String ATTRIBUTE_VERSION = "version";
11 11 private static final String ATTRIBUTE_VARIANT = "variant";
12   - private static final String ATTRIBUTE_XMLNS = "xmlns";
13   - private static final String VALUE_XMLNS = "http://www.gexf.net/1.1draft";
14   -
  12 + private static final String XMLNS_URL = "http://www.gexf.net/1.1draft";
  13 + private static final String XMLNS_VIZ = "viz";
  14 + private static final String XMLNS_VIZ_URL = "http://www.gexf.net/1.1draft/viz";
  15 +
15 16 public GexfEntityWriter(XMLStreamWriter writer, Gexf entity) {
16 17 super(writer, entity);
17 18 write();
@@ -28,10 +29,6 @@ protected void writeAttributes() throws XMLStreamException {
28 29 ATTRIBUTE_VERSION,
29 30 entity.getVersion());
30 31
31   - writer.writeAttribute(
32   - ATTRIBUTE_XMLNS,
33   - VALUE_XMLNS);
34   -
35 32 if (entity.hasVariant()) {
36 33 writer.writeAttribute(
37 34 ATTRIBUTE_VARIANT,
@@ -40,6 +37,16 @@ protected void writeAttributes() throws XMLStreamException {
40 37 }
41 38
42 39 @Override
  40 + protected void writeStartElement() throws XMLStreamException {
  41 + writer.writeStartElement(getElementName());
  42 + writer.writeDefaultNamespace(XMLNS_URL);
  43 +
  44 + if (entity.hasVisualization()) {
  45 + writer.writeNamespace(XMLNS_VIZ, XMLNS_VIZ_URL);
  46 + }
  47 + }
  48 +
  49 + @Override
43 50 protected void writeElements() throws XMLStreamException {
44 51 new MetadataEntityWriter(writer, entity.getMetadata());
45 52 new GraphEntityWriter(writer, entity.getGraph());
9 src/main/java/com/ojn/gexf4j/core/impl/writer/GraphEntityWriter.java
@@ -4,6 +4,7 @@
4 4 import javax.xml.stream.XMLStreamWriter;
5 5
6 6 import com.ojn.gexf4j.core.Graph;
  7 +import com.ojn.gexf4j.core.data.AttributeList;
7 8
8 9 public class GraphEntityWriter extends DynamicEntityWriter<Graph> {
9 10 private static final String ENTITY = "graph";
@@ -41,13 +42,17 @@ protected void writeAttributes() throws XMLStreamException {
41 42 entity.getTimeType().toString().toLowerCase());
42 43
43 44 AbstractEntityWriter.writerTimeType = entity.getTimeType();
  45 + super.writeAttributes();
44 46 }
45 47
46 48 @Override
47 49 protected void writeElements() throws XMLStreamException {
48   - new AttributesEntityWriter(writer, entity.getNodeAttributes());
49   - new AttributesEntityWriter(writer, entity.getEdgeAttributes());
  50 + for (AttributeList attList : entity.getAttributeLists()) {
  51 + new AttributesEntityWriter(writer, attList);
  52 + }
  53 +
50 54 new NodesEntityWriter(writer, entity.getNodes());
51 55 new EdgesEntityWriter(writer, entity.getAllEdges());
  56 + super.writeElements();
52 57 }
53 58 }
15 src/main/java/com/ojn/gexf4j/core/impl/writer/NodeEntityWriter.java
@@ -36,7 +36,7 @@ protected void writeAttributes() throws XMLStreamException {
36 36 if (entity.hasPID()) {
37 37 writer.writeAttribute(
38 38 ATTRIB_PID,
39   - entity.getPID().getId());
  39 + entity.getPID());
40 40 }
41 41 }
42 42
@@ -65,14 +65,7 @@ protected void writeElements() throws XMLStreamException {
65 65 new ParentsEntityWriter(writer, entity.getParentForList());
66 66
67 67 new NodesEntityWriter(writer, entity.getNodes());
68   - new EdgesEntityWriter(writer, entity.getAllEdges());
  68 + // TODO: Verify this is supposed to be commented out.
  69 + // new EdgesEntityWriter(writer, entity.getAllEdges());
69 70 }
70   -}
71   -
72   -
73   -
74   -/*
75   -edge
76   -viz:thickness ???
77   -viz:shape [viz:edge-shape] ???
78   -*/
  71 +}
28 src/test/java/com/ojn/gexf4j/core/GraphWriterTest.java
@@ -23,8 +23,11 @@
23 23 import com.ojn.gexf4j.core.testgraphs.BasicGraphBuilder;
24 24 import com.ojn.gexf4j.core.testgraphs.DataGraphBuilder;
25 25 import com.ojn.gexf4j.core.testgraphs.DynamicGraphBuilder;
26   -import com.ojn.gexf4j.core.testgraphs.GraphBuilder;
27   -import com.ojn.gexf4j.core.testgraphs.MetaDataGraphBuilder;
  26 +import com.ojn.gexf4j.core.testgraphs.GexfBuilder;
  27 +import com.ojn.gexf4j.core.testgraphs.HierarchyInlineBuilder;
  28 +import com.ojn.gexf4j.core.testgraphs.HierarchyPIDBuilder;
  29 +import com.ojn.gexf4j.core.testgraphs.PhylogenyBuilder;
  30 +import com.ojn.gexf4j.core.testgraphs.VisualizationBuilder;
28 31
29 32 @RunWith(Parameterized.class)
30 33 public abstract class GraphWriterTest {
@@ -32,35 +35,38 @@
32 35 protected abstract String getFileNamePrefix();
33 36 protected abstract GexfWriter newGraphWriter();
34 37
35   - protected GraphBuilder builder = null;
  38 + protected GexfBuilder builder = null;
36 39
37 40 @Parameters
38 41 public static List<Object[]> getData() {
39 42 List<Object[]> rv = new ArrayList<Object[]>();
40 43
41   - rv.add(new GraphBuilder[] { new BasicGraphBuilder() });
42   - rv.add(new GraphBuilder[] { new DataGraphBuilder() });
43   - rv.add(new GraphBuilder[] { new MetaDataGraphBuilder() });
44   - rv.add(new GraphBuilder[] { new DynamicGraphBuilder() });
  44 + rv.add(new GexfBuilder[] { new BasicGraphBuilder() });
  45 + rv.add(new GexfBuilder[] { new DataGraphBuilder() });
  46 + rv.add(new GexfBuilder[] { new DynamicGraphBuilder() });
  47 + rv.add(new GexfBuilder[] { new HierarchyInlineBuilder() });
  48 + rv.add(new GexfBuilder[] { new HierarchyPIDBuilder() });
  49 + rv.add(new GexfBuilder[] { new PhylogenyBuilder() });
  50 + rv.add(new GexfBuilder[] { new VisualizationBuilder() });
45 51
46 52 return rv;
47 53 }
48 54
49   - public GraphWriterTest(GraphBuilder builder) {
  55 + public GraphWriterTest(GexfBuilder builder) {
50 56 this.builder = builder;
51 57 }
52 58
53 59 @Test
54 60 public void writeToStream() throws SAXException, IOException {
55   - Graph g = builder.buildGraph();
  61 + Gexf gexf = builder.buildGexf();
56 62 GexfWriter gw = newGraphWriter();
57 63 String fileName = "target/" + getFileNamePrefix() + "_" + builder.getSuffix() + ".gexf";
58 64 File f = new File(fileName);
59 65 FileOutputStream fos = new FileOutputStream(f);
60 66
61   - gw.writeToStream(g, fos);
  67 + gw.writeToStream(gexf, fos);
62 68
63   - URL schemaFile = new URL(builder.getXsdUrl());
  69 + URL schemaFile = new URL(builder.getSchemaUrl());
64 70 Source xmlFile = new StreamSource(f);
65 71 SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
66 72 Schema schema = schemaFactory.newSchema(schemaFile);
4 src/test/java/com/ojn/gexf4j/core/impl/StaxGraphWriterTest.java
@@ -2,11 +2,11 @@
2 2
3 3 import com.ojn.gexf4j.core.GexfWriter;
4 4 import com.ojn.gexf4j.core.GraphWriterTest;
5   -import com.ojn.gexf4j.core.testgraphs.GraphBuilder;
  5 +import com.ojn.gexf4j.core.testgraphs.GexfBuilder;
6 6
7 7 public class StaxGraphWriterTest extends GraphWriterTest {
8 8
9   - public StaxGraphWriterTest(GraphBuilder builder) {
  9 + public StaxGraphWriterTest(GexfBuilder builder) {
10 10 super(builder);
11 11 }
12 12
27 src/test/java/com/ojn/gexf4j/core/testgraphs/BasicGraphBuilder.java
... ... @@ -1,10 +1,11 @@
1 1 package com.ojn.gexf4j.core.testgraphs;
2 2
  3 +import com.ojn.gexf4j.core.Gexf;
3 4 import com.ojn.gexf4j.core.Graph;
4 5 import com.ojn.gexf4j.core.Node;
5   -import com.ojn.gexf4j.core.impl.GraphImpl;
  6 +import com.ojn.gexf4j.core.impl.GexfImpl;
6 7
7   -public class BasicGraphBuilder implements GraphBuilder {
  8 +public class BasicGraphBuilder extends GexfBuilder {
8 9
9 10 @Override
10 11 public String getSuffix() {
@@ -12,21 +13,17 @@ public String getSuffix() {
12 13 }
13 14
14 15 @Override
15   - public String getXsdUrl() {
16   - return "http://gexf.net/1.1draft/gexf.xsd";
17   - }
18   -
19   - @Override
20   - public Graph buildGraph() {
21   - Graph g = new GraphImpl();
  16 + public Gexf buildGexf() {
  17 + Gexf gexf = new GexfImpl();
  18 + Graph g = gexf.getGraph();
22 19
23   - Node n1 = g.createNode();
24   - Node n2 = g.createNode();
25   - Node n3 = g.createNode();
  20 + Node hello = g.createNode("0")
  21 + .setLabel("Hello");
  22 + Node world = g.createNode("1")
  23 + .setLabel("World");
26 24
27   - n1.connectTo(n2);
28   - n1.connectTo(n3);
  25 + hello.connectTo("0", world);
29 26
30   - return g;
  27 + return gexf;
31 28 }
32 29 }
94 src/test/java/com/ojn/gexf4j/core/testgraphs/DataGraphBuilder.java
... ... @@ -1,69 +1,73 @@
1 1 package com.ojn.gexf4j.core.testgraphs;
2 2
3   -import com.ojn.gexf4j.core.Graph;
  3 +import com.ojn.gexf4j.core.Gexf;
4 4 import com.ojn.gexf4j.core.Node;
5 5 import com.ojn.gexf4j.core.data.Attribute;
6 6 import com.ojn.gexf4j.core.data.AttributeClass;
  7 +import com.ojn.gexf4j.core.data.AttributeList;
7 8 import com.ojn.gexf4j.core.data.AttributeType;
8   -import com.ojn.gexf4j.core.impl.GraphImpl;
9   -import com.ojn.gexf4j.core.impl.data.AttributeImpl;
  9 +import com.ojn.gexf4j.core.impl.GexfImpl;
  10 +import com.ojn.gexf4j.core.impl.data.AttributeListImpl;
10 11
11   -public class DataGraphBuilder implements GraphBuilder {
  12 +public class DataGraphBuilder extends GexfBuilder {
  13 +
12 14 @Override
13 15 public String getSuffix() {
14 16 return "data";
15 17 }
16 18
17 19 @Override
18   - public String getXsdUrl() {
19   - return "http://gexf.net/1.1draft/gexf.xsd";
20   - }
21   -
22   - @Override
23   - public Graph buildGraph() {
24   - Graph rv = new GraphImpl();
25   -
26   - Attribute attribUrl = new AttributeImpl(AttributeType.STRING, "0", AttributeClass.NODE);
27   - Attribute attribInDegree = new AttributeImpl(AttributeType.STRING, "1", AttributeClass.NODE);
28   - Attribute attribFrog = new AttributeImpl(AttributeType.STRING, "2", AttributeClass.NODE);
  20 + public Gexf buildGexf() {
  21 + Gexf gexf = new GexfImpl();
29 22
30   - attribUrl.setTitle("url");
31   - attribInDegree.setTitle("indegree");
32   - attribFrog.setTitle("frog");
  23 + gexf.getMetadata()
  24 + .setLastModified(toDate("2009-03-20"))
  25 + .setCreator("Gephi.org")
  26 + .setDescription("A Web network");
33 27
34   - rv.getNodeAttributes().add(attribUrl);
35   - rv.getNodeAttributes().add(attribInDegree);
36   - rv.getNodeAttributes().add(attribFrog);
  28 + AttributeList attrList = new AttributeListImpl(AttributeClass.NODE);
  29 + gexf.getGraph().getAttributeLists().add(attrList);
37 30
38   - Node nGephi = rv.createNode("0");
39   - nGephi.setLabel("Gephi");
40   - nGephi.getAttributeValues().add(attribUrl.createValue("http://gephi.org"));
41   - nGephi.getAttributeValues().add(attribInDegree.createValue("1"));
  31 + Attribute attUrl = attrList.createAttribute("0", AttributeType.STRING, "url");
  32 + Attribute attIndegree = attrList.createAttribute("1", AttributeType.FLOAT, "indegree");
  33 + Attribute attFrog = attrList.createAttribute("2", AttributeType.BOOLEAN, "frog")
  34 + .setDefaultValue("true");
42 35
43   - Node nWebatlas = rv.createNode("1");
44   - nWebatlas.setLabel("Webatlas");
45   - nWebatlas.getAttributeValues().add(attribUrl.createValue("http://webatlas.fr"));
46   - nWebatlas.getAttributeValues().add(attribInDegree.createValue("2"));
  36 + Node gephi = gexf.getGraph().createNode("0");
  37 + gephi
  38 + .setLabel("Gephi")
  39 + .getAttributeValues()
  40 + .addValue(attUrl, "http://gephi.org")
  41 + .addValue(attIndegree, "1");
47 42
48   - Node nRTGI = rv.createNode("2");
49   - nRTGI.setLabel("RTGI");
50   - nRTGI.getAttributeValues().add(attribUrl.createValue("http://rtgi.fr"));
51   - nRTGI.getAttributeValues().add(attribInDegree.createValue("1"));
  43 + Node webatlas = gexf.getGraph().createNode("1");
  44 + webatlas
  45 + .setLabel("Webatlas")
  46 + .getAttributeValues()
  47 + .addValue(attUrl, "http://webatlas.fr")
  48 + .addValue(attIndegree, "2");
52 49
53   - Node nBar = rv.createNode("3");
54   - nBar.setLabel("BarabasiLab");
55   - nBar.getAttributeValues().add(attribUrl.createValue("http://barabasilab.com"));
56   - nBar.getAttributeValues().add(attribInDegree.createValue("1"));
57   - nBar.getAttributeValues().add(attribFrog.createValue("false"));
  50 + Node rtgi = gexf.getGraph().createNode("2");
  51 + rtgi
  52 + .setLabel("RTGI")
  53 + .getAttributeValues()
  54 + .addValue(attUrl, "http://rtgi.fr")
  55 + .addValue(attIndegree, "1");
58 56
59   - nGephi.connectTo("0", nWebatlas);
60   - nGephi.connectTo("1", nRTGI);
61   - nWebatlas.connectTo("2", nGephi);
62   - nRTGI.connectTo("3", nWebatlas);
63   - nGephi.connectTo("4", nBar);
  57 + Node blab = gexf.getGraph().createNode("3");
  58 + blab
  59 + .setLabel("BarabasiLab")
  60 + .getAttributeValues()
  61 + .addValue(attUrl, "http://barabasilab.com")
  62 + .addValue(attIndegree, "1")
  63 + .addValue(attFrog, "false");
64 64
65   - nGephi.getEdges().get(0).getAttributeValues().add(attribFrog.createValue("true"));
  65 + gephi.connectTo("0", webatlas);
  66 + gephi.connectTo("1", rtgi);
  67 + webatlas.connectTo("2", gephi);
  68 + rtgi.connectTo("3", webatlas);
  69 + gephi.connectTo("4", blab);
66 70
67   - return rv;
  71 + return gexf;
68 72 }
69 73 }
171 src/test/java/com/ojn/gexf4j/core/testgraphs/DynamicGraphBuilder.java
... ... @@ -1,19 +1,17 @@
1 1 package com.ojn.gexf4j.core.testgraphs;
2 2
3   -import java.util.Date;
4   -
5   -import com.ojn.gexf4j.core.Graph;
  3 +import com.ojn.gexf4j.core.Gexf;
  4 +import com.ojn.gexf4j.core.Mode;
6 5 import com.ojn.gexf4j.core.Node;
7 6 import com.ojn.gexf4j.core.data.Attribute;
8 7 import com.ojn.gexf4j.core.data.AttributeClass;
  8 +import com.ojn.gexf4j.core.data.AttributeList;
9 9 import com.ojn.gexf4j.core.data.AttributeType;
10   -import com.ojn.gexf4j.core.impl.EdgeImpl;
11   -import com.ojn.gexf4j.core.impl.GraphImpl;
12   -import com.ojn.gexf4j.core.impl.NodeImpl;
13   -import com.ojn.gexf4j.core.impl.data.AttributeImpl;
14   -import com.ojn.gexf4j.core.impl.data.AttributeValueImpl;
  10 +import com.ojn.gexf4j.core.impl.GexfImpl;
  11 +import com.ojn.gexf4j.core.impl.data.AttributeListImpl;
  12 +import com.ojn.gexf4j.core.impl.dynamic.SliceImpl;
15 13
16   -public class DynamicGraphBuilder implements GraphBuilder {
  14 +public class DynamicGraphBuilder extends GexfBuilder {
17 15
18 16 @Override
19 17 public String getSuffix() {
@@ -21,67 +19,98 @@ public String getSuffix() {
21 19 }
22 20
23 21 @Override
24   - public String getXsdUrl() {
25   - return "http://gexf.net/1.1draft/gexf.xsd";
26   - }
27   -
28   - @Override
29   - public Graph buildGraph() {
30   - GraphImpl rv = new GraphImpl();
31   -
32   - rv.setStartDate(new Date());
33   -
34   - Attribute attribUrl = new AttributeImpl(AttributeType.STRING, "0", AttributeClass.NODE);
35   - Attribute attribInDegree = new AttributeImpl(AttributeType.STRING, "1", AttributeClass.NODE);
36   - Attribute attribFrog = new AttributeImpl(AttributeType.STRING, "2", AttributeClass.NODE);
37   -
38   - attribUrl.setTitle("url");
39   - attribInDegree.setTitle("indegree");
40   - attribFrog.setTitle("frog");
41   -
42   - rv.getNodeAttributes().add(attribUrl);
43   - rv.getNodeAttributes().add(attribInDegree);
44   - rv.getNodeAttributes().add(attribFrog);
45   -
46   - NodeImpl nGephi = (NodeImpl) rv.createNode("0");
47   - nGephi.setLabel("Gephi");
48   - nGephi.getAttributeValues().add(attribUrl.createValue("http://gephi.org"));
49   - nGephi.getAttributeValues().add(attribInDegree.createValue("1"));
50   -
51   - nGephi.setStartDate(new Date());
52   - nGephi.setEndDate(new Date());
53   -
54   - Node nWebatlas = rv.createNode("1");
55   - nWebatlas.setLabel("Webatlas");
56   - nWebatlas.getAttributeValues().add(attribUrl.createValue("http://webatlas.fr"));
57   - nWebatlas.getAttributeValues().add(attribInDegree.createValue("2"));