[jbpm-commits] JBoss JBPM SVN: r6247 - in jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph: node and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Apr 7 04:31:24 EDT 2010


Author: alex.guizar at jboss.com
Date: 2010-04-07 04:31:23 -0400 (Wed, 07 Apr 2010)
New Revision: 6247

Modified:
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/Node.java
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/SuperState.java
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/EndState.java
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/ProcessState.java
   jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/StartState.java
Log:
deprecate remaining public event type arrays

Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/Node.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/Node.java	2010-04-07 02:48:29 UTC (rev 6246)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/Node.java	2010-04-07 08:31:23 UTC (rev 6247)
@@ -109,9 +109,12 @@
 
   // event types //////////////////////////////////////////////////////////////
 
-  private static final String[] EVENT_TYPES =
-    { Event.EVENTTYPE_NODE_ENTER, Event.EVENTTYPE_NODE_LEAVE, Event.EVENTTYPE_BEFORE_SIGNAL,
-      Event.EVENTTYPE_AFTER_SIGNAL };
+  private static final String[] EVENT_TYPES = {
+    Event.EVENTTYPE_NODE_ENTER,
+    Event.EVENTTYPE_NODE_LEAVE,
+    Event.EVENTTYPE_BEFORE_SIGNAL,
+    Event.EVENTTYPE_AFTER_SIGNAL
+  };
 
   /**
    * @deprecated arrays are mutable and thus vulnerable to external

Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/SuperState.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/SuperState.java	2010-04-07 02:48:29 UTC (rev 6246)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/def/SuperState.java	2010-04-07 08:31:23 UTC (rev 6247)
@@ -39,7 +39,7 @@
 public class SuperState extends Node implements NodeCollection {
 
   private static final long serialVersionUID = 1L;
-  
+
   protected List nodes = null;
   transient Map nodesMap = null;
 
@@ -52,7 +52,7 @@
 
   // event types //////////////////////////////////////////////////////////////
 
-  public static final String[] supportedEventTypes = new String[]{
+  private static final String[] EVENT_TYPES = {
     Event.EVENTTYPE_NODE_ENTER,
     Event.EVENTTYPE_NODE_LEAVE,
     Event.EVENTTYPE_TASK_CREATE,
@@ -68,8 +68,15 @@
     Event.EVENTTYPE_SUBPROCESS_END,
     Event.EVENTTYPE_TIMER
   };
+
+  /**
+   * @deprecated arrays are mutable and thus vulnerable to external
+   * manipulation. use {@link #getSupportedEventTypes()} instead
+   */
+  public static final String[] supportedEventTypes = (String[]) EVENT_TYPES.clone();
+
   public String[] getSupportedEventTypes() {
-    return supportedEventTypes;
+    return (String[]) EVENT_TYPES.clone();
   }
 
   // xml //////////////////////////////////////////////////////////////////////
@@ -81,9 +88,9 @@
   // behaviour ////////////////////////////////////////////////////////////////
 
   public void execute(ExecutionContext executionContext) {
-    if ( (nodes==null)
-         || (nodes.size()==0) ) {
-      throw new JbpmException("transition enters superstate +"+this+"' and it there is no first child-node to delegate to");
+    if ((nodes == null) || (nodes.size() == 0)) {
+      throw new JbpmException("transition enters superstate +" + this
+        + "' and it there is no first child-node to delegate to");
     }
     Node startNode = (Node) nodes.get(0);
     startNode.enter(executionContext);
@@ -98,13 +105,12 @@
 
   // javadoc description in NodeCollection
   public Map getNodesMap() {
-    if ( (nodesMap==null)
-         && (nodes!=null) ) {
+    if ((nodesMap == null) && (nodes != null)) {
       nodesMap = new HashMap();
       Iterator iter = nodes.iterator();
       while (iter.hasNext()) {
         Node node = (Node) iter.next();
-        nodesMap.put(node.getName(),node);
+        nodesMap.put(node.getName(), node);
       }
     }
     return nodesMap;
@@ -115,7 +121,6 @@
     return (Node) getNodesMap().get(name);
   }
 
-  
   // javadoc description in NodeCollection
   public boolean hasNode(String name) {
     return getNodesMap().containsKey(name);
@@ -123,7 +128,8 @@
 
   // javadoc description in NodeCollection
   public Node addNode(Node node) {
-    if (node == null) throw new IllegalArgumentException("can't add a null node to a superstate");
+    if (node == null)
+      throw new IllegalArgumentException("can't add a null node to a superstate");
     if (nodes == null) nodes = new ArrayList();
     nodes.add(node);
     node.superState = this;
@@ -134,7 +140,8 @@
   // javadoc description in NodeCollection
   public Node removeNode(Node node) {
     Node removedNode = null;
-    if (node == null) throw new IllegalArgumentException("can't remove a null node from a superstate");
+    if (node == null)
+      throw new IllegalArgumentException("can't remove a null node from a superstate");
     if (nodes != null) {
       if (nodes.remove(node)) {
         removedNode = node;
@@ -147,14 +154,15 @@
 
   // javadoc description in NodeCollection
   public void reorderNode(int oldIndex, int newIndex) {
-    if ( (nodes!=null)
-         && (Math.min(oldIndex, newIndex)>=0)
-         && (Math.max(oldIndex, newIndex)<nodes.size()) ) {
+    if ((nodes != null) && (Math.min(oldIndex, newIndex) >= 0)
+      && (Math.max(oldIndex, newIndex) < nodes.size())) {
       Object o = nodes.remove(oldIndex);
       nodes.add(newIndex, o);
-    } else {
-      throw new IndexOutOfBoundsException("couldn't reorder element from index '"+oldIndex+"' to index '"+newIndex+"' in nodeList '"+nodes+"'");
     }
+    else {
+      throw new IndexOutOfBoundsException("couldn't reorder element from index '" + oldIndex
+        + "' to index '" + newIndex + "' in nodeList '" + nodes + "'");
+    }
   }
 
   // javadoc description in NodeCollection
@@ -168,16 +176,17 @@
   }
 
   /**
-   * recursively checks if the given node is one of the descendants of this supernode.
+   * recursively checks if the given node is one of the descendants of this
+   * supernode.
    */
   public boolean containsNode(Node node) {
     boolean containsNode = false;
     SuperState parent = node.getSuperState();
-    while( (!containsNode)
-           && (parent!=null) ) {
+    while ((!containsNode) && (parent != null)) {
       if (this.equals(parent)) {
         containsNode = true;
-      } else {
+      }
+      else {
         parent = parent.getSuperState();
       }
     }
@@ -188,12 +197,12 @@
 
   public GraphElement getParent() {
     GraphElement parent = processDefinition;
-    if (superState!=null) {
+    if (superState != null) {
       parent = superState;
     }
     return parent;
   }
-  
+
   public boolean isSuperStateNode() {
     return true;
   }

Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/EndState.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/EndState.java	2010-04-07 02:48:29 UTC (rev 6246)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/EndState.java	2010-04-07 08:31:23 UTC (rev 6247)
@@ -38,12 +38,6 @@
   public EndState() {
   }
 
-  public static final String[] supportedEventTypes = new String[] { Event.EVENTTYPE_NODE_ENTER };
-
-  public String[] getSupportedEventTypes() {
-    return supportedEventTypes;
-  }
-
   public EndState(String name) {
     super(name);
   }
@@ -52,6 +46,24 @@
     return NodeType.EndState;
   }
 
+  // event types //////////////////////////////////////////////////////////////
+
+  private static final String[] EVENT_TYPES = {
+    Event.EVENTTYPE_NODE_ENTER
+  };
+
+  /**
+   * @deprecated arrays are mutable and thus vulnerable to external
+   * manipulation. use {@link #getSupportedEventTypes()} instead
+   */
+  public static final String[] supportedEventTypes = (String[]) EVENT_TYPES.clone();
+
+  public String[] getSupportedEventTypes() {
+    return (String[]) EVENT_TYPES.clone();
+  }
+
+  // xml //////////////////////////////////////////////////////////////////////
+
   public void read(Element nodeElement, JpdlXmlReader jpdlXmlReader) {
     endCompleteProcess = nodeElement.attributeValue("end-complete-process");
   }
@@ -66,6 +78,6 @@
   }
 
   public Transition addLeavingTransition(Transition t) {
-    throw new UnsupportedOperationException("can't add a leaving transition to an end-state");
+    throw new UnsupportedOperationException("cannot add leaving transition to end state");
   }
 }

Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/ProcessState.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/ProcessState.java	2010-04-07 02:48:29 UTC (rev 6246)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/ProcessState.java	2010-04-07 08:31:23 UTC (rev 6247)
@@ -32,8 +32,9 @@
 import org.dom4j.Element;
 import org.dom4j.tree.DefaultElement;
 import org.dom4j.tree.FlyweightAttribute;
-import org.jbpm.JbpmConfiguration;
+
 import org.jbpm.JbpmException;
+import org.jbpm.JbpmConfiguration.Configs;
 import org.jbpm.context.def.VariableAccess;
 import org.jbpm.context.exe.ContextInstance;
 import org.jbpm.graph.def.Event;
@@ -51,48 +52,66 @@
 public class ProcessState extends Node {
 
   private static final long serialVersionUID = 1L;
-  
+
   static SubProcessResolver defaultSubProcessResolver = new DbSubProcessResolver();
 
   public static void setDefaultSubProcessResolver(SubProcessResolver subProcessResolver) {
     defaultSubProcessResolver = subProcessResolver;
   }
 
-  protected ProcessDefinition subProcessDefinition = null;
-  protected Set variableAccesses = null;
-  protected String subProcessName = null;
+  protected ProcessDefinition subProcessDefinition;
+  protected Set variableAccesses;
+  protected String subProcessName;
 
+  public ProcessState() {
+  }
+
+  public ProcessState(String name) {
+    super(name);
+  }
+
   // event types //////////////////////////////////////////////////////////////
 
-  public static final String[] supportedEventTypes = new String[] { Event.EVENTTYPE_SUBPROCESS_CREATED, Event.EVENTTYPE_SUBPROCESS_END,
-      Event.EVENTTYPE_NODE_ENTER, Event.EVENTTYPE_NODE_LEAVE, Event.EVENTTYPE_BEFORE_SIGNAL, Event.EVENTTYPE_AFTER_SIGNAL };
+  private static final String[] EVENT_TYPES = {
+    Event.EVENTTYPE_SUBPROCESS_CREATED,
+    Event.EVENTTYPE_SUBPROCESS_END,
+    Event.EVENTTYPE_NODE_ENTER,
+    Event.EVENTTYPE_NODE_LEAVE,
+    Event.EVENTTYPE_BEFORE_SIGNAL,
+    Event.EVENTTYPE_AFTER_SIGNAL
+  };
 
+  /**
+   * @deprecated arrays are mutable and thus vulnerable to external
+   * manipulation. use {@link #getSupportedEventTypes()} instead
+   */
+  public static final String[] supportedEventTypes = (String[]) EVENT_TYPES.clone();
+
   public String[] getSupportedEventTypes() {
-    return supportedEventTypes;
+    return (String[]) EVENT_TYPES.clone();
   }
 
   // xml //////////////////////////////////////////////////////////////////////
 
   public void read(Element processStateElement, JpdlXmlReader jpdlReader) {
     Element subProcessElement = processStateElement.element("sub-process");
-    
-    if (subProcessElement!=null) {
-      
+
+    if (subProcessElement != null) {
       String binding = subProcessElement.attributeValue("binding");
       if ("late".equalsIgnoreCase(binding)) {
         subProcessName = subProcessElement.attributeValue("name");
-      } else {
-        
+      }
+      else {
         SubProcessResolver subProcessResolver = getSubProcessResolver();
-
         try {
           subProcessDefinition = subProcessResolver.findSubProcess(subProcessElement);
-        } catch (JbpmException e) {
+        }
+        catch (JbpmException e) {
           jpdlReader.addWarning(e.getMessage());
         }
 
         // in case this is a self-recursive process invocation...
-        if (subProcessDefinition==null) {
+        if (subProcessDefinition == null) {
           String subProcessName = subProcessElement.attributeValue("name");
           if (subProcessName.equals(processDefinition.getName())) {
             subProcessDefinition = processDefinition;
@@ -100,39 +119,40 @@
         }
       }
     }
-    
-    if (subProcessDefinition!=null) {
-      log.debug("subprocess for process-state '"+name+"' bound to "+subProcessDefinition);
-    } else if (subProcessName!=null ){
-      log.debug("subprocess for process-state '"+name+"' will be late bound to "+subProcessName);
-    } else {
-      log.debug("subprocess for process-state '"+name+"' not yet bound");
+
+    if (subProcessDefinition != null) {
+      log.debug("subprocess for process-state '" + name + "' bound to " + subProcessDefinition);
     }
+    else if (subProcessName != null) {
+      log.debug("subprocess for process-state '" + name + "' will be late bound to "
+        + subProcessName);
+    }
+    else {
+      log.debug("subprocess for process-state '" + name + "' not yet bound");
+    }
 
-    this.variableAccesses = new HashSet(jpdlReader.readVariableAccesses(processStateElement));
+    variableAccesses = new HashSet(jpdlReader.readVariableAccesses(processStateElement));
   }
 
   private SubProcessResolver getSubProcessResolver() {
     SubProcessResolver subProcessResolver = defaultSubProcessResolver;
-    if (JbpmConfiguration.Configs.hasObject("jbpm.sub.process.resolver")) {
-      subProcessResolver = (SubProcessResolver) JbpmConfiguration.Configs.getObject("jbpm.sub.process.resolver");
+    if (Configs.hasObject("jbpm.sub.process.resolver")) {
+      subProcessResolver = (SubProcessResolver) Configs.getObject("jbpm.sub.process.resolver");
     }
     return subProcessResolver;
   }
-  
+
   public void execute(ExecutionContext executionContext) {
     Token superProcessToken = executionContext.getToken();
-    
+
     ProcessDefinition usedSubProcessDefinition = subProcessDefinition;
     // if this process has late binding
-    if ( (subProcessDefinition==null)
-         && (subProcessName!=null)
-       ) {
+    if (subProcessDefinition == null && subProcessName != null) {
       SubProcessResolver subProcessResolver = getSubProcessResolver();
       List attributes = new ArrayList();
       String subProcessNameResolved = (String) JbpmExpressionEvaluator.evaluate(subProcessName, executionContext);
       if (log.isDebugEnabled()) {
-          log.debug("SubProcessName after eval: " + subProcessNameResolved);
+        log.debug("SubProcessName after eval: " + subProcessNameResolved);
       }
       attributes.add(new FlyweightAttribute("name", subProcessNameResolved));
       Element subProcessElement = new DefaultElement("sub-process");
@@ -148,15 +168,13 @@
     fireEvent(Event.EVENTTYPE_SUBPROCESS_CREATED, executionContext);
 
     // feed the readable variableInstances
-    if ((variableAccesses != null) && (!variableAccesses.isEmpty())) {
-
+    if (variableAccesses != null && !variableAccesses.isEmpty()) {
       ContextInstance superContextInstance = executionContext.getContextInstance();
       ContextInstance subContextInstance = subProcessInstance.getContextInstance();
       subContextInstance.setTransientVariables(superContextInstance.getTransientVariables());
 
       // loop over all the variable accesses
-      Iterator iter = variableAccesses.iterator();
-      while (iter.hasNext()) {
+      for (Iterator iter = variableAccesses.iterator(); iter.hasNext();) {
         VariableAccess variableAccess = (VariableAccess) iter.next();
         // if this variable access is readable
         if (variableAccess.isReadable()) {
@@ -165,8 +183,9 @@
           String variableName = variableAccess.getVariableName();
           Object value = superContextInstance.getVariable(variableName, superProcessToken);
           String mappedName = variableAccess.getMappedName();
-          log.debug("copying super process var '"+variableName+"' to sub process var '"+mappedName+"': "+value);
-          if (value!=null) {
+          log.debug("copying super process var '" + variableName + "' to sub process var '"
+            + mappedName + "': " + value);
+          if (value != null) {
             subContextInstance.setVariable(mappedName, value);
           }
         }
@@ -176,8 +195,6 @@
     // send the signal to start the subprocess
     subProcessInstance.signal();
   }
-  
-  
 
   public void leave(ExecutionContext executionContext, Transition transition) {
     ProcessInstance subProcessInstance = executionContext.getSubProcessInstance();
@@ -185,14 +202,12 @@
     Token superProcessToken = subProcessInstance.getSuperProcessToken();
 
     // feed the readable variableInstances
-    if ((variableAccesses != null) && (!variableAccesses.isEmpty())) {
-
+    if (variableAccesses != null && !variableAccesses.isEmpty()) {
       ContextInstance superContextInstance = executionContext.getContextInstance();
       ContextInstance subContextInstance = subProcessInstance.getContextInstance();
 
       // loop over all the variable accesses
-      Iterator iter = variableAccesses.iterator();
-      while (iter.hasNext()) {
+      for (Iterator iter = variableAccesses.iterator(); iter.hasNext();) {
         VariableAccess variableAccess = (VariableAccess) iter.next();
         // if this variable access is writable
         if (variableAccess.isWritable()) {
@@ -201,8 +216,9 @@
           String mappedName = variableAccess.getMappedName();
           Object value = subContextInstance.getVariable(mappedName);
           String variableName = variableAccess.getVariableName();
-          log.debug("copying sub process var '"+mappedName+"' to super process var '"+variableName+"': "+value);
-          if (value!=null) {
+          log.debug("copying sub process var '" + mappedName + "' to super process var '"
+            + variableName + "': " + value);
+          if (value != null) {
             superContextInstance.setVariable(variableName, value, superProcessToken);
           }
         }
@@ -214,26 +230,30 @@
 
     // remove the subprocess reference
     superProcessToken.setSubProcessInstance(null);
-    
-    // We replaced the normal log generation of super.leave() by creating the log here
-    // and overriding the addNodeLog method with an empty version 
-    superProcessToken.addLog(new ProcessStateLog(this, superProcessToken.getNodeEnter(), Clock.getCurrentTime(), subProcessInstance));
 
+    // We replaced the normal log generation of super.leave()
+    // by creating the log here
+    // and overriding the addNodeLog method with an empty version
+    superProcessToken.addLog(new ProcessStateLog(this, superProcessToken.getNodeEnter(),
+      Clock.getCurrentTime(), subProcessInstance));
+
     // call the subProcessEndAction
     super.leave(executionContext, getDefaultLeavingTransition());
   }
 
-  // We replaced the normal log generation of super.leave() by creating the log above in the leave method 
-  // and overriding the addNodeLog method with an empty version 
+  // We replaced the normal log generation of super.leave()
+  // by creating the log above in the leave method
+  // and overriding the addNodeLog method with an empty version
   protected void addNodeLog(Token token) {
   }
 
   public ProcessDefinition getSubProcessDefinition() {
     return subProcessDefinition;
   }
+
   public void setSubProcessDefinition(ProcessDefinition subProcessDefinition) {
     this.subProcessDefinition = subProcessDefinition;
   }
-  
-  private static Log log = LogFactory.getLog(ProcessState.class);
+
+  private static final Log log = LogFactory.getLog(ProcessState.class);
 }

Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/StartState.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/StartState.java	2010-04-07 02:48:29 UTC (rev 6246)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/graph/node/StartState.java	2010-04-07 08:31:23 UTC (rev 6247)
@@ -84,8 +84,7 @@
   }
 
   public Transition addArrivingTransition(Transition t) {
-    throw new UnsupportedOperationException(
-      "illegal operation : its not possible to add a transition that is arriving in a start state");
+    throw new UnsupportedOperationException("cannot add arriving transition to start state");
   }
 
   /**
@@ -93,6 +92,6 @@
    * @throws UnsupportedOperationException to prevent invocation
    */
   public void setArrivingTransitions(Map arrivingTransitions) {
-    throw new UnsupportedOperationException("cannot set arriving transitions for start state");
+    throw new UnsupportedOperationException("cannot set arriving transitions of start state");
   }
 }



More information about the jbpm-commits mailing list