Author: ruschein
Date: 2010-06-28 14:08:43 -0700 (Mon, 28 Jun 2010)
New Revision: 20693

Added:
   cytoscape/trunk/src/cytoscape/data/readers/EqnAttrTracker.java
Removed:
   cytoscape/trunk/src/cytoscape/data/readers/AttribEquation.java
Modified:
   cytoscape/trunk/build.xml
   cytoscape/trunk/src/cytoscape/Cytoscape.java
   cytoscape/trunk/src/cytoscape/data/readers/CyAttributesReader.java
   cytoscape/trunk/src/cytoscape/data/readers/CytoscapeSessionReader.java
   cytoscape/trunk/src/cytoscape/data/readers/XGMMLParser.java
   cytoscape/trunk/src/cytoscape/data/readers/XGMMLReader.java
Log:
Completely reorganised equation loading to not error out when invalid equations 
are encountered.

Modified: cytoscape/trunk/build.xml
===================================================================
--- cytoscape/trunk/build.xml   2010-06-28 20:32:09 UTC (rev 20692)
+++ cytoscape/trunk/build.xml   2010-06-28 21:08:43 UTC (rev 20693)
@@ -271,7 +271,7 @@
                       target="${java.target_version}"
                       optimize="on" 
                       includeAntRuntime="false" 
-                      deprecation="yes">
+                      deprecation="no">
                        <classpath refid="classpath" />
                        <include name="cytoscape/**" />
                        <src path="${src.dir}" />

Modified: cytoscape/trunk/src/cytoscape/Cytoscape.java
===================================================================
--- cytoscape/trunk/src/cytoscape/Cytoscape.java        2010-06-28 20:32:09 UTC 
(rev 20692)
+++ cytoscape/trunk/src/cytoscape/Cytoscape.java        2010-06-28 21:08:43 UTC 
(rev 20693)
@@ -1,15 +1,8 @@
 /*
  File: Cytoscape.java
 
- Copyright (c) 2006, The Cytoscape Consortium (www.cytoscape.org)
+ Copyright (c) 2006, 2010, The Cytoscape Consortium (www.cytoscape.org)
 
- The Cytoscape Consortium is:
- - Institute for Systems Biology
- - University of California San Diego
- - Memorial Sloan-Kettering Cancer Center
- - Institut Pasteur
- - Agilent Technologies
-
  This library is free software; you can redistribute it and/or modify it
  under the terms of the GNU Lesser General Public License as published
  by the Free Software Foundation; either version 2.1 of the License, or
@@ -71,6 +64,7 @@
 import cytoscape.data.Semantics;
 import cytoscape.data.readers.BookmarkReader;
 import cytoscape.data.readers.CyAttributesReader;
+import cytoscape.data.readers.EqnAttrTracker;
 import cytoscape.data.readers.GraphReader;
 import cytoscape.data.readers.NestedNetworkReader;
 import cytoscape.data.servers.BioDataServer;
@@ -451,6 +445,14 @@
                return nullNetwork;
        }
 
+       private static EqnAttrTracker eqnAttrTracker = null;
+
+       public static EqnAttrTracker getEqnAttrTracker() {
+               if (eqnAttrTracker == null)
+                       eqnAttrTracker = new EqnAttrTracker();
+               return eqnAttrTracker;
+       }
+
        /**
         * Shuts down Cytoscape, after giving plugins time to react.
         *

Deleted: cytoscape/trunk/src/cytoscape/data/readers/AttribEquation.java
===================================================================
--- cytoscape/trunk/src/cytoscape/data/readers/AttribEquation.java      
2010-06-28 20:32:09 UTC (rev 20692)
+++ cytoscape/trunk/src/cytoscape/data/readers/AttribEquation.java      
2010-06-28 21:08:43 UTC (rev 20693)
@@ -1,60 +0,0 @@
-/*
- File: AttribEquation.java
-
- Copyright (c) 2010, The Cytoscape Consortium (www.cytoscape.org)
-
- This library is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation; either version 2.1 of the License, or
- any later version.
-
- This library is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
- MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  The software and
- documentation provided hereunder is on an "as is" basis, and the
- Institute for Systems Biology and the Whitehead Institute
- have no obligations to provide maintenance, support,
- updates, enhancements or modifications.  In no event shall the
- Institute for Systems Biology and the Whitehead Institute
- be liable to any party for direct, indirect, special,
- incidental or consequential damages, including lost profits, arising
- out of the use of this software and its documentation, even if the
- Institute for Systems Biology and the Whitehead Institute
- have been advised of the possibility of such damage.  See
- the GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with this library; if not, write to the Free Software Foundation,
- Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
-*/
-package cytoscape.data.readers;
-
-
-/**
- *  Utility class used by some readers to record equation attributes for later 
evaluation.
- */
-class AttribEquation {
-       private final String id;
-       private final String attrName;
-       private final String equation;
-       private final byte dataType;
-       private final int lineNumber;
-
-       AttribEquation(final String id, final String attrName, final String 
equation, final byte dataType, final int lineNumber) {
-               this.id         = id;
-               this.attrName   = attrName;
-               this.equation   = equation;
-               this.dataType   = dataType;
-               this.lineNumber = lineNumber;
-       }
-
-       AttribEquation(final String id, final String attrName, final String 
equation, final byte dataType) {
-               this(id, attrName, equation, dataType, -1);
-       }
-
-       String getID() { return id; }
-       String getAttrName() { return attrName; }
-       String getEquation() { return equation; }
-       byte getDataType() { return dataType; }
-       int getLineNumber() { return lineNumber; }
-}

Modified: cytoscape/trunk/src/cytoscape/data/readers/CyAttributesReader.java
===================================================================
--- cytoscape/trunk/src/cytoscape/data/readers/CyAttributesReader.java  
2010-06-28 20:32:09 UTC (rev 20692)
+++ cytoscape/trunk/src/cytoscape/data/readers/CyAttributesReader.java  
2010-06-28 21:08:43 UTC (rev 20693)
@@ -41,6 +41,7 @@
 import java.util.Set;
 import java.util.StringTokenizer;
 
+import cytoscape.Cytoscape;
 import cytoscape.data.CyAttributes;
 import cytoscape.data.attr.MultiHashMapDefinition;
 import cytoscape.data.writers.CyAttributesWriter;
@@ -64,7 +65,6 @@
        private int lineNum;
        private boolean doDecoding;
        final Map<String, Map<String, Class>> idsToAttribNameToTypeMapMap;
-       private List<AttribEquation> attribEquations; // This is where we 
collect equations for later addition.
        private final CyLogger logger;
 
 
@@ -73,7 +73,6 @@
                lineNum = 0;
                doDecoding = 
Boolean.valueOf(System.getProperty(DECODE_PROPERTY, "true"));
                idsToAttribNameToTypeMapMap = new HashMap<String, Map<String, 
Class>>();
-               attribEquations = new ArrayList<AttribEquation>();
        }
 
        /**
@@ -87,7 +86,6 @@
        public static void loadAttributes(final CyAttributes cyAttrs, final 
Reader fileIn) throws IOException {
                CyAttributesReader ar = new CyAttributesReader();
                ar.loadAttributesInternal(cyAttrs, fileIn);
-               ar.addEquations(cyAttrs);
        }
 
        private Class mapCytoscapeAttribTypeToEqnType(final byte attribType) {
@@ -107,53 +105,7 @@
                }
        }
 
-       private void addEquations(final CyAttributes cyAttrs) {
-               final EqnCompiler compiler = new EqnCompiler();
-               final String[] allAttribNames = cyAttrs.getAttributeNames();
-               final Class[] allTypes = new Class[allAttribNames.length];
-               int index = 0;
-               for (final String attribName : allAttribNames) {
-                       final byte type = cyAttrs.getType(attribName);
-                       allTypes[index++] = 
mapCytoscapeAttribTypeToEqnType(type);
-               }
-
-               for (final AttribEquation attribEquation : attribEquations) {
-                       Map<String, Class> attribNameToTypeMap = 
idsToAttribNameToTypeMapMap.get(attribEquation.getID());
-                       if (attribNameToTypeMap == null)
-                               attribNameToTypeMap = new HashMap<String, 
Class>();
-                       for (int i = 0; i < allAttribNames.length; ++i) {
-                               if (allTypes[i] != null)
-                                       
attribNameToTypeMap.put(allAttribNames[i], allTypes[i]);
-                       }
-
-                       if (compiler.compile(attribEquation.getEquation(), 
attribNameToTypeMap))
-                               cyAttrs.setAttribute(attribEquation.getID(), 
attribEquation.getAttrName(), compiler.getEquation(),
-                                                    
attribEquation.getDataType());
-                       else {
-                               final String errorMessage = 
compiler.getLastErrorMsg();
-                               logger.warn("bad equation on line " + 
attribEquation.getLineNumber() + ": " + errorMessage);
-                               final Class eqnType = 
mapCytoscapeAttribTypeToEqnType(attribEquation.getDataType());
-                               final Equation errorEquation = 
Equation.getErrorEquation(attribEquation.getEquation(),
-                                                                               
         eqnType, errorMessage);
-                               cyAttrs.setAttribute(attribEquation.getID(), 
attribEquation.getAttrName(), errorEquation,
-                                                    
attribEquation.getDataType());
-                       }
-               }
-       }
-
        /**
-        *  Helper function for loadAttributesInternal().
-        */
-       private void updateMapToMaps(final String id, final String attribName, 
final Class attribType,
-                                    final Map<String, Map<String, Class>> 
idsToAttribNameToTypeMapMap)
-       {
-               Map<String, Class> attribNameToTypeMap = 
idsToAttribNameToTypeMapMap.get(id);
-               if (attribNameToTypeMap == null)
-                       attribNameToTypeMap = new HashMap<String, Class>();
-               attribNameToTypeMap.put(attribName, attribType);
-       }
-
-       /**
         *  DOCUMENT ME!
         *
         * @param cyAttrs DOCUMENT ME!
@@ -303,7 +255,6 @@
                                                }
                                        }
 
-                                       updateMapToMaps(key, attributeName, 
List.class, idsToAttribNameToTypeMapMap);
                                        cyAttrs.setListAttribute(key, 
attributeName, elmsBuff);
                                } else { // Not a list.
                                        val = decodeString(val);
@@ -336,39 +287,40 @@
                                        }
 
                                        if (equation) {
-                                               final Class javaType;
+                                               final Class eqnReturnType;
                                                switch (type) {
-                                               case 
MultiHashMapDefinition.TYPE_INTEGER:
-                                                       javaType = Long.class;
+                                               case CyAttributes.TYPE_INTEGER:
+                                                       eqnReturnType = 
Long.class;
                                                        break;
-                                               case 
MultiHashMapDefinition.TYPE_FLOATING_POINT:
-                                                       javaType = Double.class;
+                                               case CyAttributes.TYPE_FLOATING:
+                                                       eqnReturnType = 
Double.class;
                                                        break;
-                                               case 
MultiHashMapDefinition.TYPE_BOOLEAN:
-                                                       javaType = 
Boolean.class;
+                                               case CyAttributes.TYPE_BOOLEAN:
+                                                       eqnReturnType = 
Boolean.class;
                                                        break;
-                                               case 
MultiHashMapDefinition.TYPE_STRING:
-                                                       javaType = String.class;
+                                               case CyAttributes.TYPE_STRING:
+                                                       eqnReturnType = 
String.class;
                                                        break;
+                                               case 
CyAttributes.TYPE_SIMPLE_LIST:
+                                                       eqnReturnType = 
List.class;
+                                                       break;
                                                default:
-                                                       throw new 
IllegalStateException("don't know which type to register on line " + lineNum + 
"!");
+                                                       final String message = 
"don't know which equation return type to register on line " + lineNum + "!";
+                                                       
System.err.println(message);
+                                                       logger.warn(message);
+                                                       continue;
                                                }
-                                               updateMapToMaps(key, 
attributeName, javaType, idsToAttribNameToTypeMapMap);
-                                               attribEquations.add(new 
AttribEquation(key, attributeName, val, type, lineNum));
+                                               final EqnAttrTracker 
eqnAttrTracker = Cytoscape.getEqnAttrTracker();
+                                               
eqnAttrTracker.recordEquation(cyAttrs, key, attributeName, val, eqnReturnType);
                                        }
-                                       else if (type == 
MultiHashMapDefinition.TYPE_INTEGER) {
-                                               updateMapToMaps(key, 
attributeName, Long.class, idsToAttribNameToTypeMapMap);
+                                       else if (type == 
MultiHashMapDefinition.TYPE_INTEGER)
                                                cyAttrs.setAttribute(key, 
attributeName, new Integer(val));
-                                       } else if (type == 
MultiHashMapDefinition.TYPE_BOOLEAN) {
-                                               updateMapToMaps(key, 
attributeName, Boolean.class, idsToAttribNameToTypeMapMap);
+                                       else if (type == 
MultiHashMapDefinition.TYPE_BOOLEAN)
                                                cyAttrs.setAttribute(key, 
attributeName, new Boolean(val));
-                                       } else if (type == 
MultiHashMapDefinition.TYPE_FLOATING_POINT) {
-                                               updateMapToMaps(key, 
attributeName, Double.class, idsToAttribNameToTypeMapMap);
+                                       else if (type == 
MultiHashMapDefinition.TYPE_FLOATING_POINT)
                                                cyAttrs.setAttribute(key, 
attributeName, new Double(val));
-                                       } else {
-                                               updateMapToMaps(key, 
attributeName, String.class, idsToAttribNameToTypeMapMap);
+                                       else
                                                cyAttrs.setAttribute(key, 
attributeName, val);
-                                       }
                                }
                        }
                } catch (Exception e) {

Modified: cytoscape/trunk/src/cytoscape/data/readers/CytoscapeSessionReader.java
===================================================================
--- cytoscape/trunk/src/cytoscape/data/readers/CytoscapeSessionReader.java      
2010-06-28 20:32:09 UTC (rev 20692)
+++ cytoscape/trunk/src/cytoscape/data/readers/CytoscapeSessionReader.java      
2010-06-28 21:08:43 UTC (rev 20693)
@@ -1,15 +1,8 @@
 /*
  File: CytoscapeSessionReader.java
 
- Copyright (c) 2006, The Cytoscape Consortium (www.cytoscape.org)
+ Copyright (c) 2006, 2010, The Cytoscape Consortium (www.cytoscape.org)
 
- The Cytoscape Consortium is:
- - Institute for Systems Biology
- - University of California San Diego
- - Memorial Sloan-Kettering Cancer Center
- - Institut Pasteur
- - Agilent Technologies
-
  This library is free software; you can redistribute it and/or modify it
  under the terms of the GNU Lesser General Public License as published
  by the Free Software Foundation; either version 2.1 of the License, or
@@ -396,7 +389,10 @@
                Cytoscape.getDesktop().getVizMapperUI().initializeTableState();
 
                try {
+                       final EqnAttrTracker eqnAttrTracker = 
Cytoscape.getEqnAttrTracker();
+                       eqnAttrTracker.reset();
                        unzipSessionFromURL(true);
+                       eqnAttrTracker.addAllEquations();
                } catch (cytoscape.visual.DuplicateCalculatorNameException 
dcne) {
                        logger.warn("Duplicate VS name found.  It will be 
ignored...", dcne);
                }
@@ -507,7 +503,7 @@
         * @throws IOException
         * @throws JAXBException
         */
-       private void unzipSessionFromURL(boolean loadVizmap) throws 
IOException, JAXBException, Exception {
+       private void unzipSessionFromURL(final boolean loadVizmap) throws 
IOException, JAXBException, Exception {
                extractEntry();
                logger.info("extractEntry: " + (System.currentTimeMillis() - 
start) + " msec.");
 
@@ -681,14 +677,13 @@
                final Unmarshaller unmarshaller = 
jaxbContext.createUnmarshaller();
                InputStream is = null;
 
-        try {
+               try {
                        is = URLUtil.getBasicInputStream(cysessionFileURL);
-            session = (Cysession) unmarshaller.unmarshal(is);
-        }
-        finally {
-            if (is != null) {
+                       session = (Cysession) unmarshaller.unmarshal(is);
+               }
+               finally {
+                       if (is != null)
                                is.close();
-            }
                }
 
                /*
@@ -698,15 +693,13 @@
                sessionID = session.getId();
                netMap = new HashMap<String, Network>();
 
-               for (Network curNet : session.getNetworkTree().getNetwork()) {
+               for (Network curNet : session.getNetworkTree().getNetwork())
                        netMap.put(curNet.getId(), curNet);
-               }
 
                walkTree(netMap.get(NETWORK_ROOT), null, cysessionFileURL);
        }
 
        private void restoreDesktopState() {
-
                // Restore Desktop size
                Cytoscape.getDesktop()
                         
.setSize(session.getSessionState().getDesktop().getDesktopSize().getWidth()
@@ -725,18 +718,18 @@
                                              .getComponents();
 
                for (int i = 0; i < desktopFrames.length; i++) {
-            Component cmp;
+                       Component cmp;
 
-            cmp = desktopFrames[i];
-            if (cmp instanceof JInternalFrame) {
-                JInternalFrame frame = (JInternalFrame)cmp;
-                NetworkFrame nFrame = frameMap.get(frame.getTitle());
+                       cmp = desktopFrames[i];
+                       if (cmp instanceof JInternalFrame) {
+                               JInternalFrame frame = (JInternalFrame)cmp;
+                               NetworkFrame nFrame = 
frameMap.get(frame.getTitle());
 
-                if (nFrame != null) {
-                    frame.setSize(nFrame.getWidth().intValue(), 
nFrame.getHeight().intValue());
-                    frame.setLocation(nFrame.getX().intValue(), 
nFrame.getY().intValue());
-                }
-            }
+                               if (nFrame != null) {
+                                       
frame.setSize(nFrame.getWidth().intValue(), nFrame.getHeight().intValue());
+                                       
frame.setLocation(nFrame.getX().intValue(), nFrame.getY().intValue());
+                               }
+                       }
                }
        }
 
@@ -750,7 +743,8 @@
         * @throws IOException
         */
        private void walkTree(final Network currentNetwork, final CyNetwork 
parent,
-                             final Object sessionSource) throws JAXBException, 
IOException {
+                             final Object sessionSource) throws JAXBException, 
IOException
+       {
                // Get the list of children under this root
                final List<Child> children = currentNetwork.getChild();
 
@@ -796,14 +790,12 @@
 
                                        reader = new XGMMLReader(networkStream);
                                        new_network = 
Cytoscape.createNetwork(reader, false, parent);
-                               }
-                               finally {
-                                       if (networkStream != null) {
+                               } finally {
+                                       if (networkStream != null)
                                                networkStream.close();
-                                       }
                                }
-                       } catch (Exception e) {
-                               String message = "Unable to read XGMML file: 
"+childNet.getFilename()+".  "+e.getMessage();
+                       } catch (final Exception e) {
+                               final String message = "Unable to read XGMML 
file: " + childNet.getFilename() + ".  " + e.getMessage();
                                logger.error(message, e);
                                Cytoscape.destroyNetwork(new_network);
                                if (taskMonitor != null)
@@ -864,9 +856,8 @@
                                setSelectedEdges(new_network, (SelectedEdges) 
childNet.getSelectedEdges());
 
                                // Load child networks
-                               if (childNet.getChild().size() != 0) {
+                               if (childNet.getChild().size() != 0)
                                        walkTree(childNet, new_network, 
sessionSource);
-                               }
                        }
                }
        }

Copied: cytoscape/trunk/src/cytoscape/data/readers/EqnAttrTracker.java (from 
rev 20677, cytoscape/trunk/src/cytoscape/data/readers/XGMMLParser.java)
===================================================================
--- cytoscape/trunk/src/cytoscape/data/readers/EqnAttrTracker.java              
                (rev 0)
+++ cytoscape/trunk/src/cytoscape/data/readers/EqnAttrTracker.java      
2010-06-28 21:08:43 UTC (rev 20693)
@@ -0,0 +1,198 @@
+/*
+ File: EqnAttrTracker.java
+
+ Copyright (c) 2010, The Cytoscape Consortium (www.cytoscape.org)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications.  In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage.  See
+ the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+*/
+package cytoscape.data.readers;
+
+
+import cytoscape.Cytoscape;
+import cytoscape.data.CyAttributes;
+import cytoscape.logger.CyLogger;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.cytoscape.equations.EqnCompiler;
+import org.cytoscape.equations.Equation;
+
+
+public class EqnAttrTracker {
+       private enum AttrClass {
+               NODES(Cytoscape.getNodeAttributes()),
+               EDGES(Cytoscape.getEdgeAttributes()),
+               NETWORKS(Cytoscape.getNetworkAttributes());
+
+               private CyAttributes attribs;
+
+               AttrClass(final CyAttributes attribs) { this.attribs = attribs; 
}
+
+               CyAttributes getAttribs() { return attribs; }
+       };
+       
+
+       private static class AttrInfo {
+               private String id;
+               private String attrName;
+               private String equation;
+               private Class returnType;
+
+               AttrInfo(final String id, final String attrName, final String 
equation, final Class returnType) {
+                       this.id = id;
+                       this.attrName = attrName;
+                       this.equation = equation;
+                       this.returnType = returnType;
+               }
+
+               String getID() { return id; }
+               String getAttrName() { return attrName; }
+               String getEquation() { return equation; }
+               Class getReturnType() { return returnType; }
+       }
+
+       private CyLogger logger;
+       private List<AttrInfo> nodeAttrs, edgeAttrs, networkAttrs;
+
+       public EqnAttrTracker() {
+               logger = CyLogger.getLogger(EqnAttrTracker.class);
+               nodeAttrs = new ArrayList<AttrInfo>();
+               edgeAttrs = new ArrayList<AttrInfo>();
+               networkAttrs = new ArrayList<AttrInfo>();
+       }
+
+       void reset() {
+               nodeAttrs.clear();
+               edgeAttrs.clear();
+               networkAttrs.clear();
+       }
+
+       void recordEquation(final CyAttributes attribs, final String id, final 
String attrName,
+                           final String equation, final Class returnType)
+       {
+               if (attribs == AttrClass.NODES.getAttribs())
+                       nodeAttrs.add(new AttrInfo(id, attrName, equation, 
returnType));
+               else if (attribs == AttrClass.EDGES.getAttribs())
+                       edgeAttrs.add(new AttrInfo(id, attrName, equation, 
returnType));
+               else if (attribs == AttrClass.NETWORKS.getAttribs())
+                       networkAttrs.add(new AttrInfo(id, attrName, equation, 
returnType));
+               else
+                       throw new IllegalArgumentException("unkown 
CyAttributes!");
+
+               if (returnType == Double.class)
+                       registerFloat(attribs, id, attrName);
+               else if (returnType == Long.class)
+                       registerInteger(attribs, id, attrName);
+               else if (returnType == String.class)
+                       registerString(attribs, id, attrName);
+               else if (returnType == Boolean.class)
+                       registerBoolean(attribs, id, attrName);
+               else if (returnType == List.class)
+                       registerList(attribs, id, attrName);
+               else
+                       throw new IllegalArgumentException("unknown retuyrn 
type: " + returnType + "!");
+       }
+
+       void addAllEquations() {
+               addEquations(AttrClass.NODES.getAttribs(), nodeAttrs);
+               addEquations(AttrClass.EDGES.getAttribs(), edgeAttrs);
+               addEquations(AttrClass.NETWORKS.getAttribs(), networkAttrs);
+       }
+
+       private void addEquations(final CyAttributes attribs, final 
List<AttrInfo> attrInfos) {
+               final EqnCompiler compiler = new EqnCompiler();
+               final String[] allAttribNames = attribs.getAttributeNames();
+               final Class[] allTypes = new Class[allAttribNames.length];
+               final Map<String, Class> attribNameToTypeMap = new 
HashMap<String, Class>();
+               int index = 0;
+               for (final String attribName : allAttribNames) {
+                       final byte type = attribs.getType(attribName);
+                       final Class eqnType = 
mapCytoscapeAttribTypeToEqnType(type);
+                       if (eqnType != null)
+                               attribNameToTypeMap.put(attribName, eqnType);
+               }
+               
+               for (final AttrInfo attrInfo : attrInfos) {
+                       attribNameToTypeMap.remove(attrInfo.getAttrName());
+
+                       if (compiler.compile(attrInfo.getEquation(), 
attribNameToTypeMap))
+                               attribs.setAttribute(attrInfo.getID(), 
attrInfo.getAttrName(), compiler.getEquation());
+                       else {
+                               final String errorMessage = 
compiler.getLastErrorMsg();
+                               logger.warn("bad equation on import: " + 
errorMessage);
+                               final Equation errorEquation = 
Equation.getErrorEquation(attrInfo.getEquation(),
+                                                                               
         attrInfo.getReturnType(), errorMessage);
+                               attribs.setAttribute(attrInfo.getID(), 
attrInfo.getAttrName(), errorEquation);
+                       }
+
+                       attribNameToTypeMap.put(attrInfo.getAttrName(), 
attrInfo.getReturnType());
+               }
+       }
+
+       private static Class mapCytoscapeAttribTypeToEqnType(final byte 
attribType) {
+               switch (attribType) {
+               case CyAttributes.TYPE_BOOLEAN:
+                       return Boolean.class;
+               case CyAttributes.TYPE_INTEGER:
+                       return Long.class;
+               case CyAttributes.TYPE_FLOATING:
+                       return Double.class;
+               case CyAttributes.TYPE_STRING:
+                       return String.class;
+               case CyAttributes.TYPE_SIMPLE_LIST:
+                       return List.class;
+               default:
+                       throw new IllegalStateException("can't map Cytoscape 
type " + attribType + " to equation return type!");
+               }
+       }
+
+       private static void registerFloat(final CyAttributes attrs, final 
String id, final String attrName) {
+               attrs.setAttribute(id, attrName, 0.0);
+               attrs.deleteAttribute(id, attrName);
+       }
+
+       private static void registerString(final CyAttributes attrs, final 
String id, final String attrName) {
+               attrs.setAttribute(id, attrName, "");
+               attrs.deleteAttribute(id, attrName);
+       }
+
+       private static void registerInteger(final CyAttributes attrs, final 
String id, final String attrName) {
+               attrs.setAttribute(id, attrName, 0);
+               attrs.deleteAttribute(id, attrName);
+       }
+
+       private static void registerBoolean(final CyAttributes attrs, final 
String id, final String attrName) {
+               attrs.setAttribute(id, attrName, true);
+               attrs.deleteAttribute(id, attrName);
+       }
+
+       private static void registerList(final CyAttributes attrs, final String 
id, final String attrName) {
+               attrs.setListAttribute(id, attrName, new ArrayList());
+               attrs.deleteAttribute(id, attrName);
+       }
+}

Modified: cytoscape/trunk/src/cytoscape/data/readers/XGMMLParser.java
===================================================================
--- cytoscape/trunk/src/cytoscape/data/readers/XGMMLParser.java 2010-06-28 
20:32:09 UTC (rev 20692)
+++ cytoscape/trunk/src/cytoscape/data/readers/XGMMLParser.java 2010-06-28 
21:08:43 UTC (rev 20693)
@@ -43,9 +43,6 @@
 import cytoscape.util.intr.IntEnumerator;
 import cytoscape.logger.CyLogger;
 
-import org.cytoscape.equations.EqnCompiler;
-import org.cytoscape.equations.Equation;
-
 import org.xml.sax.helpers.DefaultHandler;
 import org.xml.sax.helpers.AttributesImpl;
 import org.xml.sax.Attributes;
@@ -118,78 +115,6 @@
 
 
 class XGMMLParser extends DefaultHandler {
-       private enum AttrClass {
-               NODES(Cytoscape.getNodeAttributes()),
-               EDGES(Cytoscape.getEdgeAttributes()),
-               NETWORKS(Cytoscape.getNetworkAttributes());
-
-               private CyAttributes attribs;
-
-               AttrClass(final CyAttributes attribs) { this.attribs = attribs; 
}
-
-               CyAttributes getAttribs() { return attribs; }
-       };
-
-       class AttrNameToTypeMaps {
-               private final Map<String, Class> attribNameToTypeMapForNodes;
-               private final Map<String, Class> attribNameToTypeMapForEdges;
-               private final Map<String, Class> attribNameToTypeMapForNetworks;
-
-               AttrNameToTypeMaps() {
-                       attribNameToTypeMapForNodes    = new HashMap<String, 
Class>();
-                       attribNameToTypeMapForEdges    = new HashMap<String, 
Class>();
-                       attribNameToTypeMapForNetworks = new HashMap<String, 
Class>();
-               }
-
-               void put(final String attrName, final Class attrType, final 
AttrClass attrClass) {
-                       switch (attrClass) {
-                       case NODES:
-                               attribNameToTypeMapForNodes.put(attrName, 
attrType);
-                               break;
-                       case EDGES:
-                               attribNameToTypeMapForEdges.put(attrName, 
attrType);
-                               break;
-                       case NETWORKS:
-                               attribNameToTypeMapForNetworks.put(attrName, 
attrType);
-                               break;
-                       }
-               }
-
-               Map<String, Class> getAttribNameToTypeMapForNodes() { return 
attribNameToTypeMapForNodes; }
-               Map<String, Class> getAttribNameToTypeMapForEdges() { return 
attribNameToTypeMapForEdges; }
-               Map<String, Class> getAttribNameToTypeMapForNetworks() { return 
attribNameToTypeMapForNetworks; }
-       }
-
-       class AttrEqnLists {
-               private final List<AttribEquation> nodeEquations;
-               private final List<AttribEquation> edgeEquations;
-               private final List<AttribEquation> networkEquations;
-
-               AttrEqnLists() {
-                       nodeEquations    = new ArrayList<AttribEquation>();
-                       edgeEquations    = new ArrayList<AttribEquation>();
-                       networkEquations = new ArrayList<AttribEquation>();
-               }
-
-               void add(final AttribEquation equation, final AttrClass 
attrClass) {
-                       switch (attrClass) {
-                       case NODES:
-                               nodeEquations.add(equation);
-                               break;
-                       case EDGES:
-                               edgeEquations.add(equation);
-                               break;
-                       case NETWORKS:
-                               networkEquations.add(equation);
-                               break;
-                       }
-               }
-
-               List<AttribEquation> getNodeEquations() { return nodeEquations; 
}
-               List<AttribEquation> getEdgeEquations() { return edgeEquations; 
}
-               List<AttribEquation> getNetworkEquations() { return 
networkEquations; }
-       }
-
        final static String XLINK = "http://www.w3.org/1999/xlink";;
        final static String RDF = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";;
        final static String DUBLINCORE = "http://purl.org/dc/elements/1.1/";;
@@ -245,10 +170,7 @@
        private ParseState attState = ParseState.NONE;
        private String currentAttributeID = null;
        private CyAttributes currentAttributes = null;
-       private AttrClass currentAttrClass = null;
        private String objectTarget = null;
-       private AttrNameToTypeMaps attrNameToTypeMaps;
-       private AttrEqnLists attrEqnLists;
 
        /* Complex attribute data */
        private int level = 0;
@@ -268,6 +190,8 @@
        /* Y handle */
        private String edgeBendY = null;
 
+       private EqnAttrTracker eqnAttrTracker = null;
+
        /**
         * Main parse table. This table controls the state machine, and follows
         * the standard format for a state machine:
@@ -586,8 +510,7 @@
                nodeGraphicsMap = new HashMap();
                edgeGraphicsMap = new HashMap();
                idMap = new HashMap();
-               attrNameToTypeMaps = new AttrNameToTypeMaps();
-               attrEqnLists = new AttrEqnLists();
+               eqnAttrTracker = Cytoscape.getEqnAttrTracker();
        }
 
 
@@ -617,19 +540,6 @@
        }
 
 
-       void compileAndAddEquationAttribs() {
-               compileAndAddEquationAttribs(attrEqnLists.getNodeEquations(),
-                                            
attrNameToTypeMaps.getAttribNameToTypeMapForNodes(),
-                                            Cytoscape.getNodeAttributes());
-               compileAndAddEquationAttribs(attrEqnLists.getEdgeEquations(),
-                                            
attrNameToTypeMaps.getAttribNameToTypeMapForEdges(),
-                                            Cytoscape.getEdgeAttributes());
-               compileAndAddEquationAttribs(attrEqnLists.getNetworkEquations(),
-                                            
attrNameToTypeMaps.getAttribNameToTypeMapForNetworks(),
-                                            Cytoscape.getNetworkAttributes());
-       }
-
-
        private Class mapCytoscapeAttribTypeToEqnType(final byte attribType) {
                switch (attribType) {
                case CyAttributes.TYPE_BOOLEAN:
@@ -648,31 +558,6 @@
        }
 
 
-       private void compileAndAddEquationAttribs(final List<AttribEquation> 
attribEquations,
-                                                 final Map<String, Class> 
attribNameToTypeMap,
-                                                 final CyAttributes attribs)
-       {
-               attribNameToTypeMap.put("ID", String.class);
-               final EqnCompiler compiler = new EqnCompiler();
-               for (final AttribEquation attribEquation : attribEquations) {
-                       if (compiler.compile(attribEquation.getEquation(), 
attribNameToTypeMap))
-                               attribs.setAttribute(attribEquation.getID(), 
attribEquation.getAttrName(),
-                                                    compiler.getEquation(), 
attribEquation.getDataType());
-                       else {
-                               final String errorMessage = 
compiler.getLastErrorMsg();
-                               logger.warn("failed to compile an equation in 
an XGMML input file ("
-                                           + errorMessage + ")!");
-                               final Equation errorEquation =
-                                       
Equation.getErrorEquation(attribEquation.getEquation(),
-                                                                 
mapCytoscapeAttribTypeToEqnType(attribEquation.getDataType()),
-                                                                 errorMessage);
-                               attribs.setAttribute(attribEquation.getID(), 
attribEquation.getAttrName(),
-                                                    errorEquation, 
attribEquation.getDataType());
-                       }
-               }
-       }
-
-
        HashMap<CyNode, Attributes> getNodeGraphics() {
                return nodeGraphicsMap;
        }
@@ -891,7 +776,6 @@
        class HandleNetworkAttribute implements Handler {
                public ParseState handle(String tag, Attributes atts, 
ParseState current) throws SAXException {
                        currentAttributes = Cytoscape.getNetworkAttributes();
-                       currentAttrClass = AttrClass.NETWORKS;
                        attState = current;
                        ParseState nextState = current;
                        // Look for "special" network attributes
@@ -964,7 +848,6 @@
                        }
 
                        currentAttributes = Cytoscape.getNodeAttributes();
-                       currentAttrClass = AttrClass.NODES;
                        objectTarget = currentNode.getIdentifier();
 
                        ParseState nextState = handleAttribute(atts, 
currentAttributes, objectTarget);
@@ -1042,20 +925,7 @@
        class handleEdgeAttribute implements Handler {
                public ParseState handle(String tag, Attributes atts, 
ParseState current) throws SAXException {
                        attState = current;
-                       // logger.debug("Edge attribute: 
"+printAttribute(atts));
-                       /*
-                       if (atts.getValue("name").startsWith("edge.")) {
-                               // Yes, add it to our nodeGraphicsMap
-                               String name = 
atts.getValue("name").substring(5);
-                               String value = atts.getValue("value");
-                               if (!edgeGraphicsMap.containsKey(currentEdge)) {
-                                       edgeGraphicsMap.put(currentEdge, new 
AttributesImpl());
-                               } 
-                               
((AttributesImpl)edgeGraphicsMap.get(currentEdge)).addAttribute("", "", name, 
"string", value);
-                       }
-                       */
                        currentAttributes = Cytoscape.getEdgeAttributes();
-                       currentAttrClass = AttrClass.EDGES;
                        if (currentEdge != null)
                                objectTarget = currentEdge.getIdentifier();
                        else
@@ -1071,7 +941,6 @@
 
        class handleEdgeGraphics implements Handler {
                public ParseState handle(String tag, Attributes atts, 
ParseState current) throws SAXException {
-                       // logger.debug("Atts for 
"+currentEdge.getIdentifier()+": "+printAttributes(atts));
                        if (tag.equals("graphics")) {
                                if (edgeGraphicsMap.containsKey(currentEdge)) {
                                        
addAttributes(edgeGraphicsMap.get(currentEdge),atts);
@@ -1550,36 +1419,32 @@
                switch (objType) {
                case BOOLEAN:
                        if (obj != null && name != null && id != null) {
-                               attrNameToTypeMaps.put(name, Boolean.class, 
currentAttrClass);
                                if (equation)
-                                       attrEqnLists.add(new AttribEquation(id, 
name, (String)obj, MultiHashMapDefinition.TYPE_BOOLEAN), currentAttrClass);
+                                       eqnAttrTracker.recordEquation(cyAtts, 
id, name, (String)obj, Boolean.class);
                                else
                                        cyAtts.setAttribute(id, name, 
(Boolean)obj);
                        }
                        break;
                case REAL:
                        if (obj != null && name != null && id != null) {
-                               attrNameToTypeMaps.put(name, Double.class, 
currentAttrClass);
                                if (equation)
-                                       attrEqnLists.add(new AttribEquation(id, 
name, (String)obj, MultiHashMapDefinition.TYPE_FLOATING_POINT), 
currentAttrClass);
+                                       eqnAttrTracker.recordEquation(cyAtts, 
id, name, (String)obj, Double.class);
                                else
                                        cyAtts.setAttribute(id, name, 
(Double)obj);
                        }
                        break;
                case INTEGER:
                        if (obj != null && name != null && id != null) {
-                               attrNameToTypeMaps.put(name, Long.class, 
currentAttrClass);
                                if (equation)
-                                       attrEqnLists.add(new AttribEquation(id, 
name, (String)obj, MultiHashMapDefinition.TYPE_INTEGER), currentAttrClass);
+                                       eqnAttrTracker.recordEquation(cyAtts, 
id, name, (String)obj, Long.class);
                                else
                                        cyAtts.setAttribute(id, name, 
(Integer)obj);
                        }
                        break;
                case STRING:
                        if (obj != null && name != null && id != null) {
-                               attrNameToTypeMaps.put(name, String.class, 
currentAttrClass);
                                if (equation)
-                                       attrEqnLists.add(new AttribEquation(id, 
name, (String)obj, MultiHashMapDefinition.TYPE_STRING), currentAttrClass);
+                                       eqnAttrTracker.recordEquation(cyAtts, 
id, name, (String)obj, String.class);
                                else
                                        cyAtts.setAttribute(id, name, 
(String)obj);
                        }
@@ -1593,22 +1458,16 @@
                // must make sure to clear out any existing values before we 
parse.
                case LIST:
                        currentAttributeID = name;
-                       if (id != null && cyAtts.hasAttribute(id, name)) {
+                       if (id != null && cyAtts.hasAttribute(id, name))
                                cyAtts.deleteAttribute(id,name);
-                               if (name != null)
-                                       attrNameToTypeMaps.put(name, 
List.class, currentAttrClass);
-                       }
 
                        listAttrHolder = new ArrayList();
 
                        return ParseState.LISTATT;
                case MAP:
                        currentAttributeID = name;
-                       if (id != null && cyAtts.hasAttribute(id, name)) {
+                       if (id != null && cyAtts.hasAttribute(id, name))
                                cyAtts.deleteAttribute(id,name);
-                               if (name != null)
-                                        attrNameToTypeMaps.put(name, 
Map.class, currentAttrClass);
-                       }
 
                        mapAttrHolder = new HashMap();
 

Modified: cytoscape/trunk/src/cytoscape/data/readers/XGMMLReader.java
===================================================================
--- cytoscape/trunk/src/cytoscape/data/readers/XGMMLReader.java 2010-06-28 
20:32:09 UTC (rev 20692)
+++ cytoscape/trunk/src/cytoscape/data/readers/XGMMLReader.java 2010-06-28 
21:08:43 UTC (rev 20693)
@@ -303,7 +303,6 @@
                                        pa.setErrorHandler(parser);
                                        pa.parse(new 
InputSource(networkStream));
                                        networkName = parser.getNetworkName();
-                                       parser.compileAndAddEquationAttribs();
                                } catch (OutOfMemoryError oe) {
                                        /*
                                         * It's not generally a good idea to 
catch OutOfMemoryErrors, but in

-- 
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