Package org.drools.process.instance.context.variable

Examples of org.drools.process.instance.context.variable.VariableScopeInstance


                "A SubProcess node only accepts default incoming connections!");
        }
        Map<String, Object> parameters = new HashMap<String, Object>();
        for (Map.Entry<String, String> mapping: getSubProcessNode().getInMappings().entrySet()) {
          Object parameterValue = null;
            VariableScopeInstance variableScopeInstance = (VariableScopeInstance)
                resolveContextInstance(VariableScope.VARIABLE_SCOPE, mapping.getValue());
            if (variableScopeInstance != null) {
                parameterValue = variableScopeInstance.getVariable(mapping.getValue());
            } else {
              try {
                parameterValue = MVEL.eval(mapping.getValue(), new NodeInstanceResolverFactory(this));
              } catch (Throwable t) {
                System.err.println("Could not find variable scope for variable " + mapping.getValue());
                    System.err.println("when trying to execute SubProcess node " + getSubProcessNode().getName());
                    System.err.println("Continuing without setting parameter.");
              }
            }
            if (parameterValue != null) {
              parameters.put(mapping.getKey(),parameterValue);
            }
        }
        String processId = getSubProcessNode().getProcessId();
        // resolve processId if necessary
        Map<String, String> replacements = new HashMap<String, String>();
    Matcher matcher = PARAMETER_MATCHER.matcher(processId);
        while (matcher.find()) {
          String paramName = matcher.group(1);
          if (replacements.get(paramName) == null) {
              VariableScopeInstance variableScopeInstance = (VariableScopeInstance)
                  resolveContextInstance(VariableScope.VARIABLE_SCOPE, paramName);
                if (variableScopeInstance != null) {
                    Object variableValue = variableScopeInstance.getVariable(paramName);
                  String variableValueString = variableValue == null ? "" : variableValue.toString();
                  replacements.put(paramName, variableValueString);
                } else {
                  try {
                    Object variableValue = MVEL.eval(paramName, new NodeInstanceResolverFactory(this));
View Full Code Here


        handleOutMappings(processInstance);
        triggerCompleted();
    }
   
    private void handleOutMappings(ProcessInstance processInstance) {
        VariableScopeInstance subProcessVariableScopeInstance = (VariableScopeInstance)
          processInstance.getContextInstance(VariableScope.VARIABLE_SCOPE);
      for (Map.Entry<String, String> mapping: getSubProcessNode().getOutMappings().entrySet()) {
          VariableScopeInstance variableScopeInstance = (VariableScopeInstance)
              resolveContextInstance(VariableScope.VARIABLE_SCOPE, mapping.getValue());
          if (variableScopeInstance != null) {
            Object value = subProcessVariableScopeInstance.getVariable(mapping.getKey());
            if (value == null) {
              try {
                  value = MVEL.eval(mapping.getKey(), new VariableScopeResolverFactory(subProcessVariableScopeInstance));
                } catch (Throwable t) {
                  // do nothing
                }
            }
              variableScopeInstance.setVariable(mapping.getValue(), value);
          } else {
              System.err.println("Could not find variable scope for variable " + mapping.getValue());
              System.err.println("when trying to complete SubProcess node " + getSubProcessNode().getName());
              System.err.println("Continuing without setting variable.");
          }
View Full Code Here

              List<NodeInstance> nodeInstances = new ArrayList<NodeInstance>();
              for (Object o: collection) {
                  String variableName = getForEachNode().getVariableName();
                  CompositeNodeInstance nodeInstance = (CompositeNodeInstance)
                      ((NodeInstanceContainer) getNodeInstanceContainer()).getNodeInstance(getForEachSplitNode().getTo().getTo());
                  VariableScopeInstance variableScopeInstance = (VariableScopeInstance)
                      nodeInstance.resolveContextInstance(VariableScope.VARIABLE_SCOPE, variableName);
                  variableScopeInstance.setVariable(variableName, o);
                  nodeInstances.add(nodeInstance);
              }
              for (NodeInstance nodeInstance: nodeInstances) {
                  ((org.drools.workflow.instance.NodeInstance) nodeInstance).trigger(this, getForEachSplitNode().getTo().getToType());
              }
View Full Code Here

        }
       
        private Collection<?> evaluateCollectionExpression(String collectionExpression) {
            // TODO: should evaluate this expression using MVEL
          Object collection = null;
            VariableScopeInstance variableScopeInstance = (VariableScopeInstance)
                resolveContextInstance(VariableScope.VARIABLE_SCOPE, collectionExpression);
            if (variableScopeInstance != null) {
              collection = variableScopeInstance.getVariable(collectionExpression);
            } else {
              try {
                collection = MVEL.eval(collectionExpression, new NodeInstanceResolverFactory(this));
              } catch (Throwable t) {
                throw new IllegalArgumentException(
View Full Code Here

    private static final long serialVersionUID = 400L;

    public void signalEvent(String type, Object event) {
      String variableName = getEventNode().getVariableName();
      if (variableName != null) {
        VariableScopeInstance variableScopeInstance = (VariableScopeInstance)
          resolveContextInstance(VariableScope.VARIABLE_SCOPE, variableName);
        if (variableScopeInstance == null) {
          throw new IllegalArgumentException(
          "Could not find variable for event node: " + variableName);
        }
        EventTransformer transformer = getEventNode().getEventTransformer();
        if (transformer != null) {
          event = transformer.transformEvent(event);
        }
        variableScopeInstance.setVariable(variableName, event);
      }
      triggerCompleted();
    }
View Full Code Here

        stream.writeLong( processInstance.getId() );
        stream.writeUTF( processInstance.getProcessId() );
        stream.writeInt( processInstance.getState() );
        stream.writeLong( processInstance.getNodeInstanceCounter() );

        VariableScopeInstance variableScopeInstance = (VariableScopeInstance) processInstance.getContextInstance( VariableScope.VARIABLE_SCOPE );
        Map<String, Object> variables = variableScopeInstance.getVariables();
        List<String> keys = new ArrayList<String>( variables.keySet() );
        Collections.sort( keys,
                          new Comparator<String>() {
                              public int compare(String o1,
                                                 String o2) {
View Full Code Here

                stream.writeInt( triggers.get( key ) );
            }
        } else if ( nodeInstance instanceof CompositeContextNodeInstance ) {
            stream.writeShort( PersisterEnums.COMPOSITE_NODE_INSTANCE );
            CompositeContextNodeInstance compositeNodeInstance = (CompositeContextNodeInstance) nodeInstance;
            VariableScopeInstance variableScopeInstance = (VariableScopeInstance) compositeNodeInstance.getContextInstance( VariableScope.VARIABLE_SCOPE );
            Map<String, Object> variables = variableScopeInstance.getVariables();
            List<String> keys = new ArrayList<String>( variables.keySet() );
            Collections.sort( keys,
                              new Comparator<String>() {
                                  public int compare(String o1,
                                                     String o2) {
View Full Code Here

    public void setNodeInstance(NodeInstance nodeInstance) {
        this.nodeInstance = nodeInstance;
    }
   
    public Object getVariable(String variableName) {
      VariableScopeInstance variableScope = null;
      if (nodeInstance != null) {
        variableScope = (VariableScopeInstance) ((org.drools.workflow.instance.NodeInstance)
        nodeInstance).resolveContextInstance(VariableScope.VARIABLE_SCOPE, variableName);
      }
      if (variableScope == null) {
        variableScope = (VariableScopeInstance) ((ProcessInstance)
          getProcessInstance()).getContextInstance(VariableScope.VARIABLE_SCOPE);
      }
      return variableScope.getVariable(variableName);
    }
View Full Code Here

      }
      return variableScope.getVariable(variableName);
    }
   
    public void setVariable(String variableName, Object value) {
      VariableScopeInstance variableScope = null;
      if (nodeInstance != null) {
        variableScope = (VariableScopeInstance) ((org.drools.workflow.instance.NodeInstance)
          nodeInstance).resolveContextInstance(VariableScope.VARIABLE_SCOPE, variableName);
      }
      if (variableScope == null) {
        variableScope = (VariableScopeInstance) getProcessInstance().getContextInstance(VariableScope.VARIABLE_SCOPE);
        if (variableScope.getVariableScope().findVariable(variableName) == null) {
          variableScope = null;
        }
      }
      if (variableScope == null) {
        System.err.println("Could not find variable " + variableName);
        System.err.println("Using process-level scope");
        variableScope = (VariableScopeInstance) ((ProcessInstance)
          getProcessInstance()).getContextInstance(VariableScope.VARIABLE_SCOPE);
      }
      variableScope.setVariable(variableName, value);
    }
View Full Code Here

        ((WorkItem) workItem).setName(work.getName());
        ((WorkItem) workItem).setProcessInstanceId(getProcessInstance().getId());
        ((WorkItem) workItem).setParameters(new HashMap<String, Object>(work.getParameters()));
        for (Iterator<Map.Entry<String, String>> iterator = workItemNode.getInMappings().entrySet().iterator(); iterator.hasNext(); ) {
            Map.Entry<String, String> mapping = iterator.next();
            VariableScopeInstance variableScopeInstance = (VariableScopeInstance)
                resolveContextInstance(VariableScope.VARIABLE_SCOPE, mapping.getValue());
            if (variableScopeInstance != null) {
              ((WorkItem) workItem).setParameter(mapping.getKey(), variableScopeInstance.getVariable(mapping.getValue()));
            } else {
                System.err.println("Could not find variable scope for variable " + mapping.getValue());
                System.err.println("when trying to execute Work Item " + work.getName());
                System.err.println("Continuing without setting parameter.");
            }
        }
        for (Map.Entry<String, Object> entry: workItem.getParameters().entrySet()) {
          if (entry.getValue() instanceof String) {
            String s = (String) entry.getValue();
            Map<String, String> replacements = new HashMap<String, String>();
            Matcher matcher = PARAMETER_MATCHER.matcher(s);
                while (matcher.find()) {
                  String paramName = matcher.group(1);
                  if (replacements.get(paramName) == null) {
                  VariableScopeInstance variableScopeInstance = (VariableScopeInstance)
                      resolveContextInstance(VariableScope.VARIABLE_SCOPE, paramName);
                    if (variableScopeInstance != null) {
                        Object variableValue = variableScopeInstance.getVariable(paramName);
                      String variableValueString = variableValue == null ? "" : variableValue.toString();
                      replacements.put(paramName, variableValueString);
                    } else {
                        System.err.println("Could not find variable scope for variable " + paramName);
                        System.err.println("when trying to replace variable in string for Work Item " + work.getName());
View Full Code Here

TOP

Related Classes of org.drools.process.instance.context.variable.VariableScopeInstance

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.