Anonymous avatar Anonymous committed ee27df1

support for new edge conventions in the XML

Comments (0)

Files changed (2)

src/nl/tudelft/lime/xml/XMLFactory.java

 package nl.tudelft.lime.xml;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Vector;
-
 import nl.tudelft.lime.model.LimeDiagram;
 import nl.tudelft.lime.model.LimeElement;
 import nl.tudelft.lime.model.LimeLabel;
 import nl.tudelft.lime.model.port.OutputPort;
 import nl.tudelft.lime.model.port.Port;
 
-import org.dom4j.Attribute;
 import org.dom4j.Document;
 import org.dom4j.DocumentException;
 import org.dom4j.DocumentHelper;
 import org.dom4j.Element;
+
 import org.dom4j.io.OutputFormat;
 import org.dom4j.io.SAXReader;
 import org.dom4j.io.XMLWriter;
+
 import org.dom4j.tree.DefaultAttribute;
 import org.dom4j.tree.DefaultCDATA;
 import org.dom4j.tree.DefaultElement;
+
 import org.dom4j.util.XMLErrorHandler;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Vector;
+
 
 /**
  * XML factory used to create XML document from the diagram
     private static final String DUMMY_INTER_ARCS_TAG = "dummyInterArcs";
     private static final String DUMMY_ASSOCIATIONS_TAG = "dummyAssociations";
     private static final String DUMMY_ROOT_ARCS_TAG = "dummy-root-arcs";
-    
+
     //hardcoded tags (TODO: they should be moved to SystemSettings) 
     private static final String XLINK_TYPE_ATTRIBUTE = "xlink:type";
     private static final String XLINK_LABEL_ATTRIBUTE = "xlink:label";
     private static final String CODE_TAG = "code";
     private static final String ENDPOINT_TAG = "endpoint";
     private static final String EDGE_TAG = "edge";
+    private static final String EDGES_TAG = "edges";
+    private static final String TYPE_TAG = "type";
     private static final String META_TAG = "meta";
     private static final String NODE_TAG = "node";
-    private static final String NODE2_TAG = "node_";
     private static final String PORT_TAG = "port";
-    private static final String PORT2_TAG = "port_";
+    private static final String GXF_URL = "http://bitbucket.org/pjotr/lime/raw/tip/doc/gxf.dtd";
+    private static final String ID_TAG = "id";
     private static final String TO_TAG = "to";
     private static final String FROM_TAG = "from";
-    
-    
+    private static final String TO_NODE_TAG = "to-node";
+    private static final String FROM_NODE_TAG = "from-node";
+    private static final String PORT_ID_TAG = "port-id";
     private static final String META_TAG_VISUAL_ID = "visual";
     private static final String META_TAG_CODE_ID = "passthrough";
     private static final String SIZE_TAG = "size";
     private static final String LOCATION_TAG = "location";
     private static final String DIMENSION_TAG = "dimension";
-    
-    
-    
     private static final String ID_ATTRIBUTE = "id";
     private static final String VALUE_ATTRIBUTE = "value";
 
         // e.g. : Component1::port1 -> Port1@2345EA35
         LimeDiagram diagram = (LimeDiagram) getDiagram(doc.getRootElement());
         //it can be only made when all the nodes are created
+        addAssociations(doc.getRootElement(), diagram);
 
-        addAssociations(doc.getRootElement(), diagram);
         // LimeDiagram diagram = new LimeDiagram();
         // second, add the arcs to the diagram, this is a faster process
         // TODO: this can be called full of side effects, since it works with
         // references
         // it is wise to enhance it if needed
-
         return diagram;
     }
-    
+
     /**
      * Saves the XML version of the diagram.
      *
      * ports from the portDictionary and then adds the arc to them
      *
      * @param Element
-     * @param arcsPortDictionary it should only contain ports which are in the lime components inside the element  
+     * @param arcsPortDictionary it should only contain ports which are in the lime components inside the element
      */
     @SuppressWarnings("unchecked")
     private static void addArcs(Element element,
             // for these elements first create all the arcs inside them, and
             // then
             // call the same for their children
-            List<Element> arcs = (List<Element>) element.elements("edge");
+            Element edges = element.element(EDGES_TAG);
 
-            for (Element arcElement : arcs) {
-                try {
-                    Arc arc = new Arc();
-                    String fromOutput = "";
-                    String toInput = "";
-                    arc.setArcType(arcElement.element("type").getText());
+            if (edges != null) {
+                List<Element> arcs = (List<Element>) edges.elements(EDGE_TAG);
 
-                    // use QName to resolve xlink attributes, but it means
-                    // defining a
-                    // variable for the namespace, to keep it simple we keep it
-                    // as below
+                for (Element arcElement : arcs) {
+                    try {
+                        Arc arc = new Arc();
+                        String fromOutput = "";
+                        String toInput = "";
+                        arc.setArcType(arcElement.element(TYPE_TAG).getText());
 
+                        // use QName to resolve xlink attributes, but it means
+                        // defining a
+                        // variable for the namespace, to keep it simple we keep it
+                        // as below
 
-                	//TODO: the convention should be kept in one place...
-                	//now the convention is to use ${node's name}:${port's name}
-                	Element fromElement = arcElement.element(FROM_TAG);
-                	if (fromElement.element(NODE2_TAG)!= null)
-                	fromOutput = fromElement.element(NODE2_TAG).elementText("id") + ":" +
-                				 fromElement.element(NODE2_TAG).element(PORT2_TAG).elementText("id");
-                	else
-                    	fromOutput = fromElement.element(NODE_TAG).elementText("id") + ":" +
-                    				 fromElement.element(NODE_TAG).element(PORT_TAG).elementText("id");
+                        //TODO: the convention should be kept in one place...
+                        //now the convention is to use ${node's name}:${port's name}
+                        Element fromElement = arcElement.element(FROM_NODE_TAG);
 
-                    if ((fromOutput == null) || fromOutput.equals("")) {
-                        throw new XMLFormatNotCorrectException();
+                        if (fromElement != null) {
+                            fromOutput = fromElement.elementText(ID_TAG) + ":" +
+                                fromElement.element(PORT_ID_TAG).getText();
+                        } else {
+                            fromElement = arcElement.element(FROM_TAG);
+                            fromOutput = fromElement.element(NODE_TAG)
+                                                    .elementText(ID_TAG) + ":" +
+                                fromElement.element(NODE_TAG).element(PORT_TAG)
+                                           .elementText(ID_TAG);
+                        }
+
+                        if ((fromOutput == null) || fromOutput.equals("")) {
+                            throw new XMLFormatNotCorrectException();
+                        }
+
+                        // this is a non-safe way to map, but since the XML is
+                        // not well-formatted for this part
+                        // we have to continue doing this
+                        // there are two double-dot columns we have to ignore in
+                        // our indexing
+                        //fromOutput = fromOutput.substring(2);
+
+                        // if the attribute is empty get edge -> node -> port ->
+                        // id instead
+                        Element toElement = arcElement.element(TO_NODE_TAG);
+
+                        if (toElement != null) {
+                            toInput = toElement.elementText(ID_TAG) + ":" +
+                                toElement.element(PORT_ID_TAG).getText();
+                        } else {
+                            toElement = arcElement.element(TO_TAG);
+                            toInput = toElement.element(NODE_TAG)
+                                               .elementText(ID_TAG) + ":" +
+                                toElement.element(NODE_TAG).element(PORT_TAG)
+                                         .elementText(ID_TAG);
+                        }
+
+                        if ((toInput == null) || toInput.equals("")) {
+                            throw new XMLFormatNotCorrectException();
+                        }
+
+                        OutputPort outputPort = (OutputPort) arcsPortDictionary.get(fromOutput);
+                        InputPort inputPort = (InputPort) arcsPortDictionary.get(toInput);
+
+                        if ((outputPort != null) && (inputPort != null)) {
+                            arc.setSource(outputPort);
+                            arc.setTarget(inputPort);
+                            arc.setTargetTerminal(Port.CONNECTION_TERMINAL);
+                            arc.setSourceTerminal(Port.CONNECTION_TERMINAL);
+                            arc.attachSource();
+                            arc.attachTarget();
+                        }
+                    } catch (Exception e) {
+                        // ignored one arc
+                        System.err.println(arcElement.asXML());
+                        e.printStackTrace();
                     }
-
-                    // this is a non-safe way to map, but since the XML is
-                    // not well-formatted for this part
-                    // we have to continue doing this
-                    // there are two double-dot columns we have to ignore in
-                    // our indexing
-                    //fromOutput = fromOutput.substring(2);
-
-                    // if the attribute is empty get edge -> node -> port ->
-                    // id instead
-                	Element toElement = arcElement.element(TO_TAG);
-                	if (toElement.element(NODE2_TAG)!= null)
-	                	toInput = toElement.element(NODE2_TAG).elementText("id") + ":" +
-	                				 toElement.element(NODE2_TAG).element(PORT2_TAG).elementText("id");
-                	else
-	                	toInput = toElement.element(NODE_TAG).elementText("id") + ":" +
-	                				 toElement.element(NODE_TAG).element(PORT_TAG).elementText("id");
-                	
-                    if ((toInput == null) || toInput.equals("")) {
-                        throw new XMLFormatNotCorrectException();
-                    }
-
-                    OutputPort outputPort = (OutputPort) arcsPortDictionary.get(fromOutput);
-                    InputPort inputPort = (InputPort) arcsPortDictionary.get(toInput);
-
-                    if ((outputPort != null) && (inputPort != null)) {
-                        arc.setSource(outputPort);
-                        arc.setTarget(inputPort);
-                        arc.setTargetTerminal(Port.CONNECTION_TERMINAL);
-                        arc.setSourceTerminal(Port.CONNECTION_TERMINAL);
-                        arc.attachSource();
-                        arc.attachTarget();
-                    }
-                } catch (Exception e) {
-                    // ignored one arc
-                    System.err.println(arcElement.asXML());
-                    e.printStackTrace();
                 }
             }
-
         }
     }
-    
+
     /**
      * In this method associations are created between ports in the diagram. It
      * starts with all the &lt;bound-to&gt; elements and using their 'xlink:from'
      * ports from the portDictionary and then adds the arc to them
      * TODO: this should be optimized... on one hand keeping a dictionary for the associations doesn't seem to be a good solution
      * on the other hand this ways is not the best way
-     * 
+     *
      * @param Element
-     * @param arcsPortDictionary it should only contain ports which are in the lime components inside the element  
+     * @param arcsPortDictionary it should only contain ports which are in the lime components inside the element
      */
     @SuppressWarnings("unchecked")
-    private static void addAssociations(Element element, LimeDiagram diagram)     
-    {
+    private static void addAssociations(Element element, LimeDiagram diagram) {
         List<Element> associations = (List<Element>) element.elements(
-        "bound-to");
+                "bound-to");
 
         //2. now for the associations do the same procedure
         for (Element arcElement : associations) {
-		    try {
-		        Association association = new Association();
-		        String fromPort = arcElement.attribute(XLINK_FROM_ATTRIBUTE).getValue();
-		        String toPort = arcElement.attribute(XLINK_TO_ATTRIBUTE).getValue();
-		
-		        // use QName to resolve xlink attributes, but it means
-		        // defining a
-		        // variable for the namespace, to keep it simple we keep it
-		        // as below
-		        
-		        Port port1 = findPort(diagram, fromPort);
-		        Port port2 = findPort(diagram, toPort);
-		
-		        if ((port1 != null) && (port2 != null)) {
-		            association.setSource(port1);
-		            association.setTarget(port2);
-		            association.setTargetTerminal(Port.CONNECTION_TERMINAL);
-		            association.setSourceTerminal(Port.CONNECTION_TERMINAL);
-		            association.attachSource();
-		            association.attachTarget();
-		        }
-		    } catch (Exception e) {
-		        System.err.println(arcElement.asXML());
-		        e.printStackTrace();
-		    }
+            try {
+                Association association = new Association();
+                String fromPort = arcElement.attribute(XLINK_FROM_ATTRIBUTE)
+                                            .getValue();
+                String toPort = arcElement.attribute(XLINK_TO_ATTRIBUTE)
+                                          .getValue();
+
+                // use QName to resolve xlink attributes, but it means
+                // defining a
+                // variable for the namespace, to keep it simple we keep it
+                // as below
+                Port port1 = findPort(diagram, fromPort);
+                Port port2 = findPort(diagram, toPort);
+
+                if ((port1 != null) && (port2 != null)) {
+                    association.setSource(port1);
+                    association.setTarget(port2);
+                    association.setTargetTerminal(Port.CONNECTION_TERMINAL);
+                    association.setSourceTerminal(Port.CONNECTION_TERMINAL);
+                    association.attachSource();
+                    association.attachTarget();
+                }
+            } catch (Exception e) {
+                System.err.println(arcElement.asXML());
+                e.printStackTrace();
+            }
         }
+
         //do it for its children
-	    List<Element> nodes = (List<Element>) element.elements(NODE_TAG);
-		for (Element node : nodes) {
-		    addAssociations(node, diagram);
-		}        
+        List<Element> nodes = (List<Element>) element.elements(NODE_TAG);
+
+        for (Element node : nodes) {
+            addAssociations(node, diagram);
+        }
     }
 
     /**
      * @return
      */
     private static Port findPort(LimeDiagram diagram, String portParentChildPath) {
-		List<LimeElement> children = diagram.getChildren();
-		boolean lastStep = false;
-		String lookfor = portParentChildPath;
-		if (portParentChildPath.indexOf(":") == -1)
-			lastStep = true;
-		else
-			lookfor = portParentChildPath.substring(0, portParentChildPath.indexOf(":"));
-		
-		for (LimeElement child : children){
-			//if it is lastStep it should look for the port
-			if (lastStep && (child instanceof Port) && ((Port) child).getName().equals(lookfor))
-				return (Port) child;
-			if (!lastStep && (child instanceof LimeComponent) && ((LimeComponent) child).getName().equals(lookfor))
-				return findPort((LimeDiagram)child, portParentChildPath.substring(portParentChildPath.indexOf(":") + 1));
-			//else ignore other children
-		}
-		//the worst case!
-		return null;
-	}
+        List<LimeElement> children = diagram.getChildren();
+        boolean lastStep = false;
+        String lookfor = portParentChildPath;
 
-	/**
-     * Using
-     * {@link XMLFactory#createXML(nl.tudelft.lime.model.LimeElement, String)}
-     * creates equivalent XML document for the diagram
-     *
-     * @return XML document
-     */
+        if (portParentChildPath.indexOf(":") == -1) {
+            lastStep = true;
+        } else {
+            lookfor = portParentChildPath.substring(0,
+                    portParentChildPath.indexOf(":"));
+        }
+
+        for (LimeElement child : children) {
+            //if it is lastStep it should look for the port
+            if (lastStep && (child instanceof Port) &&
+                    ((Port) child).getName().equals(lookfor)) {
+                return (Port) child;
+            }
+
+            if (!lastStep && (child instanceof LimeComponent) &&
+                    ((LimeComponent) child).getName().equals(lookfor)) {
+                return findPort((LimeDiagram) child,
+                    portParentChildPath.substring(portParentChildPath.indexOf(
+                            ":") + 1));
+            }
+
+            //else ignore other children
+        }
+
+        //the worst case!
+        return null;
+    }
+
+    /**
+    * Using
+    * {@link XMLFactory#createXML(nl.tudelft.lime.model.LimeElement, String)}
+    * creates equivalent XML document for the diagram
+    *
+    * @return XML document
+    */
     public static Document getXMLForDiagram(LimeDiagram limeDiagram) {
         Document xmlDocument = DocumentHelper.createDocument();
         // QName rootName = DocumentFactory.getInstance().createQName("gxf", "",
         // "http://www.w3.org/1999/xlink");
         // Element root = DocumentFactory.getInstance().createElement(rootName);
         // xmlDocument.add(root);
-        xmlDocument.addDocType("gxf", "", "gxf.dtd");
+        xmlDocument.addDocType("gxf", "", GXF_URL);
 
         try {
             xmlDocument.add(getXML(limeDiagram));
      * <li>Create all the elements (ports and nodes), recursively</li>
      * <li>add arcs and associations for the node</li>
      * </ul>
-     * 
+     *
      * @param element
      * @param associationsFlatDictionary this is a dictioanry used to draw associations between ports at the end
      * it is called flat since its saved with flat ids node1:node2:port1
      * @return XML representation of element
      */
     @SuppressWarnings("unchecked")
-    public static LimeSubpart getDiagram(Element element) throws IllegalArgumentException {
-    	//port dictionary holds the information for the visible ports for this node
-    	//visible ports are the ones which edges can use them to connect components together
+    public static LimeSubpart getDiagram(Element element)
+        throws IllegalArgumentException {
+        //port dictionary holds the information for the visible ports for this node
+        //visible ports are the ones which edges can use them to connect components together
 
         //--------------------------------------------------------------------------------
         //1. Create the elements
         //--------------------------------------------------------------------------------
         LimeSubpart subpart = createLimeSubpart(element);
+
         if (subpart != null) {
             // if it is a port or a node then configure the default fields
             if (subpart instanceof LimeComponent || subpart instanceof Port) {
-            	createDefaultFromXML(subpart, element);
+                createDefaultFromXML(subpart, element);
             }
 
             //then if it is a port tag
             if (subpart instanceof Port) {
                 Port port = (Port) subpart;
                 createPortFromXML(port, element);
+
                 return port;
+
                 //portDictionary.put(portId, port);
             }
 
             // configure component specific fields
             if (subpart instanceof LimeDiagram) {
-            	//portdictionary should contain port information of this component's children
-            	//then it can draw edges between them
-            	//so first empy portDictionary for its own usage
+                //portdictionary should contain port information of this component's children
+                //then it can draw edges between them
+                //so first empy portDictionary for its own usage
                 if (subpart instanceof LimeComponent) {
-                	createComponentFromXML((LimeComponent)subpart, element);
+                    createComponentFromXML((LimeComponent) subpart, element);
                 }
 
                 // only get nodes - nodes are the ones which should be traversed
-                List<Element> children = (List<Element>) element.elements(
-                        NODE_TAG);
+                List<Element> children = (List<Element>) element.elements(NODE_TAG);
 
                 for (Element child : children) {
                     // add parent child relationship to the items
                 }
 
                 //for port children just add them
-                List<Element> portChildren = (List<Element>) element.elements(
-                        PORT_TAG);
-                
+                List<Element> portChildren = (List<Element>) element.elements(PORT_TAG);
+
                 for (Element child : portChildren) {
-                	//it is obviously getting a port and obviously it doesn't need to fill in associations
+                    //it is obviously getting a port and obviously it doesn't need to fill in associations
                     LimeSubpart childSubpart = getDiagram(child);
                     //now set the port's parent
                     childSubpart.setParent((LimeDiagram) subpart);
 
                     //and add it to the component
                     ((LimeDiagram) subpart).addChild(childSubpart);
-                   
                 }
+
                 //when every child of me is created, then add arcs and associations between them but before that create a 
                 //dictionary holding String->Port values for ports in my component children
-                
+
                 //now build the dictionary
                 Map<String, Port> portDictionary = buildArcDictionary(subpart);
                 addArcs(element, portDictionary);
                 portDictionary.clear();
             }
         }
+
         //--------------------------------------------------------------------------------
         //2. Add associations and arcs
         //--------------------------------------------------------------------------------
         return subpart;
     }
+
     /**
      * Create port dictionary which is indeed
      * @return
      */
-    private static Map<String, Port> buildArcDictionary(LimeSubpart subpart){
-    	Map<String, Port> portDictionary = new HashMap<String, Port>();
-        for (LimeElement myComponents : ((LimeDiagram) subpart).getChildren()){
-        	//if the element is a limeComponet get all its ports and add them to the dictionary
-        	if (myComponents instanceof LimeComponent){
-        		for(LimeElement componentElement : ((LimeComponent) myComponents).getChildren()){
-        			if (componentElement instanceof Port){
-        				Port port = (Port) componentElement;
-        				String portId = port.getParent().getName() + ":" + port.getName();
-        				portDictionary.put(portId, port);
-        			}
-        		}
-        	}
+    private static Map<String, Port> buildArcDictionary(LimeSubpart subpart) {
+        Map<String, Port> portDictionary = new HashMap<String, Port>();
+
+        for (LimeElement myComponents : ((LimeDiagram) subpart).getChildren()) {
+            //if the element is a limeComponet get all its ports and add them to the dictionary
+            if (myComponents instanceof LimeComponent) {
+                for (LimeElement componentElement : ((LimeComponent) myComponents).getChildren()) {
+                    if (componentElement instanceof Port) {
+                        Port port = (Port) componentElement;
+                        String portId = port.getParent().getName() + ":" +
+                            port.getName();
+                        portDictionary.put(portId, port);
+                    }
+                }
+            }
         }
+
         return portDictionary;
     }
+
     /**
      * Creates default element XML for nodes
      * @param component a LIME component
      * @param element
      */
     @SuppressWarnings("unchecked")
-    private static void createComponentFromXML(LimeComponent limeComponent, Element element){
-
+    private static void createComponentFromXML(LimeComponent limeComponent,
+        Element element) {
         for (Element subElement : (List<Element>) element.elements()) {
             if (subElement.getName().equals("type")) {
                 limeComponent.setType(subElement.getText());
             }
         }
     }
+
     /**
      * Creates default element XML for ports and nodes
      * @param subpart either a port or a component
      * @param element
      */
     @SuppressWarnings("unchecked")
-    private static void createDefaultFromXML(LimeSubpart subpart, Element element){
+    private static void createDefaultFromXML(LimeSubpart subpart,
+        Element element) {
         subpart.setName(element.element("id").getText());
+
         List<Element> metaElements = element.elements(META_TAG);
+
         //for meta elements only two elements should be treated in different way
         //1. meta tag with id = "visual" : which determines size and location of a LimeElement
         //2. meta tag with id = "passthrough" : which would be the code part
-        for (Element metaElement : metaElements){
-        	//if it is the first case
-        	if (metaElement.attribute("id").getValue().equals(META_TAG_VISUAL_ID)){
-            	subpart.setSizeByMap(getDimensionsListMap(metaElement.element(
-                        SIZE_TAG)));
-            	subpart.setLocationByMap(getDimensionsListMap(metaElement.element(
-                        LOCATION_TAG)));
-        		
-        	}
-        	//if it is a code fragment
-        	else if (subpart instanceof LimeComponent && metaElement.attribute("id").getValue().equals(META_TAG_CODE_ID)){
-        		//create a label and make it as a child of this component
-        		LimeLabel codeFragment = new LimeLabel();
-        		codeFragment.setLabelContents((String) metaElement.element(CODE_TAG).getData());
-        		((LimeComponent)subpart).addChild(codeFragment);
-        	}
-        	//if it is an unknown tag
-        	else{
-            	subpart.getPreservedXMLElements().add(metaElement.createCopy());
-        	}
+        for (Element metaElement : metaElements) {
+            //if it is the first case
+            if (metaElement.attribute("id").getValue().equals(META_TAG_VISUAL_ID)) {
+                subpart.setSizeByMap(getDimensionsListMap(metaElement.element(
+                            SIZE_TAG)));
+                subpart.setLocationByMap(getDimensionsListMap(
+                        metaElement.element(LOCATION_TAG)));
+            }
+            //if it is a code fragment
+            else if (subpart instanceof LimeComponent &&
+                    metaElement.attribute("id").getValue()
+                                   .equals(META_TAG_CODE_ID)) {
+                //create a label and make it as a child of this component
+                LimeLabel codeFragment = new LimeLabel();
+                codeFragment.setLabelContents((String) metaElement.element(
+                        CODE_TAG).getData());
+                ((LimeComponent) subpart).addChild(codeFragment);
+            }
+            //if it is an unknown tag
+            else {
+                subpart.getPreservedXMLElements().add(metaElement.createCopy());
+            }
         }
     }
+
     /**
      * Creates port related XML
      * @param port
      * @return portId
      */
     @SuppressWarnings("unchecked")
-    private static String createPortFromXML(Port port, Element element){
+    private static String createPortFromXML(Port port, Element element) {
         for (Element subElement : (List<Element>) element.elements()) {
             if (subElement.getName().equals("type")) {
                 //two cases happen here based on the definition of LIME
             else if (subElement.getName().equals("size")) {
                 String elementSize = subElement.getText();
 
-                if (elementSize.startsWith("(") &&
-                        elementSize.endsWith(")")) {
+                if (elementSize.startsWith("(") && elementSize.endsWith(")")) {
                     elementSize = elementSize.substring(1,
                             elementSize.length() - 1);
                 }
 
         //previously portId could be obtained from id attribute 
         String portId = element.attribute("id").getValue();
+
         //TODO:but now it is should be created from the hierarchy of the port
         //???
         return portId;
+
         // to the map ports should be added
-    	
     }
+
     private static boolean isNormalPortTag(String name) {
-        return name.equals(LOCATION_TAG) || name.equals(SIZE_TAG) || name.equals(META_TAG) ||
-        name.equals(DUMMY_INTRA_ARCS_TAG);
+        return name.equals(LOCATION_TAG) || name.equals(SIZE_TAG) ||
+        name.equals(META_TAG) || name.equals(DUMMY_INTRA_ARCS_TAG);
     }
 
     /**
             Element rootArcsToBePulledUp = new DefaultElement(DUMMY_INTRA_ARCS_TAG);
 
             for (LimeElement element : children) {
-            	//if it is a code fragment (label) ignore it,
-            	//it is earlier handled as a meta tag
-            	if (element instanceof LimeLabel)
-            		continue;
+                //if it is a code fragment (label) ignore it,
+                //it is earlier handled as a meta tag
+                if (element instanceof LimeLabel) {
+                    continue;
+                }
+
                 Element item = getXML(element);
                 root.add(item);
 
         }
 
         //add extra information which are kept as embeddedXML for an element
-        List<Element> embeddedElements = limeSubpart.getPreservedXMLElements().elements();
+        List<Element> embeddedElements = limeSubpart.getPreservedXMLElements()
+                                                    .elements();
 
         for (Element element : embeddedElements)
             root.add(element.createCopy());
             arcElement.add(new DefaultAttribute(XLINK_TO_ATTRIBUTE,
                     getParentChildPath(target)));
 
-            DefaultElement typeElement = new DefaultElement("type");
+            DefaultElement typeElement = new DefaultElement(TYPE_TAG);
             typeElement.setText(arc.getArcTypeName());
 
             arcElement.add(typeElement);
 
             // adding from and port embedded nodes
             // I. adding 'from' node
-            DefaultElement fromElement = new DefaultElement(FROM_TAG);
-            DefaultElement fromNodeElement = new DefaultElement(NODE2_TAG);
-            DefaultElement fromNodeIdElement = new DefaultElement("id");
-            DefaultElement fromPortElement = new DefaultElement(PORT2_TAG);
-            DefaultElement fromPortIdElement = new DefaultElement("id");
-            
-            String parent_ParentChildPath = getParentChildPath(source.getParent());
+            DefaultElement fromElement = new DefaultElement(FROM_NODE_TAG);
+            DefaultElement fromNodeIdElement = new DefaultElement(ID_TAG);
+            DefaultElement fromPortIdElement = new DefaultElement(PORT_ID_TAG);
+
             String parentName = source.getParent().getName();
 
             fromPortIdElement.setText(source.getRevisedName());
-            fromPortElement.add(new DefaultAttribute("id",
-                    getParentChildPath(source)));
-            fromNodeElement.add(new DefaultAttribute("id",
-                    parent_ParentChildPath));
             fromNodeIdElement.setText(parentName);
 
-            fromPortElement.add(fromPortIdElement);
-            fromNodeElement.add(fromNodeIdElement);
-            fromNodeElement.add(fromPortElement);
-            fromElement.add(fromNodeElement);
+            fromNodeIdElement.add(fromPortIdElement);
+            fromElement.add(fromNodeIdElement);
 
             // II. adding 'to' node
-            DefaultElement toElement = new DefaultElement(TO_TAG);
-            DefaultElement toNodeElement = new DefaultElement(NODE2_TAG);
-            DefaultElement toNodeIdElement = new DefaultElement("id");
-            DefaultElement toPortElement = new DefaultElement(PORT2_TAG);
-            DefaultElement toPortIdElement = new DefaultElement("id");
+            DefaultElement toElement = new DefaultElement(TO_NODE_TAG);
+            DefaultElement toNodeIdElement = new DefaultElement(ID_TAG);
+            DefaultElement toPortIdElement = new DefaultElement(PORT_ID_TAG);
 
-            
-            parent_ParentChildPath = getParentChildPath(target.getParent());
             parentName = target.getParent().getName();
 
             toPortIdElement.setText(target.getRevisedName());
-            toPortElement.add(new DefaultAttribute("id",
-                    getParentChildPath(target)));
-            toNodeElement.add(new DefaultAttribute("id",
-                    parent_ParentChildPath));
             toNodeIdElement.setText(parentName);
 
-            toPortElement.add(toPortIdElement);
-            toNodeElement.add(toNodeIdElement);
-            toNodeElement.add(toPortElement);
-            toElement.add(toNodeElement);
+            toNodeIdElement.add(toPortIdElement);
+            toElement.add(toNodeIdElement);
 
             arcElement.add(fromElement);
             arcElement.add(toElement);
         for (Association association : associations) {
             Element associationElement = new DefaultElement("bound-to");
 
-            associationElement.add(new DefaultAttribute(XLINK_TYPE_ATTRIBUTE, "arc"));
+            associationElement.add(new DefaultAttribute(XLINK_TYPE_ATTRIBUTE,
+                    "arc"));
 
             LimeSubpart source = association.getSource();
             LimeSubpart target = association.getTarget();
      */
     private static void addComponentAttributes(Element root,
         LimeComponent component) {
-    	//adding code fragment
-    	String codeFragment = component.getCodeFragment();
-    	if (!codeFragment.equals("")){
-        	DefaultElement metaCode = new DefaultElement(META_TAG);
-        	metaCode.add(new DefaultAttribute("id", META_TAG_CODE_ID));
-        	DefaultElement codeFragmentElement = new DefaultElement(CODE_TAG);
-        	metaCode.add(codeFragmentElement);
-    	
-        	codeFragmentElement.add(new DefaultCDATA(codeFragment));
-        	root.add(metaCode);
-    	}
-    		
-    	//adding component return type
-    	DefaultElement componentRet = createTextElement("ret",
+        //adding code fragment
+        String codeFragment = component.getCodeFragment();
+
+        if (!codeFragment.equals("")) {
+            DefaultElement metaCode = new DefaultElement(META_TAG);
+            metaCode.add(new DefaultAttribute("id", META_TAG_CODE_ID));
+
+            DefaultElement codeFragmentElement = new DefaultElement(CODE_TAG);
+            metaCode.add(codeFragmentElement);
+
+            codeFragmentElement.add(new DefaultCDATA(codeFragment));
+            root.add(metaCode);
+        }
+
+        //adding component return type
+        DefaultElement componentRet = createTextElement("ret",
                 component.getComponentRet());
 
         if (componentRet != null) {
      */
     private static void addDefaultAttributes(Element root,
         LimeSubpart limeSubpart) {
-    	DefaultElement metaVisual = new DefaultElement("meta");
-    	metaVisual.add(new DefaultAttribute("id", META_TAG_VISUAL_ID));
-    	metaVisual.add(createDimensionList(SIZE_TAG, limeSubpart.getSizeMap()));
-    	metaVisual.add(createDimensionList(LOCATION_TAG, limeSubpart.getLocationMap()));
+        DefaultElement metaVisual = new DefaultElement("meta");
+        metaVisual.add(new DefaultAttribute("id", META_TAG_VISUAL_ID));
+        metaVisual.add(createDimensionList(SIZE_TAG, limeSubpart.getSizeMap()));
+        metaVisual.add(createDimensionList(LOCATION_TAG,
+                limeSubpart.getLocationMap()));
 
-    	root.add(metaVisual);
+        root.add(metaVisual);
 
         DefaultElement partIDElement = new DefaultElement("id");
         partIDElement.setText(limeSubpart.getRevisedName());
 
         return element;
     }
-    
 }

src/xmldtd/test.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE gxf SYSTEM "gxf.dtd">
+
+<gxf xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="extended">
+  <node id="source" xlink:type="resource" xlink:label="source">
+    <meta id="visual">
+      <size>
+        <dimension id="height" value="457"/>
+        <dimension id="width" value="400"/>
+      </size>
+      <location>
+        <dimension id="y" value="20"/>
+        <dimension id="x" value="20"/>
+      </location>
+    </meta>
+    <id>source</id>
+    <type>relax unfold</type>
+    <ret></ret>
+    <node id="source:process" xlink:type="resource" xlink:label="process">
+      <meta id="visual">
+        <size>
+          <dimension id="height" value="200"/>
+          <dimension id="width" value="200"/>
+        </size>
+        <location>
+          <dimension id="y" value="34"/>
+          <dimension id="x" value="110"/>
+        </location>
+      </meta>
+      <id>process</id>
+      <type>relax unfold</type>
+      <ret>actor</ret>
+      <port id="source:process:buf" xlink:type="resource" xlink:label="buf">
+        <meta id="visual">
+          <size>
+            <dimension id="height" value="25"/>
+            <dimension id="width" value="75"/>
+          </size>
+          <location>
+            <dimension id="y" value="0"/>
+            <dimension id="x" value="0"/>
+          </location>
+        </meta>
+        <id>buf</id>
+        <type>unsigned int</type>
+        <size>2</size>
+        <restrict></restrict>
+      </port>
+      <bound-to xlink:type="arc" xlink:from="source:process:buf" xlink:to="source:buf"/>
+    </node>
+    <port id="source:buf" xlink:type="resource" xlink:label="buf">
+      <meta id="visual">
+        <size>
+          <dimension id="height" value="25"/>
+          <dimension id="width" value="75"/>
+        </size>
+        <location>
+          <dimension id="y" value="305"/>
+          <dimension id="x" value="168"/>
+        </location>
+      </meta>
+      <id>buf</id>
+      <type>unsigned int</type>
+      <size>2</size>
+      <restrict></restrict>
+    </port>
+  </node>
+</gxf>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.