Author: clopes
Date: 2011-12-06 11:17:14 -0800 (Tue, 06 Dec 2011)
New Revision: 27706

Modified:
   
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/HandleGraph.java
   
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/HandleGraphDone.java
   
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/HandleNodeGraph.java
   
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/ReadDataManager.java
Log:
Fixed XGMML parser exception when creating edges whose source or target nodes 
are written under a parent graph tag.
It also fixes the missing "name" (default table) values in sub-networks 
restored from 2.x session files.


Modified: 
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/HandleGraph.java
===================================================================
--- 
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/HandleGraph.java
   2011-12-06 18:28:30 UTC (rev 27705)
+++ 
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/HandleGraph.java
   2011-12-06 19:17:14 UTC (rev 27706)
@@ -110,6 +110,8 @@
                
                if (!(net instanceof CyRootNetwork))
                        manager.addNetwork(oldId, net);
+               
+               manager.getNetworkStack().push(net);
        }
        
        /**

Modified: 
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/HandleGraphDone.java
===================================================================
--- 
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/HandleGraphDone.java
       2011-12-06 18:28:30 UTC (rev 27705)
+++ 
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/HandleGraphDone.java
       2011-12-06 19:17:14 UTC (rev 27706)
@@ -19,6 +19,14 @@
 
        @Override
        public ParseState handle(String tag, Attributes atts, ParseState 
current) throws SAXException {
+               // In order to handle sub-graphs correctly
+               if (!manager.getNetworkStack().isEmpty())
+                       manager.getNetworkStack().pop();
+               
+               final CyNetwork currentNet = 
manager.getNetworkStack().isEmpty() ? null : manager.getNetworkStack().peek();
+               manager.setCurrentNetwork(currentNet);
+               
+               // End of document
                if (++manager.graphDoneCount != manager.graphCount)
                        return current;
                

Modified: 
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/HandleNodeGraph.java
===================================================================
--- 
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/HandleNodeGraph.java
       2011-12-06 18:28:30 UTC (rev 27705)
+++ 
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/HandleNodeGraph.java
       2011-12-06 19:17:14 UTC (rev 27706)
@@ -15,6 +15,7 @@
        @Override
     public ParseState handle(String tag, Attributes atts, ParseState current) 
throws SAXException {
                ParseState state = current;
+               manager.graphCount++;
                
                final CyNode node = manager.currentNode;
                final String href = atts.getValue(ReadDataManager.XLINK, 
"href");
@@ -22,7 +23,7 @@
                
                if (href != null) {
                        // The network has already been created
-                       netId = href.replaceAll(".*#", "");
+                       netId = AttributeValueUtil.getIdFromXLink(href);
                } else {
                        netId = atts.getValue("id");
                        // Create network

Modified: 
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/ReadDataManager.java
===================================================================
--- 
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/ReadDataManager.java
       2011-12-06 18:28:30 UTC (rev 27705)
+++ 
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/ReadDataManager.java
       2011-12-06 19:17:14 UTC (rev 27706)
@@ -16,6 +16,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.Stack;
 
 import org.cytoscape.equations.Equation;
 import org.cytoscape.equations.EquationCompiler;
@@ -59,6 +60,7 @@
        private Map<String, CyEdge> edgeIdMap;
        /* Map of XML ID's to networks */
        private Map<String, CyNetwork> networkIdMap;
+       private Stack<CyNetwork> networkStack;
        
        private Map<CyNetwork, Set<String>> nodeLinkMap;
        private Map<CyNetwork, Set<String>> edgeLinkMap;
@@ -148,6 +150,7 @@
                nodeIdMap = new HashMap<String, CyNode>();
                edgeIdMap = new HashMap<String, CyEdge>();
                networkIdMap = new HashMap<String, CyNetwork>();
+               networkStack = new Stack<CyNetwork>();
                
                nodeLinkMap = new HashMap<CyNetwork, Set<String>>();
                edgeLinkMap = new HashMap<CyNetwork, Set<String>>();
@@ -375,6 +378,10 @@
                return this.currentNetwork;
        }
        
+       protected Stack<CyNetwork> getNetworkStack() {
+               return networkStack;
+       }
+
        protected CyRootNetwork createRootNetwork() {
                final CyNetwork baseNet = networkFactory.createNetwork();
                final CyRootNetwork rootNetwork = 
rootNetworkManager.getRootNetwork(baseNet);
@@ -400,6 +407,7 @@
                if (index != null) {
                        node = this.getParentNetwork().getNode(index);
                        ((CySubNetwork) this.getCurrentNetwork()).addNode(node);
+                       node = this.getCurrentNetwork().getNode(index); // in 
order to return the correct instance!
                }
         }
         
@@ -419,18 +427,41 @@
                CyEdge edge = null;
         
         if (this.getCurrentNetwork() instanceof CySubNetwork && 
this.getParentNetwork() != null) {
-               // Do not create the element again if the network is a 
sub-network!
+               // Do not create the element again if the network is a 
sub-network and the edge already exists!
                Integer index = this.getIndex(id);
                
                if (index != null) {
                        edge = this.getParentNetwork().getEdge(index);
                        ((CySubNetwork) this.getCurrentNetwork()).addEdge(edge);
+                       edge = this.getCurrentNetwork().getEdge(index); // in 
order to return the correct instance!
                }
         }
         
         if (edge == null) {
                // OK, create it
-                       edge = this.getCurrentNetwork().addEdge(source, target, 
directed);
+               CyNetwork net = getCurrentNetwork();
+               // But first get the actual source/target instances from the 
current network,
+               // because both node instances have to belong to the same root 
or sub-network.
+               CyNode actualSrc = net.getNode(source.getIndex());
+               CyNode actualTgt = net.getNode(target.getIndex());
+               
+               if (actualSrc == null || actualTgt == null) {
+                               if ((getDocumentVersion() < 3.0 || 
!isSessionFormat()) && (net == getRootNetwork().getBaseNetwork())) {
+                               // The nodes might have been added to the root 
network only, but not the base one in this case,
+                               // because the root-graph element of old and 
generic XGMML formats are handled as base-network in 3.0
+                               // (3.0 session XGMML has the root-graph as the 
CyRootNetwork, though).
+                               if (actualSrc == null) {
+                                       ((CySubNetwork) net).addNode(source);
+                                       actualSrc = 
net.getNode(source.getIndex());
+                               }
+                               if (actualTgt == null) {
+                                       ((CySubNetwork) net).addNode(target);
+                                       actualTgt = 
net.getNode(target.getIndex());
+                               }
+                       }
+               }
+               
+                       edge = this.getCurrentNetwork().addEdge(actualSrc, 
actualTgt, directed);
         }
         
         // Add to internal cache

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to