001    /**
002     * Copyright 2005-2012 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.rice.kew.framework.rule.attribute;
017    
018    import org.kuali.rice.core.api.CoreConstants;
019    import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
020    import org.kuali.rice.core.api.mo.ModelObjectUtils;
021    import org.kuali.rice.core.api.uif.RemotableAttributeError;
022    import org.kuali.rice.core.api.uif.RemotableAttributeField;
023    import org.kuali.rice.core.api.util.jaxb.MapStringStringAdapter;
024    import org.w3c.dom.Element;
025    
026    import javax.xml.bind.annotation.XmlAccessType;
027    import javax.xml.bind.annotation.XmlAccessorType;
028    import javax.xml.bind.annotation.XmlAnyElement;
029    import javax.xml.bind.annotation.XmlElement;
030    import javax.xml.bind.annotation.XmlElementWrapper;
031    import javax.xml.bind.annotation.XmlRootElement;
032    import javax.xml.bind.annotation.XmlType;
033    import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
034    import java.util.Collection;
035    import java.util.Collections;
036    import java.util.List;
037    import java.util.Map;
038    
039    /**
040     * An immutable data transfer object used to hold a list of validation errors, attribute fields, and rule extension
041     * values for a WorkflowRuleAttribute.
042     *
043     * @author Kuali Rice Team (rice.collab@kuali.org)
044     */
045    @XmlRootElement(name = WorkflowRuleAttributeFields.Constants.ROOT_ELEMENT_NAME)
046    @XmlAccessorType(XmlAccessType.NONE)
047    @XmlType(name = WorkflowRuleAttributeFields.Constants.TYPE_NAME, propOrder = {
048            WorkflowRuleAttributeFields.Elements.VALIDATION_ERRORS,
049            WorkflowRuleAttributeFields.Elements.ATTRIBUTE_FIELDS,
050            WorkflowRuleAttributeFields.Elements.RULE_EXTENSION_VALUES,
051            CoreConstants.CommonElements.FUTURE_ELEMENTS
052    })
053    
054    public class WorkflowRuleAttributeFields extends AbstractDataTransferObject {
055    
056        @XmlElementWrapper(name = Elements.VALIDATION_ERRORS, required = true)
057        @XmlElement(name = Elements.VALIDATION_ERROR, required = false)
058        private final List<RemotableAttributeError> validationErrors;
059    
060        @XmlElementWrapper(name = Elements.ATTRIBUTE_FIELDS, required = true)
061        @XmlElement(name = Elements.ATTRIBUTE_FIELD, required = false)
062        private final List<RemotableAttributeField> attributeFields;
063    
064        @XmlElement(name = Elements.RULE_EXTENSION_VALUES, required = false)
065        @XmlJavaTypeAdapter(MapStringStringAdapter.class)
066        private final Map<String, String> ruleExtensionValues;
067    
068        @SuppressWarnings("unused")
069        @XmlAnyElement
070        private final Collection<Element> _futureElements = null;
071    
072        /**
073         * Private constructor used only by JAXB.
074         */
075        @SuppressWarnings("unused")
076        private WorkflowRuleAttributeFields() {
077            this.validationErrors = null;
078            this.attributeFields = null;
079            this.ruleExtensionValues = null;
080        }
081    
082        private WorkflowRuleAttributeFields(List<RemotableAttributeError> validationErrors,
083                                            List<RemotableAttributeField> attributeFields,
084                                            Map<String, String> ruleExtensionValues) {
085            this.validationErrors = ModelObjectUtils.createImmutableCopy(validationErrors);
086            this.attributeFields = ModelObjectUtils.createImmutableCopy(attributeFields);
087            this.ruleExtensionValues = ModelObjectUtils.createImmutableCopy(ruleExtensionValues);
088        }
089    
090        /**
091         * Construct a new instance of {@code WorkflowRuleAttributeFields} with the given validation errors, fields, and
092         * rule extension values.
093         *
094         * @param validationErrors    any errors associated with these fields
095         * @param attributeFields     the list of remotable attribute fields
096         * @param ruleExtensionValues the rule extension values associated with these fields
097         * @return a new WorkflowRuleAttributeFields instance containing the given values
098         */
099        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    }