001    /**
002     * Copyright 2005-2011 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.document.search;
017    
018    import org.apache.commons.collections.CollectionUtils;
019    import org.kuali.rice.core.api.CoreConstants;
020    import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
021    import org.kuali.rice.core.api.mo.ModelBuilder;
022    import org.kuali.rice.core.api.mo.ModelObjectUtils;
023    import org.w3c.dom.Element;
024    
025    import javax.xml.bind.annotation.XmlAccessType;
026    import javax.xml.bind.annotation.XmlAccessorType;
027    import javax.xml.bind.annotation.XmlAnyElement;
028    import javax.xml.bind.annotation.XmlElement;
029    import javax.xml.bind.annotation.XmlElementWrapper;
030    import javax.xml.bind.annotation.XmlRootElement;
031    import javax.xml.bind.annotation.XmlType;
032    import java.io.Serializable;
033    import java.util.ArrayList;
034    import java.util.Collection;
035    import java.util.List;
036    
037    /**
038     * An immutable data transfer object implementation of the {@link DocumentSearchResultValuesContract}.
039     * Instances of this class should be constructed using the nested {@link Builder} class.
040     *
041     * @author Kuali Rice Team (rice.collab@kuali.org)
042     */
043    @XmlRootElement(name = DocumentSearchResultValues.Constants.ROOT_ELEMENT_NAME)
044    @XmlAccessorType(XmlAccessType.NONE)
045    @XmlType(name = DocumentSearchResultValues.Constants.TYPE_NAME, propOrder = {
046        DocumentSearchResultValues.Elements.RESULT_VALUES,
047        CoreConstants.CommonElements.FUTURE_ELEMENTS
048    })
049    public final class DocumentSearchResultValues extends AbstractDataTransferObject implements DocumentSearchResultValuesContract {
050    
051        @XmlElementWrapper(name = Elements.RESULT_VALUES, required = false)
052        @XmlElement(name = Elements.RESULT_VALUE, required = false)
053        private final List<DocumentSearchResultValue> resultValues;
054    
055        @SuppressWarnings("unused")
056        @XmlAnyElement
057        private final Collection<Element> _futureElements = null;
058    
059        /**
060         * Private constructor used only by JAXB.
061         */
062        @SuppressWarnings("unused")
063        private DocumentSearchResultValues() {
064            this.resultValues = null;
065        }
066    
067        private DocumentSearchResultValues(Builder builder) {
068            this.resultValues = ModelObjectUtils.buildImmutableCopy(builder.getResultValues());
069        }
070    
071        @Override
072        public List<DocumentSearchResultValue> getResultValues() {
073            return this.resultValues;
074        }
075    
076        /**
077         * A builder which can be used to construct {@link DocumentSearchResultValues} instances.  Enforces the
078         * constraints of the {@link DocumentSearchResultValuesContract}.
079         */
080        public final static class Builder implements Serializable, ModelBuilder, DocumentSearchResultValuesContract {
081    
082            private List<DocumentSearchResultValue.Builder> resultValues;
083    
084            private Builder() {
085                setResultValues(new ArrayList<DocumentSearchResultValue.Builder>());
086            }
087    
088            /**
089             * Creates new empty builder instance.  The various lists on this builder are initialized to empty lists.  The
090             * internal list of result value builders is initialized to an empty list.
091             *
092             * @return a new empty builder instance
093             */
094            public static Builder create() {
095                return new Builder();
096            }
097    
098            /**
099             * Creates a new builder instance initialized with copies of the properties from the given contract.
100             *
101             * @param contract the contract from which to copy properties
102             *
103             * @return a builder instance initialized with properties from the given contract
104             *
105             * @throws IllegalArgumentException if the given contract is null
106             */
107            public static Builder create(DocumentSearchResultValuesContract contract) {
108                if (contract == null) {
109                    throw new IllegalArgumentException("contract was null");
110                }
111                Builder builder = create();
112                if (!CollectionUtils.isEmpty(contract.getResultValues())) {
113                    for (DocumentSearchResultValueContract resultValueContract : contract.getResultValues()) {
114                        //builder.getResultValues().add(DocumentSearchResultValue.Builder.create(resultValueContract));
115                    }
116                }
117                return builder;
118            }
119    
120            @Override
121            public DocumentSearchResultValues build() {
122                return new DocumentSearchResultValues(this);
123            }
124    
125            @Override
126            public List<DocumentSearchResultValue.Builder> getResultValues() {
127                return this.resultValues;
128            }
129    
130            public void setResultValues(List<DocumentSearchResultValue.Builder> resultValues) {
131                this.resultValues = resultValues;
132            }
133    
134        }
135    
136        /**
137         * Defines some internal constants used on this class.
138         */
139        static class Constants {
140            final static String ROOT_ELEMENT_NAME = "documentSearchResultValues";
141            final static String TYPE_NAME = "DocumentSearchResultValuesType";
142        }
143    
144        /**
145         * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
146         */
147        static class Elements {
148            final static String RESULT_VALUES = "resultValues";
149            final static String RESULT_VALUE = "resultValue";
150        }
151    
152    }