KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > action > evaluator > ActionConditionEvaluatorAbstractBase


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.action.evaluator;
18
19 import org.alfresco.repo.action.ActionConditionDefinitionImpl;
20 import org.alfresco.repo.action.ParameterizedItemAbstractBase;
21 import org.alfresco.service.cmr.action.ActionCondition;
22 import org.alfresco.service.cmr.action.ActionConditionDefinition;
23 import org.alfresco.service.cmr.repository.NodeRef;
24
25 /**
26  * Rule condition evaluator abstract base implementation.
27  *
28  * @author Roy Wetherall
29  */

30 public abstract class ActionConditionEvaluatorAbstractBase extends ParameterizedItemAbstractBase implements ActionConditionEvaluator
31 {
32     /**
33      * Indicates whether the condition is public or not
34      */

35     private boolean publicCondition = true;
36     
37     /**
38      * The action condition definition
39      */

40     protected ActionConditionDefinition actionConditionDefinition;
41     
42     /**
43      * Initialise method
44      */

45     public void init()
46     {
47         if (this.publicCondition == true)
48         {
49             // Call back to the action service to register the condition
50
this.runtimeActionService.registerActionConditionEvaluator(this);
51         }
52     }
53     
54     /**
55      * Set the value that indicates whether a condition is public or not
56      *
57      * @param publicCondition true if the condition is public, false otherwise
58      */

59     public void setPublicCondition(boolean publicCondition)
60     {
61         this.publicCondition = publicCondition;
62     }
63     
64     /**
65      * Get the action condition definition.
66      *
67      * @return the action condition definition
68      */

69     public ActionConditionDefinition getActionConditionDefintion()
70     {
71         if (this.actionConditionDefinition == null)
72         {
73             this.actionConditionDefinition = new ActionConditionDefinitionImpl(this.name);
74             ((ActionConditionDefinitionImpl)this.actionConditionDefinition).setTitleKey(getTitleKey());
75             ((ActionConditionDefinitionImpl)this.actionConditionDefinition).setDescriptionKey(getDescriptionKey());
76             ((ActionConditionDefinitionImpl)this.actionConditionDefinition).setAdhocPropertiesAllowed(getAdhocPropertiesAllowed());
77             ((ActionConditionDefinitionImpl)this.actionConditionDefinition).setConditionEvaluator(this.name);
78             ((ActionConditionDefinitionImpl)this.actionConditionDefinition).setParameterDefinitions(getParameterDefintions());
79         }
80         return this.actionConditionDefinition;
81     }
82     
83     /**
84      * @see org.alfresco.repo.action.evaluator.ActionConditionEvaluator#evaluate(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef)
85      */

86     public boolean evaluate(ActionCondition actionCondition, NodeRef actionedUponNodeRef)
87     {
88         checkMandatoryProperties(actionCondition, getActionConditionDefintion());
89         boolean result = evaluateImpl(actionCondition, actionedUponNodeRef);
90         if (actionCondition.getInvertCondition() == true)
91         {
92             result = !result;
93         }
94         return result;
95     }
96     
97     /**
98      * Evaluation implementation
99      *
100      * @param actionCondition the action condition
101      * @param actionedUponNodeRef the actioned upon node reference
102      * @return the result of the condition evaluation
103      */

104     protected abstract boolean evaluateImpl(ActionCondition actionCondition, NodeRef actionedUponNodeRef);
105 }
106
Popular Tags