View Javadoc

1   /**
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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  package org.kuali.rice.kew.framework.rule.attribute;
17  
18  import org.kuali.rice.core.api.CoreConstants;
19  import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
20  import org.kuali.rice.core.api.mo.ModelObjectUtils;
21  import org.kuali.rice.core.api.uif.RemotableAttributeError;
22  import org.kuali.rice.core.api.uif.RemotableAttributeField;
23  import org.kuali.rice.core.api.util.jaxb.MapStringStringAdapter;
24  import org.w3c.dom.Element;
25  
26  import javax.xml.bind.annotation.XmlAccessType;
27  import javax.xml.bind.annotation.XmlAccessorType;
28  import javax.xml.bind.annotation.XmlAnyElement;
29  import javax.xml.bind.annotation.XmlElement;
30  import javax.xml.bind.annotation.XmlElementWrapper;
31  import javax.xml.bind.annotation.XmlRootElement;
32  import javax.xml.bind.annotation.XmlType;
33  import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
34  import java.util.Collection;
35  import java.util.Collections;
36  import java.util.List;
37  import java.util.Map;
38  
39  /**
40   * An immutable data transfer object used to hold a list of validation errors, attribute fields, and rule extension
41   * values for a WorkflowRuleAttribute.
42   *
43   * @author Kuali Rice Team (rice.collab@kuali.org)
44   */
45  @XmlRootElement(name = WorkflowRuleAttributeFields.Constants.ROOT_ELEMENT_NAME)
46  @XmlAccessorType(XmlAccessType.NONE)
47  @XmlType(name = WorkflowRuleAttributeFields.Constants.TYPE_NAME, propOrder = {
48          WorkflowRuleAttributeFields.Elements.VALIDATION_ERRORS,
49          WorkflowRuleAttributeFields.Elements.ATTRIBUTE_FIELDS,
50          WorkflowRuleAttributeFields.Elements.RULE_EXTENSION_VALUES,
51          CoreConstants.CommonElements.FUTURE_ELEMENTS
52  })
53  
54  public class WorkflowRuleAttributeFields extends AbstractDataTransferObject {
55  
56      @XmlElementWrapper(name = Elements.VALIDATION_ERRORS, required = true)
57      @XmlElement(name = Elements.VALIDATION_ERROR, required = false)
58      private final List<RemotableAttributeError> validationErrors;
59  
60      @XmlElementWrapper(name = Elements.ATTRIBUTE_FIELDS, required = true)
61      @XmlElement(name = Elements.ATTRIBUTE_FIELD, required = false)
62      private final List<RemotableAttributeField> attributeFields;
63  
64      @XmlElement(name = Elements.RULE_EXTENSION_VALUES, required = false)
65      @XmlJavaTypeAdapter(MapStringStringAdapter.class)
66      private final Map<String, String> ruleExtensionValues;
67  
68      @SuppressWarnings("unused")
69      @XmlAnyElement
70      private final Collection<Element> _futureElements = null;
71  
72      /**
73       * Private constructor used only by JAXB.
74       */
75      @SuppressWarnings("unused")
76      private WorkflowRuleAttributeFields() {
77          this.validationErrors = null;
78          this.attributeFields = null;
79          this.ruleExtensionValues = null;
80      }
81  
82      private WorkflowRuleAttributeFields(List<RemotableAttributeError> validationErrors,
83                                          List<RemotableAttributeField> attributeFields,
84                                          Map<String, String> ruleExtensionValues) {
85          this.validationErrors = ModelObjectUtils.createImmutableCopy(validationErrors);
86          this.attributeFields = ModelObjectUtils.createImmutableCopy(attributeFields);
87          this.ruleExtensionValues = ModelObjectUtils.createImmutableCopy(ruleExtensionValues);
88      }
89  
90      /**
91       * Construct a new instance of {@code WorkflowRuleAttributeFields} with the given validation errors, fields, and
92       * rule extension values.
93       *
94       * @param validationErrors    any errors associated with these fields
95       * @param attributeFields     the list of remotable attribute fields
96       * @param ruleExtensionValues the rule extension values associated with these fields
97       * @return a new WorkflowRuleAttributeFields instance containing the given values
98       */
99      public static WorkflowRuleAttributeFields create(List<RemotableAttributeError> validationErrors,
100                                                      List<RemotableAttributeField> attributeFields,
101                                                      Map<String, String> ruleExtensionValues) {
102         if (validationErrors == null) {
103             validationErrors = Collections.emptyList();
104         }
105         if (attributeFields == null) {
106             attributeFields = Collections.emptyList();
107         }
108         if (ruleExtensionValues == null) {
109             ruleExtensionValues = Collections.emptyMap();
110         }
111         return new WorkflowRuleAttributeFields(validationErrors, attributeFields, ruleExtensionValues);
112     }
113 
114     public List<RemotableAttributeError> getValidationErrors() {
115         return validationErrors;
116     }
117 
118     public List<RemotableAttributeField> getAttributeFields() {
119         return attributeFields;
120     }
121 
122     public Map<String, String> getRuleExtensionValues() {
123         return ruleExtensionValues;
124     }
125 
126     /**
127      * Defines some internal constants used on this class.
128      */
129     static class Constants {
130         final static String ROOT_ELEMENT_NAME = "workflowRuleAttributeFields";
131         final static String TYPE_NAME = "WorkflowRuleAttributeFieldsType";
132     }
133 
134     /**
135      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
136      */
137     static class Elements {
138         final static String VALIDATION_ERRORS = "validationErrors";
139         final static String VALIDATION_ERROR = "validationError";
140         final static String ATTRIBUTE_FIELDS = "attributeFields";
141         final static String ATTRIBUTE_FIELD = "attributeField";
142         final static String RULE_EXTENSION_VALUES = "ruleExtensionValues";
143 
144     }
145 
146 }