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

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


  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


        long nodeInstanceCounter = stream.readLong();
        processInstance.setWorkingMemory( wm );

        int nbVariables = stream.readInt();
        if ( nbVariables > 0 ) {
            VariableScopeInstance variableScopeInstance = (VariableScopeInstance) processInstance.getContextInstance( VariableScope.VARIABLE_SCOPE );
            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

        nodeInstance.setId( id );
        switch ( nodeType ) {
            case PersisterEnums.COMPOSITE_NODE_INSTANCE :
                int nbVariables = stream.readInt();
                if ( nbVariables > 0 ) {
                    VariableScopeInstance variableScopeInstance = (VariableScopeInstance) ((CompositeContextNodeInstance) nodeInstance).getContextInstance( VariableScope.VARIABLE_SCOPE );
                    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 );
        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

        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

                "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());
View Full Code Here

      return new String[] { "processInstanceCompleted:" + processInstanceId };
    }
   
    public void processInstanceCompleted(ProcessInstance processInstance) {
        removeEventListeners();
        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
            VariableScopeInstance variableScopeInstance = (VariableScopeInstance)
                resolveContextInstance(VariableScope.VARIABLE_SCOPE, collectionExpression);
            if (variableScopeInstance == null) {
                throw new IllegalArgumentException(
                    "Could not find collection " + collectionExpression);
            }
            Object collection = variableScopeInstance.getVariable(collectionExpression);
            if (collection == null) {
              return Collections.EMPTY_LIST;
            }
            if (collection instanceof Collection<?>) {
              return (Collection<?>) collection;
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.