-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added output adapter so view multiplex graph on multiplexgraph.html a…
…nalog zu customgraphs on graph.html
- Loading branch information
1 parent
6d9d6c4
commit 849a1ae
Showing
12 changed files
with
380 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...va/i5/las2peer/services/ocd/adapters/graphOutput/AbstractMultiplexGraphOutputAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package i5.las2peer.services.ocd.adapters.graphOutput; | ||
|
||
import i5.las2peer.services.ocd.adapters.AbstractOutputAdapter; | ||
|
||
/** | ||
* An abstract class for graph output adapters. | ||
* @author Sebastian | ||
* | ||
*/ | ||
public abstract class AbstractMultiplexGraphOutputAdapter extends AbstractOutputAdapter implements MultiplexGraphOutputAdapter { | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
...src/main/java/i5/las2peer/services/ocd/adapters/graphOutput/CommonGraphOutputAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package i5.las2peer.services.ocd.adapters.graphOutput; | ||
|
||
import i5.las2peer.services.ocd.adapters.AdapterException; | ||
import i5.las2peer.services.ocd.adapters.InputAdapter; | ||
import i5.las2peer.services.ocd.adapters.OutputAdapter; | ||
import i5.las2peer.services.ocd.graphs.MultiplexGraph; | ||
|
||
import java.text.ParseException; | ||
import java.util.Map; | ||
|
||
/** | ||
* The common interface of all graph output adapters. | ||
* @author Sebastian | ||
* | ||
*/ | ||
public interface CommonGraphOutputAdapter<T> extends OutputAdapter { | ||
|
||
/** | ||
* Writes a graph and closes the writer. | ||
* @throws AdapterException if the adapter failed | ||
*/ | ||
public void writeGraph(T graph) throws AdapterException; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...ava/i5/las2peer/services/ocd/adapters/graphOutput/MetaXmlMultiplexGraphOutputAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package i5.las2peer.services.ocd.adapters.graphOutput; | ||
|
||
import i5.las2peer.services.ocd.adapters.AdapterException; | ||
import i5.las2peer.services.ocd.graphs.MultiplexGraph; | ||
import i5.las2peer.services.ocd.graphs.GraphType; | ||
import org.w3c.dom.Document; | ||
import org.w3c.dom.Element; | ||
|
||
import javax.xml.parsers.DocumentBuilder; | ||
import javax.xml.parsers.DocumentBuilderFactory; | ||
import javax.xml.transform.OutputKeys; | ||
import javax.xml.transform.Transformer; | ||
import javax.xml.transform.TransformerFactory; | ||
import javax.xml.transform.dom.DOMSource; | ||
import javax.xml.transform.stream.StreamResult; | ||
|
||
/** | ||
* A graph output adapter for the meta XML format. | ||
* The output contains meta information about the graph in XML format, but not the actual graph structure or other node or edge related meta data. | ||
* @author Sebastian | ||
* | ||
*/ | ||
public class MetaXmlMultiplexGraphOutputAdapter extends AbstractMultiplexGraphOutputAdapter { | ||
|
||
@Override | ||
public void writeGraph(MultiplexGraph graph) throws AdapterException { | ||
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); | ||
try { | ||
DocumentBuilder builder = builderFactory.newDocumentBuilder(); | ||
Document doc = builder.newDocument(); | ||
Element graphElt = doc.createElement("Graph"); | ||
doc.appendChild(graphElt); | ||
/* | ||
* Basic Attributes | ||
*/ | ||
Element graphIdElt = doc.createElement("Id"); | ||
graphIdElt.appendChild(doc.createTextNode(graph.getKey())); | ||
graphElt.appendChild(graphIdElt); | ||
Element graphNameElt = doc.createElement("Name"); | ||
graphNameElt.appendChild(doc.createTextNode(graph.getName())); | ||
graphElt.appendChild(graphNameElt); | ||
Element graphNodeCountElt = doc.createElement("NodeCount"); | ||
graphNodeCountElt.appendChild(doc.createTextNode(Integer.toString(graph.getNodeCount()))); | ||
graphElt.appendChild(graphNodeCountElt); | ||
Element graphEdgeCountElt = doc.createElement("EdgeCount"); | ||
graphEdgeCountElt.appendChild(doc.createTextNode(Integer.toString(graph.getEdgeCount()))); | ||
graphElt.appendChild(graphEdgeCountElt); | ||
Element graphLayerCountElt = doc.createElement("LayerCount"); | ||
graphLayerCountElt.appendChild(doc.createTextNode(Integer.toString(graph.getLayerCount()))); | ||
graphElt.appendChild(graphLayerCountElt); | ||
/* | ||
* Graph Types | ||
*/ | ||
Element typesElt = doc.createElement("Types"); | ||
for(GraphType type : graph.getTypes()) { | ||
Element typeElt = doc.createElement("Type"); | ||
typeElt.appendChild(doc.createTextNode(type.name())); | ||
typeElt.setAttribute("displayName", type.getDisplayName()); | ||
typesElt.appendChild(typeElt); | ||
} | ||
graphElt.appendChild(typesElt); | ||
/* | ||
* Creation Method | ||
*/ | ||
Element creationMethodElt = doc.createElement("CreationMethod"); | ||
Element creationMethodTypeElt = doc.createElement("Type"); | ||
creationMethodTypeElt.appendChild(doc.createTextNode(graph.getCreationMethod().getType().name())); | ||
creationMethodTypeElt.setAttribute("displayName", graph.getCreationMethod().getType().getDisplayName()); | ||
creationMethodElt.appendChild(creationMethodTypeElt); | ||
Element creationMethodStatus = doc.createElement("Status"); | ||
creationMethodStatus.appendChild(doc.createTextNode(graph.getCreationMethod().getStatus().name())); | ||
creationMethodElt.appendChild(creationMethodStatus); | ||
graphElt.appendChild(creationMethodElt); | ||
/* | ||
* XML output | ||
*/ | ||
TransformerFactory transformerFactory = TransformerFactory.newInstance(); | ||
Transformer transformer = transformerFactory.newTransformer(); | ||
transformer.setOutputProperty(OutputKeys.INDENT, "yes"); | ||
DOMSource domSource = new DOMSource(doc); | ||
StreamResult streamResult = new StreamResult(this.writer); | ||
transformer.transform(domSource, streamResult); | ||
} | ||
catch(Exception e) { | ||
throw new AdapterException(e); | ||
} | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
.../main/java/i5/las2peer/services/ocd/adapters/graphOutput/MultiplexGraphOutputAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package i5.las2peer.services.ocd.adapters.graphOutput; | ||
|
||
import i5.las2peer.services.ocd.adapters.AdapterException; | ||
import i5.las2peer.services.ocd.adapters.OutputAdapter; | ||
import i5.las2peer.services.ocd.adapters.graphInput.CommonGraphInputAdapter; | ||
import i5.las2peer.services.ocd.graphs.CustomGraph; | ||
import i5.las2peer.services.ocd.graphs.MultiplexGraph; | ||
|
||
/** | ||
* The common interface of all graph output adapters. | ||
* @author Sebastian | ||
* | ||
*/ | ||
public interface MultiplexGraphOutputAdapter extends CommonGraphOutputAdapter<MultiplexGraph> { | ||
|
||
/** | ||
* Writes a graph and closes the writer. | ||
* @param graph The graph to write. | ||
* @throws AdapterException if the adapter failed | ||
*/ | ||
public void writeGraph(MultiplexGraph graph) throws AdapterException; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.