01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18:
19: /* $Id: BooleanVariableCondition.java 473861 2006-11-12 03:51:14Z gregor $ */
20:
21: package org.apache.lenya.workflow.impl;
22:
23: import org.apache.lenya.workflow.Version;
24: import org.apache.lenya.workflow.Workflow;
25: import org.apache.lenya.workflow.WorkflowException;
26: import org.apache.lenya.workflow.Workflowable;
27:
28: /**
29: * Implementation of a boolean variable condition.
30: */
31: public class BooleanVariableCondition extends AbstractCondition {
32:
33: private String variableName;
34: private boolean value;
35:
36: /**
37: * Returns the variable value to check.
38: * @return A boolean value.
39: */
40: protected boolean getValue() {
41: return this .value;
42: }
43:
44: /**
45: * Returns the variable name to check.
46: * @return A string.
47: */
48: protected String getVariableName() {
49: return this .variableName;
50: }
51:
52: /**
53: * @see org.apache.lenya.workflow.Condition#setExpression(java.lang.String)
54: */
55: public void setExpression(String expression)
56: throws WorkflowException {
57: super .setExpression(expression);
58: String[] sides = expression.split("=");
59: if (sides.length != 2) {
60: throw new WorkflowException("The expression '" + expression
61: + "' must be of the form 'name = [true|false]'");
62: }
63:
64: this .variableName = sides[0].trim();
65: this .value = Boolean.valueOf(sides[1].trim()).booleanValue();
66:
67: if (getLogger().isDebugEnabled()) {
68: getLogger().debug(
69: "Expression: [" + sides[1].trim() + "]");
70: getLogger().debug("Setting value: [" + this .value + "]");
71: }
72: }
73:
74: /**
75: * @see org.apache.lenya.workflow.Condition#isComplied(org.apache.lenya.workflow.Workflow,
76: * org.apache.lenya.workflow.Workflowable)
77: */
78: public boolean isComplied(Workflow workflow,
79: Workflowable workflowable) throws WorkflowException {
80: Version latestVersion = workflowable.getLatestVersion();
81: boolean value = false;
82: if (latestVersion == null) {
83: value = workflow.getInitialValue(getVariableName());
84: } else {
85: value = latestVersion.getValue(getVariableName());
86: }
87:
88: if (getLogger().isDebugEnabled()) {
89: getLogger().debug("Checking boolean variable condition");
90: getLogger().debug(
91: " Condition value: [" + getValue() + "]");
92: getLogger().debug(" Variable value: [" + value + "]");
93: }
94: return value == getValue();
95: }
96: }
|