KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > action > ParameterizedItemAbstractBase


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;
18
19 import java.text.MessageFormat JavaDoc;
20 import java.util.ArrayList JavaDoc;
21 import java.util.List JavaDoc;
22
23 import org.alfresco.i18n.I18NUtil;
24 import org.alfresco.service.cmr.action.ParameterDefinition;
25 import org.alfresco.service.cmr.action.ParameterizedItem;
26 import org.alfresco.service.cmr.action.ParameterizedItemDefinition;
27 import org.alfresco.service.cmr.rule.RuleServiceException;
28
29 /**
30  * Rule item abstract base.
31  * <p>
32  * Helper base class used by the action exector and condition evaluator implementations.
33  *
34  * @author Roy Wetherall
35  */

36 public abstract class ParameterizedItemAbstractBase extends CommonResourceAbstractBase
37 {
38     /**
39      * Error messages
40      */

41     private static final String JavaDoc ERR_MAND_PROP = "A value for the mandatory parameter {0} has not been set on the rule item {1}";
42     
43     /**
44      * Look-up constants
45      */

46     private static final String JavaDoc TITLE = "title";
47     private static final String JavaDoc DESCRIPTION = "description";
48     private static final String JavaDoc DISPLAY_LABEL = "display-label";
49     
50     /**
51      * Action service
52      */

53     protected RuntimeActionService runtimeActionService;
54     
55     /**
56      * @return Return a short title and description string
57      */

58     public String JavaDoc toString()
59     {
60         StringBuilder JavaDoc sb = new StringBuilder JavaDoc(60);
61         sb.append("ParameterizedItem")
62           .append("[ title='").append(getTitleKey()).append("'")
63           .append(", description='").append(getDescriptionKey()).append("'")
64           .append("]");
65         return sb.toString();
66     }
67     
68     /**
69      * Gets a list containing the parameter definitions for this rule item.
70      *
71      * @return the list of parameter definitions
72      */

73     protected List JavaDoc<ParameterDefinition> getParameterDefintions()
74     {
75         List JavaDoc<ParameterDefinition> result = new ArrayList JavaDoc<ParameterDefinition>();
76         addParameterDefintions(result);
77         return result;
78     }
79     
80     /**
81      * Adds the parameter definitions to the list
82      *
83      * @param paramList the parameter definitions list
84      */

85     protected abstract void addParameterDefintions(List JavaDoc<ParameterDefinition> paramList);
86
87     /**
88      * Sets the action service
89      *
90      * @param actionRegistration the action service
91      */

92     public void setRuntimeActionService(RuntimeActionService runtimeActionService)
93     {
94         this.runtimeActionService = runtimeActionService;
95     }
96
97     /**
98      * Gets the title I18N key
99      *
100      * @return the title key
101      */

102     protected String JavaDoc getTitleKey()
103     {
104         return this.name + "." + TITLE;
105     }
106
107     /**
108      * Gets the description I18N key
109      *
110      * @return the description key
111      */

112     protected String JavaDoc getDescriptionKey()
113     {
114         return this.name + "." + DESCRIPTION;
115     }
116     
117     /**
118      * Indicates whether adhoc property definitions are allowed or not
119      *
120      * @return true if they are, by default false
121      */

122     protected boolean getAdhocPropertiesAllowed()
123     {
124         // By default adhoc properties are not allowed
125
return false;
126     }
127
128     /**
129      * Gets the parameter definition display label from the properties file.
130      *
131      * @param paramName the name of the parameter
132      * @return the diaplay label of the parameter
133      */

134     protected String JavaDoc getParamDisplayLabel(String JavaDoc paramName)
135     {
136         return I18NUtil.getMessage(this.name + "." + paramName + "." + DISPLAY_LABEL);
137     }
138     
139     /**
140      * Checked whether all the mandatory parameters for the rule item have been assigned.
141      *
142      * @param ruleItem the rule item
143      * @param ruleItemDefinition the rule item definition
144      */

145     protected void checkMandatoryProperties(ParameterizedItem ruleItem, ParameterizedItemDefinition ruleItemDefinition)
146     {
147         List JavaDoc<ParameterDefinition> definitions = ruleItemDefinition.getParameterDefinitions();
148         for (ParameterDefinition definition : definitions)
149         {
150             if (definition.isMandatory() == true)
151             {
152                 // Check that a value has been set for the mandatory parameter
153
if (ruleItem.getParameterValue(definition.getName()) == null)
154                 {
155                     // Error since a mandatory parameter has a null value
156
throw new RuleServiceException(
157                           MessageFormat.format(ERR_MAND_PROP, new Object JavaDoc[]{definition.getName(), ruleItemDefinition.getName()}));
158                 }
159             }
160         }
161         
162     }
163 }
164
Popular Tags