]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/controllers/ProcessController.java
Remove SlcAgentFactory
[gpl/argeo-slc.git] / plugins / org.argeo.slc.client.ui / src / main / java / org / argeo / slc / client / ui / controllers / ProcessController.java
index 4cb7c9bda7130fa7966917a27542f6255e0b0bad..abf41dc5b54daec7868ee6e90778d53e43e2d335 100644 (file)
  */
 package org.argeo.slc.client.ui.controllers;
 
-import java.util.HashMap;
-import java.util.Map;
-
 import javax.jcr.Node;
-import javax.jcr.NodeIterator;
-import javax.jcr.Property;
 import javax.jcr.RepositoryException;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.argeo.slc.SlcException;
 import org.argeo.slc.execution.ExecutionProcess;
 import org.argeo.slc.execution.SlcAgent;
-import org.argeo.slc.execution.SlcAgentFactory;
-import org.argeo.slc.jcr.SlcJcrConstants;
-import org.argeo.slc.jcr.SlcJcrUtils;
-import org.argeo.slc.jcr.SlcNames;
 import org.argeo.slc.jcr.execution.JcrExecutionProcess;
 
 /**
@@ -39,8 +28,12 @@ import org.argeo.slc.jcr.execution.JcrExecutionProcess;
  * in an application context.
  */
 public class ProcessController {
-       private final static Log log = LogFactory.getLog(ProcessController.class);
-       private Map<String, SlcAgentFactory> agentFactories = new HashMap<String, SlcAgentFactory>();
+       // private final static Log log =
+       // LogFactory.getLog(ProcessController.class);
+       // private Map<String, SlcAgentFactory> agentFactories = new HashMap<String,
+       // SlcAgentFactory>();
+
+       private SlcAgent agent;
 
        public ExecutionProcess process(Node processNode) {
                JcrExecutionProcess process = new JcrExecutionProcess(processNode);
@@ -71,49 +64,55 @@ public class ProcessController {
                }
        }
 
+       /** Always return the default runtime agent */
        protected SlcAgent findAgent(Node processNode) throws RepositoryException {
                // we currently only deal with single agents
-               Node realizedFlowNode = processNode.getNode(SlcNames.SLC_FLOW);
-               NodeIterator nit = realizedFlowNode.getNodes();
-               if (nit.hasNext()) {
-                       // TODO find a better way to determine which agent to use
-                       // currently we check the agent of the first registered flow
-                       Node firstRealizedFlow = nit.nextNode();
-                       // we assume there is an nt:address
-                       String firstFlowPath = firstRealizedFlow
-                                       .getNode(SlcNames.SLC_ADDRESS)
-                                       .getProperty(Property.JCR_PATH).getString();
-                       Node flowNode = processNode.getSession().getNode(firstFlowPath);
-                       String agentFactoryPath = SlcJcrUtils
-                                       .flowAgentFactoryPath(firstFlowPath);
-                       if (!agentFactories.containsKey(agentFactoryPath))
-                               throw new SlcException("No agent factory registered under "
-                                               + agentFactoryPath);
-                       SlcAgentFactory agentFactory = agentFactories.get(agentFactoryPath);
-                       Node agentNode = ((Node) flowNode
-                                       .getAncestor(SlcJcrUtils.AGENT_FACTORY_DEPTH + 1));
-                       String agentUuid = agentNode.getProperty(SlcNames.SLC_UUID)
-                                       .getString();
+               // Node realizedFlowNode = processNode.getNode(SlcNames.SLC_FLOW);
+               // NodeIterator nit = realizedFlowNode.getNodes();
+               // if (nit.hasNext()) {
+               // // TODO find a better way to determine which agent to use
+               // // currently we check the agent of the first registered flow
+               // Node firstRealizedFlow = nit.nextNode();
+               // // we assume there is an nt:address
+               // String firstFlowPath = firstRealizedFlow
+               // .getNode(SlcNames.SLC_ADDRESS)
+               // .getProperty(Property.JCR_PATH).getString();
+               // Node flowNode = processNode.getSession().getNode(firstFlowPath);
+               // String agentFactoryPath = SlcJcrUtils
+               // .flowAgentFactoryPath(firstFlowPath);
+               // if (!agentFactories.containsKey(agentFactoryPath))
+               // throw new SlcException("No agent factory registered under "
+               // + agentFactoryPath);
+               // SlcAgentFactory agentFactory = agentFactories.get(agentFactoryPath);
+               // Node agentNode = ((Node) flowNode
+               // .getAncestor(SlcJcrUtils.AGENT_FACTORY_DEPTH + 1));
+               // String agentUuid = agentNode.getProperty(SlcNames.SLC_UUID)
+               // .getString();
+               //
+               // // process
+               // return agentFactory.getAgent(agentUuid);
+               // }
 
-                       // process
-                       return agentFactory.getAgent(agentUuid);
-               }
-               return null;
+               return agent;
        }
 
-       public synchronized void register(SlcAgentFactory agentFactory,
-                       Map<String, String> properties) {
-               String path = properties.get(SlcJcrConstants.PROPERTY_PATH);
-               if (log.isDebugEnabled())
-                       log.debug("Agent factory registered under " + path);
-               agentFactories.put(path, agentFactory);
+       public void setAgent(SlcAgent agent) {
+               this.agent = agent;
        }
 
-       public synchronized void unregister(SlcAgentFactory agentFactory,
-                       Map<String, String> properties) {
-               String path = properties.get(SlcJcrConstants.PROPERTY_PATH);
-               if (log.isDebugEnabled())
-                       log.debug("Agent factory unregistered from " + path);
-               agentFactories.remove(path);
-       }
+       // public synchronized void register(SlcAgentFactory agentFactory,
+       // Map<String, String> properties) {
+       // String path = properties.get(SlcJcrConstants.PROPERTY_PATH);
+       // if (log.isDebugEnabled())
+       // log.debug("Agent factory registered under " + path);
+       // agentFactories.put(path, agentFactory);
+       // }
+       //
+       // public synchronized void unregister(SlcAgentFactory agentFactory,
+       // Map<String, String> properties) {
+       // String path = properties.get(SlcJcrConstants.PROPERTY_PATH);
+       // if (log.isDebugEnabled())
+       // log.debug("Agent factory unregistered from " + path);
+       // agentFactories.remove(path);
+       // }
 }