KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > workflow > impl > BooleanVariableCondition


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17
18 /* $Id: BooleanVariableCondition.java 42837 2004-04-13 22:04:35Z joerg $ */
19
20 package org.apache.lenya.workflow.impl;
21
22 import org.apache.lenya.workflow.Situation;
23 import org.apache.lenya.workflow.WorkflowException;
24 import org.apache.lenya.workflow.WorkflowInstance;
25 import org.apache.log4j.Category;
26
27 /**
28  * Implementation of a boolean variable condition.
29  */

30 public class BooleanVariableCondition extends AbstractCondition {
31     
32     private static final Category log = Category.getInstance(BooleanVariableCondition.class);
33
34     private String JavaDoc variableName;
35     private boolean value;
36
37     /**
38      * Returns the variable value to check.
39      * @return A boolean value.
40      */

41     protected boolean getValue() {
42         return value;
43     }
44
45     /**
46      * Returns the variable name to check.
47      * @return A string.
48      */

49     protected String JavaDoc getVariableName() {
50         return variableName;
51     }
52
53     /**
54      * @see org.apache.lenya.workflow.Condition#setExpression(java.lang.String)
55      */

56     public void setExpression(String JavaDoc expression) throws WorkflowException {
57         super.setExpression(expression);
58         String JavaDoc[] sides = expression.split("=");
59         if (sides.length != 2) {
60             throw new WorkflowException(
61                 "The expression '" + expression + "' must be of the form 'name = [true|false]'");
62         }
63         
64         variableName = sides[0].trim();
65         value = Boolean.valueOf(sides[1].trim()).booleanValue();
66         
67         if (log.isDebugEnabled()) {
68             log.debug("Expression: [" + sides[1].trim() + "]");
69             log.debug("Setting value: [" + value + "]");
70         }
71     }
72
73     /**
74      * @see org.apache.lenya.workflow.Condition#isComplied(org.apache.lenya.workflow.Situation, org.apache.lenya.workflow.WorkflowInstance)
75      */

76     public boolean isComplied(Situation situation, WorkflowInstance instance) throws WorkflowException {
77         if (log.isDebugEnabled()) {
78             log.debug("Checking boolean variable condition");
79             log.debug(" Condition value: [" + getValue() + "]");
80             log.debug(" Variable value: [" + instance.getValue(getVariableName()) + "]");
81         }
82         return instance.getValue(getVariableName()) == getValue();
83     }
84
85 }
86
Popular Tags