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

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


          if (variableAccesses != null) {
            for (VariableAccess variableAccess: variableAccesses) {
              String mappedName = variableAccess.getMappedName();
              if (variableAccess.isReadable()) {
                String variableName = variableAccess.getVariableName();
                VariableScopeInstance variableScopeInstance = (VariableScopeInstance)
                  nodeInstance.resolveContextInstance(VariableScope.VARIABLE_SCOPE, variableName);
                Object value = variableScopeInstance.getVariable(variableName);
                workItem.setParameter(mappedName, value);
              }
              }
          }
        }
View Full Code Here


                String mappedName = variableAccess.getMappedName();
                String variableName = variableAccess.getVariableName();
                if (variableAccess.isWritable()) {
                  Object value = workItem.getParameter(mappedName);
                  if (value != null) {
                    VariableScopeInstance variableScopeInstance = (VariableScopeInstance)
                    nodeInstance.resolveContextInstance(VariableScope.VARIABLE_SCOPE, variableName);
                    variableScopeInstance.setVariable(variableName, value);
                  }
                }
              }
          }
        }
    } else {
      // the default behaviour is that all task-local variables are flushed to the process
      VariableScopeInstance variableScopeInstance = (VariableScopeInstance)
        nodeInstance.getProcessInstance().getContextInstance(VariableScope.VARIABLE_SCOPE);
      for (Map.Entry<String, Object> entry: workItem.getResults().entrySet()) {
        variableScopeInstance.setVariable(entry.getKey(), entry.getValue());
      }
    }
  }
View Full Code Here

      }
      public void leaveNode(Transition transition) {
          leaveNode(transition.getName());
      }
      public void setVariable(String name, Object value) {
          VariableScopeInstance variableScopeInstance = (VariableScopeInstance)
              resolveContextInstance(VariableScope.VARIABLE_SCOPE, name);
          variableScopeInstance.setVariable(name, value);
        }
View Full Code Here

          VariableScopeInstance variableScopeInstance = (VariableScopeInstance)
              resolveContextInstance(VariableScope.VARIABLE_SCOPE, name);
          variableScopeInstance.setVariable(name, value);
        }
        public Object getVariable(String name) {
            VariableScopeInstance variableScopeInstance = (VariableScopeInstance)
                resolveContextInstance(VariableScope.VARIABLE_SCOPE, name);
            if (variableScopeInstance == null) {
              variableScopeInstance = (VariableScopeInstance)
                ((ProcessInstance) JpdlNodeInstance.this.getProcessInstance())
                  .getContextInstance(VariableScope.VARIABLE_SCOPE);
            }
            return variableScopeInstance.getVariable(name);
        }
View Full Code Here

    }
   
    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

        assertEquals(1, session.getProcessInstances().size());
        assertTrue(handler.getWorkItem() != null);
       
        session = getSerialisedStatefulSession( session );
        assertEquals(1, session.getProcessInstances().size());
        VariableScopeInstance variableScopeInstance = (VariableScopeInstance)
          (( ProcessInstance )session.getProcessInstances().iterator().next()).getContextInstance(VariableScope.VARIABLE_SCOPE);
        assertEquals("ThisIsMyValue", variableScopeInstance.getVariable("myVariable"));
       
        session.getWorkItemManager().completeWorkItem(handler.getWorkItem().getId(), null);
       
        assertEquals(0, session.getProcessInstances().size());
    }
View Full Code Here

                                 NodeInstanceContainer nodeInstanceContainer) throws NumberFormatException {
        if ( parentIds.size() == 0 ) {
            if ( !(nodeInstanceContainer instanceof ContextableInstance) ) {
                throw new IllegalArgumentException( "Parent node instance is not a contextable instance: " + nodeInstanceContainer );
            }
            VariableScopeInstance variableScopeInstance = (VariableScopeInstance) ((ContextableInstance) nodeInstanceContainer).getContextInstance( VariableScope.VARIABLE_SCOPE );
            VariablePersistenceStrategy persistenceStrategy = VariablePersistenceStrategyFactory.getVariablePersistenceStrategy();
            Object value = persistenceStrategy.getVariable( variableInfo,
                                                            this.env );
            System.out.println( ">>>>> Restoring variable " + variableName + " = " + value );
            variableScopeInstance.setVariable( variableName,
                                               value );
        } else {
            Long nodeInstanceId = parentIds.get( 0 );
            // find the node and get the variableScopeInstance and insert the
            // variable..
View Full Code Here

        }
    }

    private boolean persistVariables() {
        // Get Process Variables
        VariableScopeInstance variableScopeInstance = (VariableScopeInstance) ((WorkflowProcessInstanceImpl) this.processInstance).getContextInstance( VariableScope.VARIABLE_SCOPE );
        Map<String, Object> processVariables = variableScopeInstance.getVariables();
        Map<String, VariableInstanceInfo> newVariables = new HashMap<String, VariableInstanceInfo>();
        // persist process variables
        persist( processVariables,
                 "",
                 newVariables );
View Full Code Here

            String prefix = parentPrefix + nodeInstance.getId() + VARIABLE_SEPARATOR;
            if ( nodeInstance instanceof ContextInstanceContainer ) {
                List<ContextInstance> variableScopeInstances = ((ContextInstanceContainer) nodeInstance).getContextInstances( VariableScope.VARIABLE_SCOPE );
                if ( variableScopeInstances != null ) {
                    for ( ContextInstance contextInstance : variableScopeInstances ) {
                        VariableScopeInstance variableScopeInstance = (VariableScopeInstance) contextInstance;
                        persist( variableScopeInstance.getVariables(),
                                 prefix,
                                 newVariables );
                    }
                }
            }
View Full Code Here

        ProcessInstance processInstance = ( ProcessInstance )
        workingMemory.startProcess("com.sample.ruleflow", map);
        assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
        assertEquals(2, workingMemory.getProcessInstances().size());
        for (ProcessInstance p: workingMemory.getProcessInstances()) {
        VariableScopeInstance variableScopeInstance = (VariableScopeInstance)
          (( ProcessInstance )p).getContextInstance(VariableScope.VARIABLE_SCOPE);
          if ("com.sample.ruleflow".equals(p.getProcessId())) {
            assertEquals("x-value", variableScopeInstance.getVariable("x"));
          } else if ("com.sample.subflow".equals(p.getProcessId())) {
            assertEquals("x-value", variableScopeInstance.getVariable("y"));
            assertEquals("z-value", variableScopeInstance.getVariable("z"));
            assertEquals(7, variableScopeInstance.getVariable("n"));
            assertEquals(10, variableScopeInstance.getVariable("o"));
          }
        }
        workingMemory.insert(new Person());
        assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
        VariableScopeInstance variableScopeInstance = (VariableScopeInstance)
      processInstance.getContextInstance(VariableScope.VARIABLE_SCOPE);
      assertEquals("z-value", variableScopeInstance.getVariable("x"));
      assertEquals(10, variableScopeInstance.getVariable("m"));
        assertEquals(0, workingMemory.getProcessInstances().size());
    }
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.