View Javadoc

1   /*
2    * Copyright 2005-2009 The Kuali Foundation
3    * 
4    * 
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    * 
9    * http://www.opensource.org/licenses/ecl2.php
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  package org.kuali.rice.kew.dto;
18  
19  import java.io.Serializable;
20  import java.util.ArrayList;
21  import java.util.Arrays;
22  import java.util.HashMap;
23  import java.util.List;
24  import java.util.Map;
25  
26  /**
27   * Defines a remote WorkflowAttribute and how to construct it.  This is to be used when 
28   * the attributes are being hosted remotely inside the Workflow runtime.
29   * 
30   * The attribute definition must be constructed with the fully qualified class name of the
31   * target attribute.  It can be constructed one of two ways, through the constructor of the
32   * attribute or by setting java bean properties.  If both are specified, then the attribute
33   * will be constructed using both the constructor and properties.  If no constructor
34   * parameters are specified the target attribute must have a no-argument public constructor.
35   * 
36   * The "properties" represented by the PropertyDefinitionVOs will be set as bean properties
37   * (setters) on the target attribute class.  The standard KSB resource/object-definition loading
38   * mechanism implements this functionality.  If the attribute is a GenericXMLRuleAttribute
39   * or GenerixXMLSearchableAttribute, then the properties will also be set explicitly in the <code>paramMap</code>
40   * by the workflow server. 
41   * 
42   * @author Kuali Rice Team (rice.collab@kuali.org)
43   */
44  public class WorkflowAttributeDefinitionDTO implements Serializable {
45      
46      static final long serialVersionUID = 1000;
47      private String attributeName;
48      private List<String> constructorParameters = new ArrayList<String>();
49      private Map<String, PropertyDefinitionDTO> properties = new HashMap<String, PropertyDefinitionDTO>();
50      
51      public WorkflowAttributeDefinitionDTO() {}
52      
53      public WorkflowAttributeDefinitionDTO(String attributeName) {
54          setAttributeName(attributeName);
55      }
56      
57      public String getAttributeName() {
58          return attributeName;
59      }
60      
61      public void setAttributeName(String attributeName) {
62          if (attributeName == null) throw new IllegalArgumentException("Attribute name cannot be null");
63          this.attributeName = attributeName;
64      }
65          
66      public void addConstructorParameter(String parameter) {
67          constructorParameters.add(parameter);
68      }
69      
70      public void removeConstructorParameter(String parameter) {
71          constructorParameters.remove(parameter);
72      }
73      
74      public void setConstructorParameters(String[] parameters) {
75          constructorParameters = Arrays.asList(parameters);
76      }
77      
78      public String[] getConstructorParameters() {
79          return (String[])constructorParameters.toArray(new String[0]);
80      }
81      
82      public void addProperty(PropertyDefinitionDTO property) {
83          if (property == null) return;
84          if (property.getName() == null) {
85              throw new IllegalArgumentException("PropertyDefinition cannot have a null name.");
86          }
87          properties.put(property.getName(), property);
88      }
89      
90      public PropertyDefinitionDTO getProperty(String name) {
91          return (PropertyDefinitionDTO)properties.get(name);
92      }
93      
94      public PropertyDefinitionDTO[] getProperties() {
95          return (PropertyDefinitionDTO[])properties.values().toArray(new PropertyDefinitionDTO[0]);
96      }
97      
98      public void setProperties(PropertyDefinitionDTO[] properties) {
99          this.properties.clear();
100         if (properties == null) return;
101         for (int index = 0; index < properties.length; index++) {
102             addProperty(properties[index]);
103         }
104     }   
105     
106     public void addProperty(String name, String value) {
107         addProperty(new PropertyDefinitionDTO(name, value));
108     }
109 }