Author: mes
Date: 2010-08-10 13:02:33 -0700 (Tue, 10 Aug 2010)
New Revision: 21286

Added:
   
core3/model-impl/trunk/src/main/java/org/cytoscape/model/internal/TableManager.java
   
core3/model-impl/trunk/src/test/java/org/cytoscape/model/CyTableManagerTest.java
Modified:
   
core3/model-impl/trunk/src/main/java/org/cytoscape/model/internal/ArrayGraph.java
   
core3/model-impl/trunk/src/main/java/org/cytoscape/model/internal/ArraySubGraph.java
   
core3/model-impl/trunk/src/main/java/org/cytoscape/model/internal/CyNetworkFactoryImpl.java
   
core3/model-impl/trunk/src/main/resources/META-INF/spring/bundle-context-osgi.xml
   core3/model-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml
   
core3/model-impl/trunk/src/test/java/org/cytoscape/model/TestCyNetworkFactory.java
Log:
changed how CyDataTables are managed for networks

Modified: 
core3/model-impl/trunk/src/main/java/org/cytoscape/model/internal/ArrayGraph.java
===================================================================
--- 
core3/model-impl/trunk/src/main/java/org/cytoscape/model/internal/ArrayGraph.java
   2010-08-10 20:01:56 UTC (rev 21285)
+++ 
core3/model-impl/trunk/src/main/java/org/cytoscape/model/internal/ArrayGraph.java
   2010-08-10 20:02:33 UTC (rev 21286)
@@ -44,6 +44,7 @@
 
 import org.cytoscape.event.CyEventHelper;
 import org.cytoscape.model.CyDataTable;
+import org.cytoscape.model.CyTableManager;
 import org.cytoscape.model.CyEdge;
 import org.cytoscape.model.CyNetwork;
 import org.cytoscape.model.CyNode;
@@ -99,14 +100,16 @@
        private final List<CySubNetwork> subNets;
        private final List<CyMetaNode> metaNodes;
        private CySubNetwork base;
+
+       private CyTableManager tableMgr;
        
-       private final Map<String, Map<String, CyDataTable>> dataTableMap;
 
        /**
         * Creates a new ArrayGraph object.
         * @param eh The CyEventHelper used for firing events.
         */
-       public ArrayGraph(final CyEventHelper eh) {
+       public ArrayGraph(final CyEventHelper eh, final CyTableManager 
tableMgr) {
+               this.tableMgr = tableMgr;
                suid = SUIDFactory.getNextSUID();
                numSubNetworks = 0;
                nodeCount = 0;
@@ -121,6 +124,8 @@
 
                
netAttrMgr.get(CyNetwork.DEFAULT_ATTRS).createColumn("name",String.class,false);
                attrs().set("name","");
+               // potential leak since "this" isn't yet fully constructed
+               tableMgr.setTableMap("NETWORK", this, netAttrMgr);
 
                nodeAttrMgr = new HashMap<String, CyDataTable>();
                nodeAttrMgr.put(CyNetwork.DEFAULT_ATTRS, new 
CyDataTableImpl(null, suid + " node", true,eh));
@@ -128,6 +133,7 @@
 
                
nodeAttrMgr.get(CyNetwork.DEFAULT_ATTRS).createColumn("name",String.class,false);
                
nodeAttrMgr.get(CyNetwork.DEFAULT_ATTRS).createColumn("selected",Boolean.class,false);
+               tableMgr.setTableMap("NODE", this, nodeAttrMgr);
 
                edgeAttrMgr = new HashMap<String, CyDataTable>();
                edgeAttrMgr.put(CyNetwork.DEFAULT_ATTRS, new 
CyDataTableImpl(null, suid + " edge", true,eh));
@@ -136,12 +142,8 @@
                
edgeAttrMgr.get(CyNetwork.DEFAULT_ATTRS).createColumn("name",String.class,false);
                
edgeAttrMgr.get(CyNetwork.DEFAULT_ATTRS).createColumn("selected",Boolean.class,false);
                
edgeAttrMgr.get(CyNetwork.DEFAULT_ATTRS).createColumn("interaction",String.class,false);
+               tableMgr.setTableMap("EDGE", this, edgeAttrMgr);
                
-               dataTableMap = new HashMap<String, Map<String, CyDataTable>>();
-               dataTableMap.put(NODE, nodeAttrMgr);
-               dataTableMap.put(EDGE, edgeAttrMgr);
-               dataTableMap.put(NETWORK, netAttrMgr);
-               
                eventHelper = eh;
 
                subNets = new ArrayList<CySubNetwork>();
@@ -582,31 +584,6 @@
                return getCyRow(CyNetwork.DEFAULT_ATTRS);
        }
 
-       /**
-        * {...@inheritdoc}
-        */
-       public Map<String, CyDataTable> getNetworkCyDataTables() {
-               return netAttrMgr;
-       }
-
-       /**
-        * {...@inheritdoc}
-        */
-       public Map<String, CyDataTable> getNodeCyDataTables() {
-               return nodeAttrMgr;
-       }
-
-       /**
-        * {...@inheritdoc}
-        */
-       public Map<String, CyDataTable> getEdgeCyDataTables() {
-               return edgeAttrMgr;
-       }
-       
-       public Map<String, CyDataTable> getCyDataTables(String graphObjectType) 
{
-               return dataTableMap.get(graphObjectType);
-       }
-
        private Iterator<EdgePointer> edgesAdjacent(final NodePointer n, final 
CyEdge.Type edgeType, final int inId) {
                assert(n!=null);
 

Modified: 
core3/model-impl/trunk/src/main/java/org/cytoscape/model/internal/ArraySubGraph.java
===================================================================
--- 
core3/model-impl/trunk/src/main/java/org/cytoscape/model/internal/ArraySubGraph.java
        2010-08-10 20:01:56 UTC (rev 21285)
+++ 
core3/model-impl/trunk/src/main/java/org/cytoscape/model/internal/ArraySubGraph.java
        2010-08-10 20:02:33 UTC (rev 21286)
@@ -232,31 +232,6 @@
        /**
         * {...@inheritdoc}
         */
-       public Map<String,CyDataTable> getNetworkCyDataTables() {
-               return parent.getNetworkCyDataTables();
-       }
-
-       /**
-        * {...@inheritdoc}
-        */
-       public Map<String,CyDataTable> getNodeCyDataTables() {
-               return parent.getNodeCyDataTables();
-       }
-
-       /**
-        * {...@inheritdoc}
-        */
-       public Map<String,CyDataTable> getEdgeCyDataTables() {
-               return parent.getEdgeCyDataTables();
-       }
-       
-       public Map<String, CyDataTable> getCyDataTables(String graphObjectType) 
{
-               return parent.getCyDataTables(graphObjectType);
-       }
-
-       /**
-        * {...@inheritdoc}
-        */
        public CyRow getCyRow(final String namespace) {
                return parent.getCyRow(namespace);
        }

Modified: 
core3/model-impl/trunk/src/main/java/org/cytoscape/model/internal/CyNetworkFactoryImpl.java
===================================================================
--- 
core3/model-impl/trunk/src/main/java/org/cytoscape/model/internal/CyNetworkFactoryImpl.java
 2010-08-10 20:01:56 UTC (rev 21285)
+++ 
core3/model-impl/trunk/src/main/java/org/cytoscape/model/internal/CyNetworkFactoryImpl.java
 2010-08-10 20:02:33 UTC (rev 21286)
@@ -38,6 +38,7 @@
 
 import org.cytoscape.model.CyNetwork;
 import org.cytoscape.model.CyNetworkFactory;
+import org.cytoscape.model.CyTableManager;
 
 
 /**
@@ -46,17 +47,22 @@
 public class CyNetworkFactoryImpl implements CyNetworkFactory {
        
        private final CyEventHelper help;
+       private final CyTableManager mgr;
 
        /**
         * Creates a new CyNetworkFactoryImpl object.
         *
         * @param help An instance of CyEventHelper. 
         */
-       public CyNetworkFactoryImpl(final CyEventHelper help) {
+       public CyNetworkFactoryImpl(final CyEventHelper help, final 
CyTableManager mgr) {
                if (help == null)
                        throw new NullPointerException("CyEventHelper is null");
 
+               if (mgr == null)
+                       throw new NullPointerException("CyTableManager is 
null");
+
                this.help = help;
+               this.mgr = mgr;
        }
 
        /**
@@ -64,7 +70,7 @@
         */
        public CyNetwork getInstance() {
                //return new MGraph(help);
-               ArrayGraph net = new ArrayGraph(help);
+               ArrayGraph net = new ArrayGraph(help,mgr);
                return net.getBaseNetwork(); 
        }
 }

Added: 
core3/model-impl/trunk/src/main/java/org/cytoscape/model/internal/TableManager.java
===================================================================
--- 
core3/model-impl/trunk/src/main/java/org/cytoscape/model/internal/TableManager.java
                         (rev 0)
+++ 
core3/model-impl/trunk/src/main/java/org/cytoscape/model/internal/TableManager.java
 2010-08-10 20:02:33 UTC (rev 21286)
@@ -0,0 +1,93 @@
+
+/*
+ Copyright (c) 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
+ 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 org.cytoscape.model.internal; 
+
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.HashMap;
+
+import org.cytoscape.model.CyDataTable;
+import org.cytoscape.model.CyTableManager;
+import org.cytoscape.model.CyNetwork;
+
+/**
+ * An interface describing a factory used for managing 
+ * {...@link CyDataTable} objects.  This class will be
+ * provided as a service through Spring/OSGi.
+ */
+public class TableManager implements CyTableManager {
+
+       private final Map<String, Map<CyNetwork, Map<String,CyDataTable>>> map;
+
+       public TableManager() {
+               map = new HashMap<String, Map<CyNetwork, 
Map<String,CyDataTable>>>();   
+               map.put( "NETWORK", new HashMap<CyNetwork, 
Map<String,CyDataTable>>() );
+               map.put( "NODE", new HashMap<CyNetwork, 
Map<String,CyDataTable>>() );
+               map.put( "EDGE", new HashMap<CyNetwork, 
Map<String,CyDataTable>>() );
+       }
+
+       public Map<String,CyDataTable> getTableMap(String type, CyNetwork o) {
+               if ( o == null || type == null )
+                       return null;
+
+               Map<CyNetwork, Map<String,CyDataTable>> tmap = map.get(type);
+
+               if ( tmap == null )
+                       throw new IllegalArgumentException("no data tables of 
type: " + type + " exist");
+
+               return map.get(type).get(o);
+       }
+
+       public void setTableMap(String type, CyNetwork net, 
Map<String,CyDataTable> tm) {
+               if ( net == null )
+                       throw new NullPointerException("CyNetwork is null");
+               if ( type == null )
+                       throw new NullPointerException("Type is null");
+
+               if ( !map.containsKey(type) )
+                       map.put(type, new HashMap<CyNetwork, 
Map<String,CyDataTable>>());
+
+               Map<CyNetwork, Map<String,CyDataTable>> tmap = map.get(type);
+
+               if ( tm == null )
+                       tmap.remove(net);
+               else
+                       tmap.put(net,tm);
+       }
+
+}

Modified: 
core3/model-impl/trunk/src/main/resources/META-INF/spring/bundle-context-osgi.xml
===================================================================
--- 
core3/model-impl/trunk/src/main/resources/META-INF/spring/bundle-context-osgi.xml
   2010-08-10 20:01:56 UTC (rev 21285)
+++ 
core3/model-impl/trunk/src/main/resources/META-INF/spring/bundle-context-osgi.xml
   2010-08-10 20:02:33 UTC (rev 21286)
@@ -9,30 +9,21 @@
        <!-- Individual Service -->
        <osgi:service id="cyNetworkFactoryService"
                ref="cyNetworkFactory" 
interface="org.cytoscape.model.CyNetworkFactory">
-               <osgi:service-properties>
-                       <entry key="service.type" value="factory" />
-               </osgi:service-properties>
        </osgi:service>
        
        <osgi:service id="cyDataTableFactoryService"
                ref="cyDataTableFactory" 
interface="org.cytoscape.model.CyDataTableFactory">
-               <osgi:service-properties>
-                       <entry key="service.type" value="factory" />
-               </osgi:service-properties>
        </osgi:service>
        
        <osgi:service id="cyRootNetworkFactoryService"
                ref="cyRootNetworkFactory" 
interface="org.cytoscape.model.subnetwork.CyRootNetworkFactory">
-               <osgi:service-properties>
-                       <entry key="service.type" value="factory" />
-               </osgi:service-properties>
        </osgi:service>
        
        <osgi:service id="cyEventHelperService"
                ref="cyEventHelper" 
interface="org.cytoscape.event.CyEventHelper">
-               <osgi:service-properties>
-                       <entry key="service.type" value="helper" />
-               </osgi:service-properties>
        </osgi:service>
 
+       <osgi:service id="cyTableManagerService"
+               ref="cyTableManager" 
interface="org.cytoscape.model.CyTableManager">
+       </osgi:service>
 </beans>

Modified: 
core3/model-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml
===================================================================
--- 
core3/model-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml    
    2010-08-10 20:01:56 UTC (rev 21285)
+++ 
core3/model-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml    
    2010-08-10 20:02:33 UTC (rev 21286)
@@ -15,8 +15,12 @@
 
        <context:annotation-config/>
        
+       <bean id="cyTableManager" 
class="org.cytoscape.model.internal.TableManager">
+       </bean>
+
        <bean id="cyNetworkFactory" 
class="org.cytoscape.model.internal.CyNetworkFactoryImpl">
                <constructor-arg ref="cyEventHelper" />
+               <constructor-arg ref="cyTableManager" />
        </bean>
 
        <bean id="cyDataTableFactory" 
class="org.cytoscape.model.internal.CyDataTableFactoryImpl">

Added: 
core3/model-impl/trunk/src/test/java/org/cytoscape/model/CyTableManagerTest.java
===================================================================
--- 
core3/model-impl/trunk/src/test/java/org/cytoscape/model/CyTableManagerTest.java
                            (rev 0)
+++ 
core3/model-impl/trunk/src/test/java/org/cytoscape/model/CyTableManagerTest.java
    2010-08-10 20:02:33 UTC (rev 21286)
@@ -0,0 +1,59 @@
+/*
+ Copyright (c) 2008, 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
+ 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 org.cytoscape.model;
+
+import org.cytoscape.model.internal.TableManager;
+
+/**
+ * DOCUMENT ME!
+ */
+public class CyTableManagerTest extends AbstractCyTableManagerTest {
+
+       /**
+        * DOCUMENT ME!
+        */
+       public void setUp() {
+               super.setUp();
+               mgr = new TableManager();
+       }
+
+       /**
+        * DOCUMENT ME!
+        */
+       public void tearDown() {
+               mgr = null;
+       }
+}

Modified: 
core3/model-impl/trunk/src/test/java/org/cytoscape/model/TestCyNetworkFactory.java
===================================================================
--- 
core3/model-impl/trunk/src/test/java/org/cytoscape/model/TestCyNetworkFactory.java
  2010-08-10 20:01:56 UTC (rev 21285)
+++ 
core3/model-impl/trunk/src/test/java/org/cytoscape/model/TestCyNetworkFactory.java
  2010-08-10 20:02:33 UTC (rev 21286)
@@ -40,6 +40,7 @@
 //import org.cytoscape.model.internal.CyNetworkImpl;
 //import org.cytoscape.model.internal.MGraph;
 import org.cytoscape.model.internal.ArrayGraph;
+import org.cytoscape.model.internal.TableManager;
 import org.cytoscape.event.DummyCyEventHelper;
 
 import org.cytoscape.model.subnetwork.CyRootNetwork;
@@ -51,11 +52,11 @@
        public static CyNetwork getInstance() {
                //return new CyNetworkImpl(new DummyCyEventHelper());
                //return new MGraph(new DummyCyEventHelper());
-               return new ArrayGraph(new DummyCyEventHelper());
+               return new ArrayGraph(new DummyCyEventHelper(), new 
TableManager());
        }
 
        public static CyRootNetwork getRootInstance() {
-               return new ArrayGraph(new DummyCyEventHelper());
+               return new ArrayGraph(new DummyCyEventHelper(), new 
TableManager());
        }
 }
 

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