Author: mkirby
Date: 2012-06-25 18:39:46 -0700 (Mon, 25 Jun 2012)
New Revision: 29689
Added:
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/cytobridge/
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/cytobridge/NetworkManager.java
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/cytobridge/NetworkSync.java
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/cytobridge/rpc/
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/cytobridge/rpc/CytoBridgeRequestProcessorFactoryFactory.java
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/cytobridge/rpc/CytoscapeRPCCallHandler.java
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/cytobridge/rpc/CytoscapeRPCServer.java
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/cytobridge/rpc/RPCLogger.java
Removed:
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/cytobridge/CytoscapeRPCCallHandler.java
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/cytobridge/CytoscapeRPCServer.java
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/cytobridge/RPCLogger.java
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/sample/
Modified:
csplugins/trunk/soc/mkirby/CytoBridge/pom.xml
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/cytobridge/CyActivator.java
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/cytobridge/CytoBridgeAction.java
Log:
mkirby: Got network creation working.
Modified: csplugins/trunk/soc/mkirby/CytoBridge/pom.xml
===================================================================
--- csplugins/trunk/soc/mkirby/CytoBridge/pom.xml 2012-06-25 23:47:43 UTC
(rev 29688)
+++ csplugins/trunk/soc/mkirby/CytoBridge/pom.xml 2012-06-26 01:39:46 UTC
(rev 29689)
@@ -2,15 +2,15 @@
<modelVersion>4.0.0</modelVersion>
<properties>
- <bundle.symbolicName>sample03</bundle.symbolicName>
-
<bundle.namespace>org.cytoscape.sample.internal</bundle.namespace>
+ <bundle.symbolicName>CytoBridge</bundle.symbolicName>
+ <bundle.namespace>org.cytoscape.cytobridge</bundle.namespace>
<cytoscape.api.version>3.0.0-alpha8-SNAPSHOT</cytoscape.api.version>
<maven-bundle-plugin.version>2.3.4</maven-bundle-plugin.version>
<osgi.api.version>4.2.0</osgi.api.version>
</properties>
- <groupId>org.cytoscape.sample</groupId>
+ <groupId>org.cytoscape.cytobridge</groupId>
<artifactId>CytoBridge</artifactId>
<packaging>bundle</packaging>
<name>${bundle.symbolicName}</name>
@@ -71,9 +71,13 @@
<artifactId>swing-application-api</artifactId>
<version>${cytoscape.api.version}</version>
</dependency>
-
<dependency>
<groupId>org.cytoscape</groupId>
+ <artifactId>core-task-api</artifactId>
+ <version>${cytoscape.api.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.cytoscape</groupId>
<artifactId>work-api</artifactId>
<version>${cytoscape.api.version}</version>
<scope>provided</scope>
@@ -91,10 +95,10 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>xerces</groupId>
- <artifactId>xerces</artifactId>
- <version>1.2.3</version>
- </dependency>
+ <groupId>xerces</groupId>
+ <artifactId>xercesImpl</artifactId>
+ <version>2.10.0</version>
+</dependency>
<dependency>
<groupId>org.apache.xmlrpc</groupId>
<artifactId>xmlrpc-server</artifactId>
Modified:
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/cytobridge/CyActivator.java
===================================================================
---
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/sample/internal/CyActivator.java
2012-06-22 20:01:34 UTC (rev 29662)
+++
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/cytobridge/CyActivator.java
2012-06-26 01:39:46 UTC (rev 29689)
@@ -1,4 +1,4 @@
-package org.cytoscape.sample.internal;
+package org.cytoscape.cytobridge;
/*
Copyright (c) 2010 Delft University of Technology (www.tudelft.nl)
@@ -29,7 +29,12 @@
import org.cytoscape.application.swing.CyAction;
import org.cytoscape.application.swing.CySwingApplication;
+import org.cytoscape.model.CyNetworkFactory;
+import org.cytoscape.model.CyNetworkManager;
import org.cytoscape.service.util.AbstractCyActivator;
+import org.cytoscape.task.create.NewEmptyNetworkViewFactory;
+import org.cytoscape.view.model.CyNetworkViewFactory;
+import org.cytoscape.view.model.CyNetworkViewManager;
import org.osgi.framework.BundleContext;
@@ -51,8 +56,16 @@
public void start(BundleContext bc) {
+ CyNetworkFactory netFact =
getService(bc,CyNetworkFactory.class);
+ CyNetworkManager netMan = getService(bc,CyNetworkManager.class);
+ CyNetworkViewFactory netViewFact =
getService(bc,CyNetworkViewFactory.class);
+ CyNetworkViewManager netViewMan =
getService(bc,CyNetworkViewManager.class);
+
CySwingApplication cytoscapeDesktopService =
getService(bc,CySwingApplication.class);
- CytoBridgeAction cytoBridgeAction = new
CytoBridgeAction(cytoscapeDesktopService);
+
+ NetworkManager myManager = new NetworkManager(netFact,
netViewFact, netMan, netViewMan);
+
+ CytoBridgeAction cytoBridgeAction = new
CytoBridgeAction(cytoscapeDesktopService, myManager);
registerService(bc,cytoBridgeAction,CyAction.class, new
Properties());
}
}
Modified:
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/cytobridge/CytoBridgeAction.java
===================================================================
---
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/sample/internal/CytoBridgeAction.java
2012-06-22 20:01:34 UTC (rev 29662)
+++
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/cytobridge/CytoBridgeAction.java
2012-06-26 01:39:46 UTC (rev 29689)
@@ -1,4 +1,4 @@
-package org.cytoscape.sample.internal;
+package org.cytoscape.cytobridge;
import java.awt.event.ActionEvent;
import java.io.IOException;
@@ -8,13 +8,21 @@
import org.apache.xmlrpc.XmlRpcException;
import org.cytoscape.application.swing.AbstractCyAction;
import org.cytoscape.application.swing.CySwingApplication;
+import org.cytoscape.cytobridge.rpc.CytoscapeRPCServer;
+import org.cytoscape.model.CyNetworkFactory;
+import org.cytoscape.model.CyNetworkManager;
+import org.cytoscape.task.create.NewEmptyNetworkViewFactory;
+import org.cytoscape.view.model.CyNetworkViewFactory;
+import org.cytoscape.view.model.CyNetworkViewManager;
public class CytoBridgeAction extends AbstractCyAction {
CytoscapeRPCServer xmlrpcServer = null;
private CySwingApplication desktopApp;
- public CytoBridgeAction(CySwingApplication desktopApp){
+ private NetworkManager myManager;
+
+ public CytoBridgeAction(CySwingApplication desktopApp, NetworkManager
myManager){
// Add a menu item -- Plugins->sample03
super("CytoBridge");
setPreferredMenu("Apps");
@@ -27,6 +35,7 @@
//putValue(SMALL_ICON, smallIcon);
this.desktopApp = desktopApp;
+ this.myManager = myManager;
}
/**
@@ -73,7 +82,7 @@
try {
System.out.println("XML-RPC Port: " + port);
xmlrpcServer = new CytoscapeRPCServer(port, localOnly);
- xmlrpcServer.startXmlServer();
+ xmlrpcServer.startXmlServer(myManager);
}
catch (XmlRpcException ex) {
ex.printStackTrace();
Deleted:
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/cytobridge/CytoscapeRPCCallHandler.java
===================================================================
---
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/sample/internal/CytoscapeRPCCallHandler.java
2012-06-22 20:01:34 UTC (rev 29662)
+++
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/cytobridge/CytoscapeRPCCallHandler.java
2012-06-26 01:39:46 UTC (rev 29689)
@@ -1,118 +0,0 @@
-package org.cytoscape.sample.internal;
-
-/*
-Copyright (c) 2010 Delft University of Technology (www.tudelft.nl)
-
-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 3.0 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 Delft
-University of Technology has no obligations to provide maintenance,
-support, updates, enhancements or modifications.
-In no event shall the Delft University of Technology 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 Delft University of
-Technology 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.
-*/
-
-import java.awt.Color;
-import java.lang.reflect.Method;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.Vector;
-import javax.jws.WebParam;
-
-import javax.swing.JOptionPane;
-
-import org.apache.xmlrpc.XmlRpcException;
-import sun.reflect.generics.reflectiveObjects.NotImplementedException;
-
-/**
-* This class implements all the supported methods for the Cytoscape XMLRPC
-* server. It acts as a basic translator of XMLRPC calls to native Cytoscape
-* functions with some additional error checking.
-*
-* @author Jan Bot
-* @version 1.6 Scooter
-*/
-public class CytoscapeRPCCallHandler {
-
- /**
- * Constructs a CytoscapeRPCCallHandler.
- */
- public CytoscapeRPCCallHandler() {
- System.out.println("Instanciating CytoscapeRPCCallHandler");
- }
-
- /*************************************************************
- * Helper functions
- * Functions which make working with CytoscapeRPC easier.
- *************************************************************/
-
- /**
- * Minimal method to test if the connection is working.
- * @return The string "It works!".
- */
-
- public String test() {
- System.out.println("Starting now!");
- return "It works!";
- }
-
-
- /**
- * Returns a string representing the version of the plugin.
- * @return
- */
- public String version() {
- return "1.8";
- }
-
- /*************************************************************
- * Internal classes
- * Implement classes which are used internally for e.g.
- * comparisons.
- *************************************************************/
- private class MethodCompare implements Comparator<Method> {
-
- public int compare(Method o1, Method o2) {
- return o1.getName().compareTo(o2.getName());
- }
- }
-
- /**
- * Creates a hashmap out of a list of keys and a list of values
- */
- protected static <A, B> HashMap<A,B> arraysToMap(A[] keys, B[] values)
- throws XmlRpcException {
- if (keys.length != values.length)
- throw new XmlRpcException("Sizes of input lists do not match.");
-
- HashMap<A,B> mapping = new HashMap<A,B>();
- for(int i=0;i<keys.length;i++)
- mapping.put(keys[i],values[i]);
- return mapping;
- }
-
-}
-
Deleted:
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/cytobridge/CytoscapeRPCServer.java
===================================================================
---
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/sample/internal/CytoscapeRPCServer.java
2012-06-22 20:01:34 UTC (rev 29662)
+++
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/cytobridge/CytoscapeRPCServer.java
2012-06-26 01:39:46 UTC (rev 29689)
@@ -1,107 +0,0 @@
-package org.cytoscape.sample.internal;
-
-/*
-Copyright (c) 2010 Delft University of Technology (www.tudelft.nl)
-
-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 3.0 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 Delft
-University of Technology has no obligations to provide maintenance,
-support, updates, enhancements or modifications.
-In no event shall the Delft University of Technology 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 Delft University of
-Technology 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.
-*/
-
-import java.io.IOException;
-import org.apache.xmlrpc.*;
-import org.apache.xmlrpc.server.*;
-import org.apache.xmlrpc.webserver.*;
-
-
-/**
-* XML-RPC server class for CytoscapeRPC.
-* Manages the XML-RPC server.
-* @author Jan Bot
-*/
-public class CytoscapeRPCServer {
-
- private int port = 9000;
- private boolean localOnly = false;
- private WebServer webServer = null;
- private XmlRpcServer xmlRpcServer = null;
-
- /**
- * Instanciate the CytoscapeRPCServer
- * @param port port number to listen on.
- * @param localOnly whether the plug-in should listen for local traffic
- * only.
- * @throws XmlRpcException
- * @throws IOException
- */
- public CytoscapeRPCServer(int port, boolean localOnly)
- throws XmlRpcException, IOException {
- this.port = port;
- this.localOnly = localOnly;
- webServer = new WebServer(port);
- }
-
- /**
- * Starts the XML-RPC server.
- * @throws XmlRpcException When the port can not be allocated.
- * @throws IOException
- */
- public void startXmlServer() throws XmlRpcException, IOException{
- if(localOnly) {
- webServer.setParanoid(true);
- webServer.acceptClient("127.0.0.1");
- webServer.acceptClient("0.0.0.0");
- }
-
- xmlRpcServer = webServer.getXmlRpcServer();
- PropertyHandlerMapping phm = new PropertyHandlerMapping();
- phm.addHandler("Cytoscape", CytoscapeRPCCallHandler.class);
-
- xmlRpcServer.setHandlerMapping(phm);
-
- XmlRpcServerConfigImpl serverConfig =
- (XmlRpcServerConfigImpl) xmlRpcServer.getConfig();
- serverConfig.setEnabledForExtensions(true);
- serverConfig.setContentLengthOptional(false);
-
- webServer.start();
- System.out.println("Starting now!");
- }
-
- /**
- * Stops the XML-RPC server.
- */
- public void stop(){
- webServer.shutdown();
- xmlRpcServer = null;
- //webServer = null;
- }
-
- /**
- * Main method to test if the server works (stand-alone).
- * @param args command line arguments
- * @throws Exception when anything goes wrong in the XML-RPC server.
- */
- public static void main(String[] args) throws Exception {
- CytoscapeRPCServer s = new CytoscapeRPCServer(9000, false);
- }
-}
Added:
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/cytobridge/NetworkManager.java
===================================================================
---
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/cytobridge/NetworkManager.java
(rev 0)
+++
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/cytobridge/NetworkManager.java
2012-06-26 01:39:46 UTC (rev 29689)
@@ -0,0 +1,82 @@
+package org.cytoscape.cytobridge;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Vector;
+
+import org.cytoscape.model.CyEdge;
+import org.cytoscape.model.CyNetwork;
+import org.cytoscape.model.CyNetworkFactory;
+import org.cytoscape.model.CyNetworkManager;
+import org.cytoscape.model.CyNode;
+import org.cytoscape.view.model.CyNetworkView;
+import org.cytoscape.view.model.CyNetworkViewFactory;
+import org.cytoscape.view.model.CyNetworkViewManager;
+
+public class NetworkManager {
+
+ private CyNetworkFactory netFact;
+ private CyNetworkViewFactory netViewFact;
+ private CyNetworkManager netMan;
+ private CyNetworkViewManager netViewMan;
+
+ private Map<String, NetworkSync> currentNets;
+
+ public NetworkManager(CyNetworkFactory netFact, CyNetworkViewFactory
netViewFact,
+ CyNetworkManager
netMan, CyNetworkViewManager netViewMan) {
+
+ this.netFact = netFact;
+ this.netViewFact = netViewFact;
+ this.netMan = netMan;
+ this.netViewMan = netViewMan;
+
+ currentNets = new HashMap<String, NetworkSync>();
+ }
+
+ public void pushNetwork(String netName, Vector<Integer> nodes,
Vector<Double> edgeFrom, Vector<Double> edgeTo) {
+
+ if (currentNets.containsKey(netName)) {
+ System.out.println("Updating network "+netName);
+ CyNetwork network =
currentNets.get(netName).getNetwork();
+ CyNode node = network.addNode();
+ network.getRow(node).set(CyNetwork.NAME, "55");
+ } else {
+ System.out.println("Creating network "+netName);
+ CyNetwork network = netFact.createNetwork();
+ network.getRow(network).set(CyNetwork.NAME,netName);
+
+ currentNets.put(netName, new NetworkSync(network));
+
+ Map<String, CyNode> nMap = new HashMap<String,
CyNode>();
+
+ for (Integer n : nodes) {
+ CyNode node = network.addNode();
+ network.getRow(node).set(CyNetwork.NAME, n+"");
+ nMap.put(n+"", node);
+ System.out.println("Added node "+n);
+ }
+ System.out.println("Got nodes...");
+ for (int e=0; e<edgeFrom.size();e++) {
+ CyNode fromNode =
nMap.get(edgeFrom.get(e).intValue()+"");
+ CyNode toNode =
nMap.get(edgeTo.get(e).intValue()+"");
+ CyEdge edge = network.addEdge(fromNode, toNode,
false);
+ network.getRow(edge).set(CyNetwork.NAME, e+"");
+ }
+ System.out.println("Got edges...");
+
+ CyNetworkView networkView =
netViewFact.createNetworkView(network);
+ netMan.addNetwork(network);
+ netViewMan.addNetworkView(networkView);
+ }
+
+ //create network, record network id
+ //create map from r-id to suid or Cynode
+ //create similar ,map for edges
+ //create all nodes, update maps
+ //create all edges, update maps
+ //create view
+ //register network
+ //register view
+ }
+
+}
Added:
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/cytobridge/NetworkSync.java
===================================================================
---
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/cytobridge/NetworkSync.java
(rev 0)
+++
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/cytobridge/NetworkSync.java
2012-06-26 01:39:46 UTC (rev 29689)
@@ -0,0 +1,17 @@
+package org.cytoscape.cytobridge;
+
+import org.cytoscape.model.CyNetwork;
+
+public class NetworkSync {
+
+ private CyNetwork network;
+
+ public NetworkSync(CyNetwork net) {
+ this.network = net;
+ }
+
+ public CyNetwork getNetwork() {
+ return network;
+ }
+
+}
Deleted:
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/cytobridge/RPCLogger.java
===================================================================
---
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/sample/internal/RPCLogger.java
2012-06-22 20:01:34 UTC (rev 29662)
+++
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/cytobridge/RPCLogger.java
2012-06-26 01:39:46 UTC (rev 29689)
@@ -1,77 +0,0 @@
-package org.cytoscape.sample.internal;
-
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import org.apache.xmlrpc.XmlRpcException;
-
-/**
- *
- * @author Jan Bot
- */
-public class RPCLogger {
-
- public static enum RPCLogLevel {
- DEBUG(10, "DEBUG"),
- MESSAGE(20, "MESSAGE"),
- WARNING(30, "WARNING"),
- ERROR(40, "ERROR");
-
- int level;
- String str;
- RPCLogLevel(int level, String str) {
- this.level = level;
- this.str = str;
- }
- }
-
- public static Map<String, RPCLogLevel> RPCLogMap =
- Collections.unmodifiableMap(new HashMap<String, RPCLogLevel>() {
- {
- put("DEBUG", RPCLogLevel.DEBUG);
- put("MESSAGE", RPCLogLevel.MESSAGE);
- put("WARNING", RPCLogLevel.WARNING);
- put("ERROR", RPCLogLevel.ERROR);
- }
- });
-
- private RPCLogger(){
-
- }
-
- public static void setLogLevel(RPCLogLevel l) {
- level = l;
- }
-
- public static void setLogLevel(String logStr) {
- level = RPCLogMap.get(logStr);
- }
-
- public static void addMessage(RPCLogLevel l, String message) {
- if(l.level >= level.level) {
- //Cytoscape.getDesktop().setStatusBarMsg(message);
- }
- }
-
- public static boolean setRPCLogLevel(String l) throws XmlRpcException {
- if(RPCLogMap.containsKey(l)) {
- level = RPCLogMap.get(l);
- }
- else {
- throw new XmlRpcException("Log level does not exist.");
- }
- return true;
- }
-
- public static RPCLogLevel getRPCLogLevel() {
- return level;
- }
-
- private static RPCLogLevel level = RPCLogLevel.ERROR;
-}
-
Added:
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/cytobridge/rpc/CytoBridgeRequestProcessorFactoryFactory.java
===================================================================
---
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/cytobridge/rpc/CytoBridgeRequestProcessorFactoryFactory.java
(rev 0)
+++
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/cytobridge/rpc/CytoBridgeRequestProcessorFactoryFactory.java
2012-06-26 01:39:46 UTC (rev 29689)
@@ -0,0 +1,30 @@
+package org.cytoscape.cytobridge.rpc;
+
+import org.apache.xmlrpc.XmlRpcException;
+import org.apache.xmlrpc.XmlRpcRequest;
+import org.apache.xmlrpc.server.RequestProcessorFactoryFactory;
+
+public class CytoBridgeRequestProcessorFactoryFactory implements
+ RequestProcessorFactoryFactory {
+
+ private final RequestProcessorFactory factory =
+ new CytoBridgeRequestProcessorFactory();
+
+ private final CytoscapeRPCCallHandler handler;
+
+ public CytoBridgeRequestProcessorFactoryFactory(CytoscapeRPCCallHandler
handler) {
+ this.handler = handler;
+ }
+
+ public RequestProcessorFactory getRequestProcessorFactory(Class aClass)
+ throws XmlRpcException {
+ return factory;
+ }
+
+ private class CytoBridgeRequestProcessorFactory implements
RequestProcessorFactory {
+ public Object getRequestProcessor(XmlRpcRequest xmlRpcRequest)
+ throws XmlRpcException {
+ return handler;
+ }
+ }
+ }
Added:
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/cytobridge/rpc/CytoscapeRPCCallHandler.java
===================================================================
---
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/cytobridge/rpc/CytoscapeRPCCallHandler.java
(rev 0)
+++
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/cytobridge/rpc/CytoscapeRPCCallHandler.java
2012-06-26 01:39:46 UTC (rev 29689)
@@ -0,0 +1,121 @@
+package org.cytoscape.cytobridge.rpc;
+
+/*
+Copyright (c) 2010 Delft University of Technology (www.tudelft.nl)
+
+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 3.0 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 Delft
+University of Technology has no obligations to provide maintenance,
+support, updates, enhancements or modifications.
+In no event shall the Delft University of Technology 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 Delft University of
+Technology 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.
+*/
+
+import java.lang.reflect.Method;
+
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Vector;
+import org.apache.xmlrpc.XmlRpcException;
+import org.cytoscape.cytobridge.NetworkManager;
+import org.cytoscape.task.create.NewEmptyNetworkViewFactory;
+
+/**
+* This class implements all the supported methods for the Cytoscape XMLRPC
+* server. It acts as a basic translator of XMLRPC calls to native Cytoscape
+* functions with some additional error checking.
+*
+* @author Jan Bot
+* @version 1.6 Scooter
+*/
+public class CytoscapeRPCCallHandler {
+
+ private NetworkManager myManager;
+
+ /**
+ * Constructs a CytoscapeRPCCallHandler.
+ */
+ public CytoscapeRPCCallHandler(NetworkManager myManager) {
+ System.out.println("Instanciating CytoscapeRPCCallHandler");
+ this.myManager = myManager;
+ }
+
+ /*************************************************************
+ * Helper functions
+ * Functions which make working with CytoscapeRPC easier.
+ *************************************************************/
+
+ /**
+ * Minimal method to test if the connection is working.
+ * @return The string "It works!".
+ */
+
+ public String test(Vector<String> nodes) {
+ System.out.println("Got "+nodes.size()+" nodes!");
+ return "Thanks";
+ }
+
+ public String pushNetwork(String name, Vector<Integer> nodes,
Vector<Double> edgeFrom, Vector<Double> edgeTo) throws XmlRpcException {
+ if (edgeFrom.size()!=edgeTo.size()) {
+ throw new XmlRpcException("Edge Communication error!");
+ }
+ System.out.println("Got "+nodes.size()+" nodes.");
+
+ myManager.pushNetwork(name, nodes, edgeFrom, edgeTo);
+
+ return "Pushed to Cytoscape.";
+ }
+
+
+ /**
+ * Returns a string representing the version of the plugin.
+ * @return
+ */
+ public String version() {
+ return "1.8";
+ }
+
+ /*************************************************************
+ * Internal classes
+ * Implement classes which are used internally for e.g.
+ * comparisons.
+ *************************************************************/
+ private class MethodCompare implements Comparator<Method> {
+
+ public int compare(Method o1, Method o2) {
+ return o1.getName().compareTo(o2.getName());
+ }
+ }
+
+ /**
+ * Creates a hashmap out of a list of keys and a list of values
+ */
+ protected static <A, B> HashMap<A,B> arraysToMap(A[] keys, B[] values)
+ throws XmlRpcException {
+ if (keys.length != values.length)
+ throw new XmlRpcException("Sizes of input lists do not match.");
+
+ HashMap<A,B> mapping = new HashMap<A,B>();
+ for(int i=0;i<keys.length;i++)
+ mapping.put(keys[i],values[i]);
+ return mapping;
+ }
+
+}
+
Added:
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/cytobridge/rpc/CytoscapeRPCServer.java
===================================================================
---
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/cytobridge/rpc/CytoscapeRPCServer.java
(rev 0)
+++
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/cytobridge/rpc/CytoscapeRPCServer.java
2012-06-26 01:39:46 UTC (rev 29689)
@@ -0,0 +1,116 @@
+package org.cytoscape.cytobridge.rpc;
+
+/*
+Copyright (c) 2010 Delft University of Technology (www.tudelft.nl)
+
+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 3.0 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 Delft
+University of Technology has no obligations to provide maintenance,
+support, updates, enhancements or modifications.
+In no event shall the Delft University of Technology 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 Delft University of
+Technology 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.
+*/
+
+import java.io.IOException;
+import org.apache.xmlrpc.*;
+import org.apache.xmlrpc.server.*;
+import org.apache.xmlrpc.webserver.*;
+import org.cytoscape.cytobridge.NetworkManager;
+import org.cytoscape.model.CyNetworkFactory;
+import org.cytoscape.model.CyNetworkManager;
+import org.cytoscape.task.create.NewEmptyNetworkViewFactory;
+import org.cytoscape.view.model.CyNetworkViewFactory;
+import org.cytoscape.view.model.CyNetworkViewManager;
+
+
+/**
+* XML-RPC server class for CytoscapeRPC.
+* Manages the XML-RPC server.
+* @author Jan Bot
+*/
+public class CytoscapeRPCServer {
+
+ private int port = 9000;
+ private boolean localOnly = false;
+ private WebServer webServer = null;
+ private XmlRpcServer xmlRpcServer = null;
+
+ /**
+ * Instanciate the CytoscapeRPCServer
+ * @param port port number to listen on.
+ * @param localOnly whether the plug-in should listen for local traffic
+ * only.
+ * @throws XmlRpcException
+ * @throws IOException
+ */
+ public CytoscapeRPCServer(int port, boolean localOnly)
+ throws XmlRpcException, IOException {
+ this.port = port;
+ this.localOnly = localOnly;
+ webServer = new WebServer(port);
+ }
+
+ /**
+ * Starts the XML-RPC server.
+ * @throws XmlRpcException When the port can not be allocated.
+ * @throws IOException
+ */
+ public void startXmlServer(NetworkManager myManager) throws
XmlRpcException, IOException{
+ if(localOnly) {
+ webServer.setParanoid(true);
+ webServer.acceptClient("127.0.0.1");
+ webServer.acceptClient("0.0.0.0");
+ }
+
+ xmlRpcServer = webServer.getXmlRpcServer();
+ PropertyHandlerMapping phm = new PropertyHandlerMapping();
+ CytoscapeRPCCallHandler handler = new
CytoscapeRPCCallHandler(myManager);
+ phm.setRequestProcessorFactoryFactory(new
CytoBridgeRequestProcessorFactoryFactory(handler));
+ phm.setVoidMethodEnabled(true);
+ phm.addHandler("Cytoscape", CytoscapeRPCCallHandler.class);
+
+ xmlRpcServer.setHandlerMapping(phm);
+
+ XmlRpcServerConfigImpl serverConfig =
+ (XmlRpcServerConfigImpl) xmlRpcServer.getConfig();
+ serverConfig.setEnabledForExtensions(true);
+ serverConfig.setContentLengthOptional(false);
+
+ webServer.start();
+ System.out.println("Starting now!");
+ }
+
+ /**
+ * Stops the XML-RPC server.
+ */
+ public void stop(){
+ webServer.shutdown();
+ xmlRpcServer = null;
+ //webServer = null;
+ }
+
+ /**
+ * Main method to test if the server works (stand-alone).
+ * @param args command line arguments
+ * @throws Exception when anything goes wrong in the XML-RPC server.
+ */
+ public static void main(String[] args) throws Exception {
+ CytoscapeRPCServer s = new CytoscapeRPCServer(9000, false);
+ }
+}
Added:
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/cytobridge/rpc/RPCLogger.java
===================================================================
---
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/cytobridge/rpc/RPCLogger.java
(rev 0)
+++
csplugins/trunk/soc/mkirby/CytoBridge/src/main/java/org/cytoscape/cytobridge/rpc/RPCLogger.java
2012-06-26 01:39:46 UTC (rev 29689)
@@ -0,0 +1,77 @@
+package org.cytoscape.cytobridge.rpc;
+
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.xmlrpc.XmlRpcException;
+
+/**
+ *
+ * @author Jan Bot
+ */
+public class RPCLogger {
+
+ public static enum RPCLogLevel {
+ DEBUG(10, "DEBUG"),
+ MESSAGE(20, "MESSAGE"),
+ WARNING(30, "WARNING"),
+ ERROR(40, "ERROR");
+
+ int level;
+ String str;
+ RPCLogLevel(int level, String str) {
+ this.level = level;
+ this.str = str;
+ }
+ }
+
+ public static Map<String, RPCLogLevel> RPCLogMap =
+ Collections.unmodifiableMap(new HashMap<String, RPCLogLevel>() {
+ {
+ put("DEBUG", RPCLogLevel.DEBUG);
+ put("MESSAGE", RPCLogLevel.MESSAGE);
+ put("WARNING", RPCLogLevel.WARNING);
+ put("ERROR", RPCLogLevel.ERROR);
+ }
+ });
+
+ private RPCLogger(){
+
+ }
+
+ public static void setLogLevel(RPCLogLevel l) {
+ level = l;
+ }
+
+ public static void setLogLevel(String logStr) {
+ level = RPCLogMap.get(logStr);
+ }
+
+ public static void addMessage(RPCLogLevel l, String message) {
+ if(l.level >= level.level) {
+ //Cytoscape.getDesktop().setStatusBarMsg(message);
+ }
+ }
+
+ public static boolean setRPCLogLevel(String l) throws XmlRpcException {
+ if(RPCLogMap.containsKey(l)) {
+ level = RPCLogMap.get(l);
+ }
+ else {
+ throw new XmlRpcException("Log level does not exist.");
+ }
+ return true;
+ }
+
+ public static RPCLogLevel getRPCLogLevel() {
+ return level;
+ }
+
+ private static RPCLogLevel level = RPCLogLevel.ERROR;
+}
+
--
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.