Coverage Report - org.kuali.rice.kew.framework.document.search.AttributeFields
 
Classes in this File Line Coverage Branch Coverage Complexity
AttributeFields
0%
0/18
0%
0/6
2
AttributeFields$Constants
0%
0/1
N/A
2
AttributeFields$Elements
0%
0/1
N/A
2
 
 1  
 /**
 2  
  * Copyright 2005-2011 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.document.search;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.core.api.CoreConstants;
 20  
 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
 21  
 import org.kuali.rice.core.api.uif.RemotableAttributeField;
 22  
 import org.w3c.dom.Element;
 23  
 
 24  
 import javax.xml.bind.annotation.XmlAccessType;
 25  
 import javax.xml.bind.annotation.XmlAccessorType;
 26  
 import javax.xml.bind.annotation.XmlAnyElement;
 27  
 import javax.xml.bind.annotation.XmlElement;
 28  
 import javax.xml.bind.annotation.XmlElementWrapper;
 29  
 import javax.xml.bind.annotation.XmlRootElement;
 30  
 import javax.xml.bind.annotation.XmlType;
 31  
 import java.util.ArrayList;
 32  
 import java.util.Collection;
 33  
 import java.util.Collections;
 34  
 import java.util.List;
 35  
 
 36  
 /**
 37  
  * An immutable data transfer object used to hold a list of {@link RemotableAttributeField} objects and the name of the
 38  
  * {@link org.kuali.rice.kew.framework.document.attribute.SearchableAttribute} from which the fields are derived.  This
 39  
  * is essentially used as a grouping mechanism in order to identify which fields are sourced from which attributes.
 40  
  *
 41  
  * <p>Since this class serves primarily as a simple wrapper for use by {@link DocumentSearchCriteriaConfiguration},
 42  
  * it does not have a builder, only a single static create method that is used for constructing instances of it.</p>
 43  
  *
 44  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 45  
  */
 46  
 @XmlRootElement(name = AttributeFields.Constants.ROOT_ELEMENT_NAME)
 47  
 @XmlAccessorType(XmlAccessType.NONE)
 48  
 @XmlType(name = AttributeFields.Constants.TYPE_NAME, propOrder = {
 49  
     AttributeFields.Elements.ATTRIBUTE_NAME,
 50  
     AttributeFields.Elements.REMOTABLE_ATTRIBUTE_FIELDS,
 51  
     CoreConstants.CommonElements.FUTURE_ELEMENTS
 52  
 })
 53  
 public final class AttributeFields extends AbstractDataTransferObject {
 54  
 
 55  
         @XmlElement(name = Elements.ATTRIBUTE_NAME, required = true)
 56  
     private final String attributeName;
 57  
 
 58  
     @XmlElementWrapper(name = Elements.REMOTABLE_ATTRIBUTE_FIELDS, required = true)
 59  
     @XmlElement(name = Elements.REMOTABLE_ATTRIBUTE_FIELD, required = false)
 60  
     private final List<RemotableAttributeField> remotableAttributeFields;
 61  
 
 62  0
     @SuppressWarnings("unused")
 63  
     @XmlAnyElement
 64  
     private final Collection<Element> _futureElements = null;
 65  
 
 66  
     /**
 67  
      * Private constructor used only by JAXB.
 68  
      */
 69  
     @SuppressWarnings("unused")
 70  0
     private AttributeFields() {
 71  0
         this.attributeName = null;
 72  0
         this.remotableAttributeFields = null;
 73  0
     }
 74  
 
 75  0
     private AttributeFields(String attributeName, List<RemotableAttributeField> remotableAttributeFields) {
 76  0
         if (StringUtils.isBlank(attributeName)) {
 77  0
             throw new IllegalArgumentException("attributeName was blank or null");
 78  
         }
 79  0
         if (remotableAttributeFields == null) {
 80  0
             throw new IllegalArgumentException("attributeFields was blank or null");
 81  
         }
 82  0
         this.attributeName = attributeName;
 83  0
         this.remotableAttributeFields = Collections.unmodifiableList(new ArrayList<RemotableAttributeField>(remotableAttributeFields));
 84  0
     }
 85  
 
 86  
     /**
 87  
      * Constract a new instance of {@code AttributeFields} with the given attribute name and list of remotable attribute
 88  
      * fields.
 89  
      *
 90  
      * @param attributeName the name of the attribute, must not be a null or blank value
 91  
      * @param attributeFields the remotable attribute fields to associate with the given attribute name
 92  
      *
 93  
      * @return a new AttributeFields instance containing the given values
 94  
      * @throws IllegalArgumentException if the given attributeName is blank or null
 95  
      */
 96  
     public static AttributeFields create(String attributeName, List<RemotableAttributeField> attributeFields) {
 97  0
         if (attributeFields == null) {
 98  0
             attributeFields = Collections.emptyList();
 99  
         }
 100  0
         return new AttributeFields(attributeName, attributeFields);
 101  
     }
 102  
 
 103  
     /**
 104  
      * Returns the name of the searchable attribute associated with this attribute fields instance.  Should never return
 105  
      * a null or blank value.
 106  
      *
 107  
      * @return the searchable attribute name of this instance
 108  
      */
 109  
     public String getAttributeName() {
 110  0
         return attributeName;
 111  
     }
 112  
 
 113  
     /**
 114  
      * Returns a list of remotable attribute fields associated with the searchable attribute name of this instance.
 115  
      * This should never return a null reference, though the list returned can be empty.
 116  
      *
 117  
      * @return a list of remotable attribute fields associated with this instance
 118  
      */
 119  
     public List<RemotableAttributeField> getRemotableAttributeFields() {
 120  0
         return remotableAttributeFields;
 121  
     }
 122  
 
 123  
     /**
 124  
      * Defines some internal constants used on this class.
 125  
      */
 126  0
     static class Constants {
 127  
         final static String ROOT_ELEMENT_NAME = "attributeFields";
 128  
         final static String TYPE_NAME = "AttributeFieldsType";
 129  
     }
 130  
 
 131  
     /**
 132  
      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
 133  
      */
 134  0
     static class Elements {
 135  
         final static String ATTRIBUTE_NAME = "attributeName";
 136  
         final static String REMOTABLE_ATTRIBUTE_FIELDS = "remotableAttributeFields";
 137  
         final static String REMOTABLE_ATTRIBUTE_FIELD = "remotableAttributeField";
 138  
     }
 139  
 
 140  
 }