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

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


    }
   
    public static class ProcessUtils {
     
      public static Object getValue(RuleFlowProcessInstance processInstance, String name) {
        VariableScopeInstance scope = (VariableScopeInstance)
          processInstance.getContextInstance(VariableScope.VARIABLE_SCOPE);
        return scope.getVariable(name);
      }
View Full Code Here


  public WorkflowProcess getWorkflowProcess() {
    return (WorkflowProcess) getProcess();
  }
 
  public Object getVariable(String name) {
    VariableScopeInstance variableScopeInstance = (VariableScopeInstance)
      getContextInstance(VariableScope.VARIABLE_SCOPE);
    if (variableScopeInstance == null) {
      return null;
    }
    return variableScopeInstance.getVariable(name);
  }
View Full Code Here

        ((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();
            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 Work Item " + work.getName());
                  System.err.println("Continuing without setting parameter.");
              }
            }
            if (parameterValue != null) {
              ((WorkItem) workItem).setParameter(mapping.getKey(), parameterValue);
            }
        }
        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 {
                      try {
                        Object variableValue = MVEL.eval(paramName, new NodeInstanceResolverFactory(this));
View Full Code Here

    }

    public void triggerCompleted(WorkItem workItem) {
        for (Iterator<Map.Entry<String, String>> iterator = getWorkItemNode().getOutMappings().entrySet().iterator(); iterator.hasNext(); ) {
            Map.Entry<String, String> mapping = iterator.next();
            VariableScopeInstance variableScopeInstance = (VariableScopeInstance)
                resolveContextInstance(VariableScope.VARIABLE_SCOPE, mapping.getValue());
            if (variableScopeInstance != null) {
              Object value = workItem.getResult(mapping.getKey());
              if (value == null) {
                try {
                    value = MVEL.eval(mapping.getKey(), new WorkItemResolverFactory(workItem));
                  } 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 Work Item " + workItem.getName());
                System.err.println("Continuing without setting variable.");
            }
View Full Code Here

    stream.writeLong(workFlow.getId());
    stream.writeUTF(workFlow.getProcessId());
    stream.writeInt(workFlow.getState());
    stream.writeLong(workFlow.getNodeInstanceCounter());
   
    VariableScopeInstance variableScopeInstance = (VariableScopeInstance) workFlow.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

    int nbVariables = stream.readInt();
    if (nbVariables > 0) {
      Context variableScope = process
          .getDefaultContext(VariableScope.VARIABLE_SCOPE);
      VariableScopeInstance variableScopeInstance = (VariableScopeInstance)
        processInstance.getContextInstance(variableScope);
      for (int i = 0; i < nbVariables; i++) {
        String name = stream.readUTF();
        try {
          Object value = stream.readObject();
          variableScopeInstance.setVariable(name, value);
        } catch (ClassNotFoundException e) {
          throw new IllegalArgumentException(
            "Could not reload variable " + name);
        }
      }
View Full Code Here

          case PersisterEnums.COMPOSITE_NODE_INSTANCE :
              int nbVariables = stream.readInt();
              if ( nbVariables > 0 ) {
                Context variableScope = ((org.drools.process.core.Process)
                  processInstance.getProcess()).getDefaultContext(VariableScope.VARIABLE_SCOPE);
            VariableScopeInstance variableScopeInstance = (VariableScopeInstance)
              ((CompositeContextNodeInstance) nodeInstance).getContextInstance(variableScope);
                  for ( int i = 0; i < nbVariables; i++ ) {
                      String name = stream.readUTF();
                      try {
                          Object value = stream.readObject();
                          variableScopeInstance.setVariable( name,
                                                             value );
                      } catch ( ClassNotFoundException e ) {
                          throw new IllegalArgumentException( "Could not reload variable " + name );
                      }
                  }
View Full Code Here

        processInstance.setProcess( process );
       
        // set variable default values
        // TODO: should be part of processInstanceImpl?
        VariableScope variableScope = (VariableScope) ((ContextContainer) process).getDefaultContext( VariableScope.VARIABLE_SCOPE );
        VariableScopeInstance variableScopeInstance = (VariableScopeInstance) processInstance.getContextInstance( VariableScope.VARIABLE_SCOPE );
        // set input parameters
        if ( parameters != null ) {
            if ( variableScope != null ) {
                for ( Map.Entry<String, Object> entry : parameters.entrySet() ) {
                    variableScopeInstance.setVariable( entry.getKey(),
                                                       entry.getValue() );
                }
            } else {
                throw new IllegalArgumentException( "This process does not support parameters!" );
            }
View Full Code Here

        processInstance.setProcess( process );
        processInstanceManager.addProcessInstance( processInstance );
        // set variable default values
        // TODO: should be part of processInstanceImpl?
        VariableScope variableScope = (VariableScope) ((ContextContainer) process).getDefaultContext( VariableScope.VARIABLE_SCOPE );
        VariableScopeInstance variableScopeInstance = (VariableScopeInstance) processInstance.getContextInstance( VariableScope.VARIABLE_SCOPE );
        // set input parameters
        if ( parameters != null ) {
            if ( variableScope != null ) {
                for ( Map.Entry<String, Object> entry : parameters.entrySet() ) {
                    variableScopeInstance.setVariable( entry.getKey(),
                                                       entry.getValue() );
                }
            } else {
                throw new IllegalArgumentException( "This process does not support parameters!" );
            }
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.