⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 abstractworkflow.java

📁 osworkflow修改版本
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
            ActionDescriptor action = (ActionDescriptor) iterator2.next();            //check auto            if (action.getAutoExecute()) {                if (isActionAvailable(action, transientVars, ps, s.getId())) {                    l.add(new Integer(action.getId()));                }            }        }        return l;    }    protected WorkflowStore getPersistence() throws StoreException {        return getConfiguration().getWorkflowStore();    }    protected void checkImplicitFinish(long id) throws WorkflowException {        WorkflowStore store = getPersistence();        WorkflowEntry entry = store.findEntry(id);        WorkflowDescriptor wf = getConfiguration().getWorkflow(entry.getWorkflowName());        Collection currentSteps = store.findCurrentSteps(id);        boolean isCompleted = true;        for (Iterator iterator = currentSteps.iterator(); iterator.hasNext();) {            Step step = (Step) iterator.next();            StepDescriptor stepDes = wf.getStep(step.getStepId());            // if at least on current step have an available action            if (stepDes.getActions().size() > 0) {                isCompleted = false;            }        }        if (isCompleted == true) {            completeEntry(id, currentSteps);        }    }    /**     * Mark the specified entry as completed, and move all current steps to history.     */    protected void completeEntry(long id, Collection currentSteps) throws StoreException {        getPersistence().setEntryState(id, WorkflowEntry.COMPLETED);        Iterator i = new ArrayList(currentSteps).iterator();        while (i.hasNext()) {            Step step = (Step) i.next();            getPersistence().moveToHistory(step);        }    }    protected Object loadObject(String clazz) {        try {            return ClassLoaderUtil.loadClass(clazz.trim(), getClass()).newInstance();        } catch (Exception e) {            log.error("Could not load object '" + clazz + "'", e);            return null;        }    }    protected boolean passesCondition(ConditionDescriptor conditionDesc, Map transientVars, PropertySet ps, int currentStepId) throws WorkflowException {        String type = conditionDesc.getType();        Map args = new HashMap(conditionDesc.getArgs());        for (Iterator iterator = args.entrySet().iterator();                iterator.hasNext();) {            Map.Entry mapEntry = (Map.Entry) iterator.next();            mapEntry.setValue(ScriptVariableParser.translateVariables((String) mapEntry.getValue(), transientVars, ps));        }        if (currentStepId != -1) {            Object stepId = args.get("stepId");            if ((stepId != null) && stepId.equals("-1")) {                args.put("stepId", String.valueOf(currentStepId));            }        }        String clazz;        if ("remote-ejb".equals(type)) {            clazz = RemoteEJBCondition.class.getName();        } else if ("local-ejb".equals(type)) {            clazz = LocalEJBCondition.class.getName();        } else if ("jndi".equals(type)) {            clazz = JNDICondition.class.getName();        } else if ("bsf".equals(type)) {            clazz = BSFCondition.class.getName();        } else if ("beanshell".equals(type)) {            clazz = BeanShellCondition.class.getName();        } else {            clazz = (String) args.get(CLASS_NAME);        }        Condition condition = (Condition) loadObject(clazz);        if (condition == null) {            String message = "Could not load Condition: " + clazz;            throw new WorkflowException(message);        }        try {            boolean passed = condition.passesCondition(transientVars, args, ps);            if (conditionDesc.isNegate()) {                passed = !passed;            }            return passed;        } catch (Exception e) {            context.setRollbackOnly();            if (e instanceof WorkflowException) {                throw (WorkflowException) e;            }            throw new WorkflowException("Unknown exception encountered when trying condition: " + clazz, e);        }    }    protected boolean passesConditions(String conditionType, List conditions, Map transientVars, PropertySet ps, int currentStepId) throws WorkflowException {        if ((conditions == null) || (conditions.size() == 0)) {            return true;        }        boolean and = "AND".equals(conditionType);        boolean or = !and;        for (Iterator iterator = conditions.iterator(); iterator.hasNext();) {            AbstractDescriptor descriptor = (AbstractDescriptor) iterator.next();            boolean result;            if (descriptor instanceof ConditionsDescriptor) {                ConditionsDescriptor conditionsDescriptor = (ConditionsDescriptor) descriptor;                result = passesConditions(conditionsDescriptor.getType(), conditionsDescriptor.getConditions(), transientVars, ps, currentStepId);            } else {                result = passesCondition((ConditionDescriptor) descriptor, transientVars, ps, currentStepId);            }            if (and && !result) {                return false;            } else if (or && result) {                return true;            }        }        if (and) {            return true;        } else if (or) {            return false;        } else {            return false;        }    }    protected void populateTransientMap(WorkflowEntry entry, Map transientVars, List registers, Integer actionId, Collection currentSteps) throws WorkflowException {        transientVars.put("context", context);        transientVars.put("entry", entry);        transientVars.put("store", getPersistence());        transientVars.put("descriptor", getConfiguration().getWorkflow(entry.getWorkflowName()));        if (actionId != null) {            transientVars.put("actionId", actionId);        }        transientVars.put("currentSteps", Collections.unmodifiableCollection(currentSteps));        // now talk to the registers for any extra objects needed in scope        for (Iterator iterator = registers.iterator(); iterator.hasNext();) {            RegisterDescriptor register = (RegisterDescriptor) iterator.next();            Map args = register.getArgs();            String type = register.getType();            String clazz;            if ("remote-ejb".equals(type)) {                clazz = RemoteEJBRegister.class.getName();            } else if ("local-ejb".equals(type)) {                clazz = LocalEJBRegister.class.getName();            } else if ("jndi".equals(type)) {                clazz = JNDIRegister.class.getName();            } else if ("bsf".equals(type)) {                clazz = BSFRegister.class.getName();            } else if ("beanshell".equals(type)) {                clazz = BeanShellRegister.class.getName();            } else {                clazz = (String) args.get(CLASS_NAME);            }            Register r = (Register) loadObject(clazz);            if (r == null) {                String message = "Could not load register class: " + clazz;                throw new WorkflowException(message);            }            try {                transientVars.put(register.getVariableName(), r.registerVariable(context, entry, args));            } catch (Exception e) {                context.setRollbackOnly();                if (e instanceof WorkflowException) {                    throw (WorkflowException) e;                }                throw new WorkflowException("An unknown exception occured while registering variable using class: " + clazz, e);            }        }    }    /**     * Validates input against a list of ValidatorDescriptor objects.     *     * @param entry the workflow instance     * @param validators the list of ValidatorDescriptors     * @param transientVars the transientVars     * @param ps the persistence variables     * @throws InvalidInputException if the input is deemed invalid by any validator     */    protected void verifyInputs(WorkflowEntry entry, List validators, Map transientVars, PropertySet ps) throws WorkflowException {        for (Iterator iterator = validators.iterator(); iterator.hasNext();) {            ValidatorDescriptor input = (ValidatorDescriptor) iterator.next();            if (input != null) {                String type = input.getType();                HashMap args = new HashMap(input.getArgs());                for (Iterator iterator2 = args.entrySet().iterator();                        iterator2.hasNext();) {                    Map.Entry mapEntry = (Map.Entry) iterator2.next();                    mapEntry.setValue(ScriptVariableParser.translateVariables((String) mapEntry.getValue(), transientVars, ps));                }                String clazz;                if ("remote-ejb".equals(type)) {                    clazz = RemoteEJBValidator.class.getName();                } else if ("local-ejb".equals(type)) {                    clazz = LocalEJBValidator.class.getName();                } else if ("jndi".equals(type)) {                    clazz = JNDIValidator.class.getName();                } else if ("bsf".equals(type)) {                    clazz = BSFValidator.class.getName();                } else if ("beanshell".equals(type)) {                    clazz = BeanShellValidator.class.getName();                } else {                    clazz = (String) args.get(CLASS_NAME);                }                Validator validator = (Validator) loadObject(clazz);                if (validator == null) {                    String message = "Could not load validator class: " + clazz;                    throw new WorkflowException(message);                }                try {                    validator.validate(transientVars, args, ps);                } catch (InvalidInputException e) {                    throw e;                } catch (Exception e) {                    context.setRollbackOnly();                    if (e instanceof WorkflowException) {                        throw (WorkflowException) e;                    }                    String message = "An unknown exception occured executing Validator: " + clazz;                    throw new WorkflowException(message, e);                }            }        }    }    /**     * check if an action is available or not     * @param action The action descriptor     * @return true if the action is available     */    private boolean isActionAvailable(ActionDescriptor action, Map transientVars, PropertySet ps, int stepId) throws WorkflowException {        if (action == null) {            return false;        }        RestrictionDescriptor restriction = action.getRestriction();        List conditions = null;        if (restriction != null) {            conditions = restriction.getConditions();        }        return passesConditions(null, conditions, Collections.unmodifiableMap(transientVars), ps, stepId);    }    private Step getCurrentStep(WorkflowDescriptor wfDesc, int actionId, List currentSteps, Map transientVars, PropertySet ps) throws WorkflowException {        if (currentSteps.size() == 1) {            return (Step) currentSteps.get(0);        }        for (Iterator iterator = currentSteps.iterator(); iterator.hasNext();) {            Step step = (Step) iterator.next();            ActionDescriptor action = wfDesc.getStep(step.getStepId()).getAction(actionId);            //$AR init            if (isActionAvailable(action, transientVars, ps, step.getStepId())) {                return step;            }            //$AR end        }        return null;    }    private boolean canInitialize(String workflowName, int initialAction, Map transientVars, PropertySet ps) throws WorkflowException {        WorkflowDescriptor wf = getConfiguration().getWorkflow(workflowName);        ActionDescriptor actionDescriptor = wf.getInitialAction(initialAction);        if (actionDescriptor == null) {            throw new InvalidActionException("Invalid Initial Action #" + initialAction);        }        RestrictionDescriptor restriction = actionDescriptor.getRestriction();        List conditions = null;        if (restriction != null) {            conditions = restriction.getConditions();        }        return passesConditions(null, conditions, Collections.unmodifiableMap(transientVars), ps, 0);    }    private Step createNewCurrentStep(ResultDescriptor theResult, WorkflowEntry entry, WorkflowStore store, int actionId, Step currentStep, long[] previousIds, Map transientVars, PropertySet ps) throws WorkflowException {        try {            int nextStep = theResult.getStep();            if (nextStep == -1) {                if (currentStep != null) {                    nextStep = currentStep.getStepId();                } else {                    throw new StoreException("Illegal argument: requested new current step same as current step, but current step not specified");                }            }            if (log.isDebugEnabled()) {                log.debug("Outcome: stepId=" + nextStep + ", status=" + theResult.getStatus() + ", owner=" + theResult.getOwner() + ", actionId=" + actionId + ", currentStep=" + ((currentStep != null) ? currentStep.getStepId() : 0));            }            if (previousIds == null) {                previousIds = new long[0];            }            String owner = TextUtils.noNull(theResult.getOwner());            if (owner.equals("")) {                owner = null;            } else {                Object o = ScriptVariableParser.translateVariables(owner, transientVars, ps);                owner = (o != null) ? o.toString() : null;            }            String oldStatus = theResult.getOldStatus();            oldStatus = ScriptVariableParser.translateVariables(oldStatus, transientVars, ps).toString();            String status = theResult.getStatus();            status = ScriptVariableParser.translateVariables(status, transientVars, ps).toString();            if (currentStep != null) {                store.markFinished(currentStep, actionId, new Date(), oldStatus, context.getCaller());                store.moveToHistory(currentStep);                //store.moveToHistory(actionId, new Date(), currentStep, oldStatus, context.getCaller());

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -