Author: mes
Date: 2011-03-11 11:50:25 -0800 (Fri, 11 Mar 2011)
New Revision: 24410

Added:
   core3/command-executor-impl/trunk/
   core3/command-executor-impl/trunk/osgi.bnd
   core3/command-executor-impl/trunk/pom.xml
   core3/command-executor-impl/trunk/src/
   core3/command-executor-impl/trunk/src/main/
   core3/command-executor-impl/trunk/src/main/java/
   core3/command-executor-impl/trunk/src/main/java/org/
   core3/command-executor-impl/trunk/src/main/java/org/cytoscape/
   core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/
   
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/
   
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/CommandExecutorImpl.java
   
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/CommandExecutorTask.java
   
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/CommandExecutorTaskFactory.java
   
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/Executor.java
   
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/NTFExecutor.java
   
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/TFExecutor.java
   core3/command-executor-impl/trunk/src/main/resources/
   core3/command-executor-impl/trunk/src/main/resources/META-INF/
   core3/command-executor-impl/trunk/src/main/resources/META-INF/spring/
   
core3/command-executor-impl/trunk/src/main/resources/META-INF/spring/bundle-context-osgi.xml
   
core3/command-executor-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml
Log:
initial creation

Added: core3/command-executor-impl/trunk/osgi.bnd
===================================================================
--- core3/command-executor-impl/trunk/osgi.bnd                          (rev 0)
+++ core3/command-executor-impl/trunk/osgi.bnd  2011-03-11 19:50:25 UTC (rev 
24410)
@@ -0,0 +1,5 @@
+#-----------------------------------------------------------------
+# Use this file to add customized Bnd instructions for the bundle
+#-----------------------------------------------------------------
+
+Private-Package: ${bundle.namespace}.*

Added: core3/command-executor-impl/trunk/pom.xml
===================================================================
--- core3/command-executor-impl/trunk/pom.xml                           (rev 0)
+++ core3/command-executor-impl/trunk/pom.xml   2011-03-11 19:50:25 UTC (rev 
24410)
@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+       <parent>
+               <groupId>org.cytoscape</groupId>
+               <artifactId>parent</artifactId>
+               <version>3.0.0-alpha6-SNAPSHOT</version>
+       </parent>
+
+       <properties>
+               
<bundle.symbolicName>org.cytoscape.command-executor-impl</bundle.symbolicName>
+               
<bundle.namespace>org.cytoscape.command.internal</bundle.namespace>
+       </properties>
+
+       <modelVersion>4.0.0</modelVersion>
+       <groupId>org.cytoscape</groupId>
+       <artifactId>command-executor-impl</artifactId>
+       <version>3.0.0-alpha2-SNAPSHOT</version>
+
+       <name>Command Executor</name>
+
+       <packaging>bundle</packaging>
+
+    <scm>
+        
<connection>scm:svn:http://chianti.ucsd.edu/svn/core3/command-executor-impl/trunk</connection>
+        
<developerConnection>scm:svn:svn+ssh://grenache.ucsd.edu/cellar/common/svn/core3/command-executor-impl/trunk</developerConnection>
+        
<url>http://chianti.ucsd.edu/svn/core3/command-executor-impl/trunk</url>
+    </scm>
+
+    <repositories>
+        <!-- bootstrap for cytoscape dependencies, namely the parent POM 
snapshots -->
+        <repository>
+            <id>cytoscape_snapshots</id>
+            <snapshots>
+                <enabled>true</enabled>
+            </snapshots>
+            <releases>
+                <enabled>false</enabled>
+            </releases>
+            <name>Cytoscape Snapshots</name>
+            
<url>http://cytoscape.wodaklab.org/nexus/content/repositories/snapshots/</url>
+        </repository>
+        <!-- bootstrap for cytoscape dependencies, namely the parent POM 
releases -->
+        <repository>
+            <id>cytoscape_releases</id>
+            <snapshots>
+                <enabled>false</enabled>
+            </snapshots>
+            <releases>
+                <enabled>true</enabled>
+            </releases>
+            <name>Cytoscape Releases</name>
+            
<url>http://cytoscape.wodaklab.org/nexus/content/repositories/releases/</url>
+        </repository>
+    </repositories>
+
+       <build>
+               <plugins>
+                       <plugin>
+                               <groupId>org.ops4j</groupId>
+                               <artifactId>maven-pax-plugin</artifactId>
+                               <version>${maven-pax-plugin.version}</version>
+                               <extensions>true</extensions>
+                       </plugin>
+                       <plugin>
+                               <groupId>org.apache.felix</groupId>
+                               <artifactId>maven-bundle-plugin</artifactId>
+                               
<version>${maven-bundle-plugin.version}</version>
+                               <configuration>
+                                       <instructions>
+                                               
<Bundle-SymbolicName>${bundle.symbolicName}</Bundle-SymbolicName>
+                                               
<Bundle-Version>${project.version}</Bundle-Version>
+                                               <_include>-osgi.bnd</_include>
+                                       </instructions>
+                               </configuration>
+                       </plugin>
+
+               </plugins>
+       </build>
+
+       <dependencies>
+               <dependency>
+                       <groupId>org.cytoscape</groupId>
+                       <artifactId>core-task-api</artifactId>
+                       <version>3.0.0-alpha2</version>
+               </dependency>
+       </dependencies>
+
+</project>

Added: 
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/CommandExecutorImpl.java
===================================================================
--- 
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/CommandExecutorImpl.java
                             (rev 0)
+++ 
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/CommandExecutorImpl.java
     2011-03-11 19:50:25 UTC (rev 24410)
@@ -0,0 +1,70 @@
+package org.cytoscape.command.internal;
+
+
+import java.util.Properties;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.cytoscape.work.TaskFactory;
+import org.cytoscape.task.NetworkTaskFactory;
+
+public class CommandExecutorImpl {
+
+       private final Map<String,Executor> commandExecutorMap = new 
HashMap<String,Executor>();
+       private final static Logger logger = 
LoggerFactory.getLogger(CommandExecutorImpl.class);
+
+       public void addTaskFactory(TaskFactory tf, Map props) {
+               String commandName = (String)props.get("commandName");
+               if ( commandName != null ) 
+                       commandExecutorMap.put(commandName, new TFExecutor(tf));
+       }
+
+       public void removeTaskFactory(TaskFactory tf, Map props) {
+               String commandName = (String)props.get("commandName");
+               if ( commandName != null ) 
+                       commandExecutorMap.remove(commandName);
+       }
+
+       public void addNetworkTaskFactory(NetworkTaskFactory tf, Map props) {
+               String commandName = (String)props.get("commandName");
+               if ( commandName != null ) 
+                       commandExecutorMap.put(commandName, new 
NTFExecutor(tf));
+       }
+
+       public void removeNetworkTaskFactory(NetworkTaskFactory tf, Map props) {
+               String commandName = (String)props.get("commandName");
+               if ( commandName != null ) 
+                       commandExecutorMap.remove(commandName);
+       }
+
+       public void executeList(List<String> commandLines) {
+               try {
+                       for ( String line : commandLines ) { 
+                               System.out.println("begin parsing line: '" + 
line + "'");
+                               for ( String command : 
commandExecutorMap.keySet() ) {
+                                       System.out.println("testing command: '" 
+ command + "'");
+                                       if ( line.length() < command.length() ) 
+                                               continue;
+                                       final String comm = 
line.substring(0,command.length()); 
+                                       final String args = 
line.substring(command.length(),line.length()); 
+                                       System.out.println("comm: '" + comm + 
"'");
+                                       System.out.println("args: '" + args + 
"'");
+                                       if ( comm.equals(command) ) {
+                                               System.out.println(" -- 
executing");
+                                               Executor e = 
commandExecutorMap.get(command);
+                                               e.execute(args);
+                                               break;
+                                       } else {
+                                               System.out.println(" -- trying 
next");
+                                       }
+                               }
+                       }
+               } catch (Exception e) {
+                       logger.error("Command parsing error: ", e);
+               }
+       }
+}

Added: 
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/CommandExecutorTask.java
===================================================================
--- 
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/CommandExecutorTask.java
                             (rev 0)
+++ 
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/CommandExecutorTask.java
     2011-03-11 19:50:25 UTC (rev 24410)
@@ -0,0 +1,90 @@
+
+/*
+  Copyright (c) 2006, 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.command.internal;
+
+import org.cytoscape.work.AbstractTask;
+import org.cytoscape.work.TaskMonitor;
+import org.cytoscape.work.Tunable;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+
+
+import java.util.List;
+import java.util.ArrayList;
+
+
+public class CommandExecutorTask extends AbstractTask {
+
+       @Tunable(description="Select the command file:", params="input=true")
+       public File file;
+
+       private final CommandExecutorImpl cei;
+
+       public CommandExecutorTask(CommandExecutorImpl cei) {
+               super();
+               this.cei = cei;
+       }
+
+       public void run(TaskMonitor e) throws Exception {
+        if (file == null)
+            throw new NullPointerException("You must specify a non-null 
command file to load!");
+
+               FileReader fin = null; 
+               BufferedReader bin = null; 
+
+               try {
+
+               fin = new FileReader(file);
+               bin = new BufferedReader(fin);
+               List<String> lines = new ArrayList<String>();
+               String s;
+
+               while ((s = bin.readLine()) != null) 
+                       lines.add( s.trim() );
+
+               cei.executeList(lines);
+
+               } finally {
+                       if ( bin != null )
+                               bin.close();
+                       if ( fin != null )
+                               fin.close();
+               }
+       }
+}

Added: 
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/CommandExecutorTaskFactory.java
===================================================================
--- 
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/CommandExecutorTaskFactory.java
                              (rev 0)
+++ 
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/CommandExecutorTaskFactory.java
      2011-03-11 19:50:25 UTC (rev 24410)
@@ -0,0 +1,47 @@
+
+/*
+  Copyright (c) 2006, 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 org.cytoscape.command.internal;
+
+
+import org.cytoscape.work.TaskFactory;
+import org.cytoscape.work.TaskIterator;
+
+
+public class CommandExecutorTaskFactory implements TaskFactory {
+
+       private final CommandExecutorImpl cei;
+
+       public CommandExecutorTaskFactory(CommandExecutorImpl cei) {
+               this.cei = cei;
+       }
+
+       public TaskIterator getTaskIterator() {
+               return new TaskIterator(new CommandExecutorTask(cei));
+       } 
+}

Added: 
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/Executor.java
===================================================================
--- 
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/Executor.java
                                (rev 0)
+++ 
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/Executor.java
        2011-03-11 19:50:25 UTC (rev 24410)
@@ -0,0 +1,8 @@
+
+package org.cytoscape.command.internal;
+
+
+
+interface Executor {
+       void execute(String args);
+}

Added: 
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/NTFExecutor.java
===================================================================
--- 
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/NTFExecutor.java
                             (rev 0)
+++ 
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/NTFExecutor.java
     2011-03-11 19:50:25 UTC (rev 24410)
@@ -0,0 +1,19 @@
+
+
+package org.cytoscape.command.internal;
+
+import org.cytoscape.task.NetworkTaskFactory;
+
+class NTFExecutor extends TFExecutor {
+       private final NetworkTaskFactory ntf;
+
+       public NTFExecutor(NetworkTaskFactory ntf) {
+               super(ntf);
+               this.ntf = ntf;
+       }
+
+       public void execute(String args) {
+               System.out.println("set current network!");
+               super.execute(args);
+       }
+}

Added: 
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/TFExecutor.java
===================================================================
--- 
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/TFExecutor.java
                              (rev 0)
+++ 
core3/command-executor-impl/trunk/src/main/java/org/cytoscape/command/internal/TFExecutor.java
      2011-03-11 19:50:25 UTC (rev 24410)
@@ -0,0 +1,16 @@
+
+package org.cytoscape.command.internal;
+
+import org.cytoscape.work.TaskFactory;
+
+class TFExecutor implements Executor {
+       private final TaskFactory tf;
+
+       public TFExecutor(TaskFactory tf) {
+               this.tf = tf;
+       }
+
+       public void execute(String args) {
+               System.out.println("executing: " + tf + "   with args: '" + 
args + "'");
+       }
+}

Added: 
core3/command-executor-impl/trunk/src/main/resources/META-INF/spring/bundle-context-osgi.xml
===================================================================
--- 
core3/command-executor-impl/trunk/src/main/resources/META-INF/spring/bundle-context-osgi.xml
                                (rev 0)
+++ 
core3/command-executor-impl/trunk/src/main/resources/META-INF/spring/bundle-context-osgi.xml
        2011-03-11 19:50:25 UTC (rev 24410)
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans";
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xmlns:osgi="http://www.springframework.org/schema/osgi";
+       xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+                      http://www.springframework.org/schema/osgi 
http://www.springframework.org/schema/osgi/spring-osgi-1.0.xsd";
+       default-lazy-init="false">
+
+
+       <osgi:service id="commandExecutorTaskFactoryService" 
ref="commandExecutorTaskFactory"
+               interface="org.cytoscape.work.TaskFactory">
+        <osgi:service-properties>
+            <entry key="title" value="Load Command File" />
+            <entry key="preferredMenu" value="Plugins" />
+        </osgi:service-properties>
+       </osgi:service>
+
+    <osgi:set id="taskFactorySet" 
+              interface="org.cytoscape.work.TaskFactory"
+              cardinality="0..N" >
+        <osgi:listener bind-method="addTaskFactory"
+                       unbind-method="removeTaskFactory" 
+                       ref="commandExecutorImpl" />
+    </osgi:set>
+
+    <osgi:set id="networkTaskFactorySet" 
+              interface="org.cytoscape.task.NetworkTaskFactory"
+              cardinality="0..N" >
+        <osgi:listener bind-method="addNetworkTaskFactory"
+                       unbind-method="removeNetworkTaskFactory" 
+                       ref="commandExecutorImpl" />
+    </osgi:set>
+
+</beans>

Added: 
core3/command-executor-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml
===================================================================
--- 
core3/command-executor-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml
                             (rev 0)
+++ 
core3/command-executor-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml
     2011-03-11 19:50:25 UTC (rev 24410)
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans";
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xmlns:context="http://www.springframework.org/schema/context";
+       xmlns:util="http://www.springframework.org/schema/util";
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans
+            http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+        http://www.springframework.org/schema/aop
+            http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
+        http://www.springframework.org/schema/context
+            
http://www.springframework.org/schema/context/spring-context-2.5.xsd
+        http://www.springframework.org/schema/util
+            http://www.springframework.org/schema/util/spring-util-2.5.xsd
+        http://www.springframework.org/schema/lang
+            http://www.springframework.org/schema/lang/spring-lang-2.5.xsd
+        http://www.springframework.org/schema/osgi
+            http://www.springframework.org/schema/osgi/spring-osgi-1.0.xsd";
+       default-lazy-init="false">
+
+       <!--
+               regular spring configuration file defining the beans for this 
bundle.
+               We've kept the osgi definitions in a separate configuration 
file so
+               that this file can easily be used for integration testing 
outside of
+               an OSGi environment
+       -->
+
+       <context:annotation-config />
+
+       <bean id="commandExecutorImpl" 
class="org.cytoscape.command.internal.CommandExecutorImpl">
+       </bean>
+
+       <bean id="commandExecutorTaskFactory" 
+             class="org.cytoscape.command.internal.CommandExecutorTaskFactory">
+               <constructor-arg ref="commandExecutorImpl" />
+       </bean>
+</beans>

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