001/** 002 * Copyright 2005-2016 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 */ 016package org.kuali.rice.kew.framework.document.search; 017 018import org.apache.commons.lang.StringUtils; 019import org.kuali.rice.core.api.CoreConstants; 020import org.kuali.rice.core.api.mo.AbstractDataTransferObject; 021import org.kuali.rice.core.api.uif.RemotableAttributeField; 022import org.w3c.dom.Element; 023 024import javax.xml.bind.annotation.XmlAccessType; 025import javax.xml.bind.annotation.XmlAccessorType; 026import javax.xml.bind.annotation.XmlAnyElement; 027import javax.xml.bind.annotation.XmlElement; 028import javax.xml.bind.annotation.XmlElementWrapper; 029import javax.xml.bind.annotation.XmlRootElement; 030import javax.xml.bind.annotation.XmlType; 031import java.util.ArrayList; 032import java.util.Collection; 033import java.util.Collections; 034import java.util.List; 035 036/** 037 * An immutable data transfer object used to hold a list of {@link RemotableAttributeField} objects and the name of the 038 * {@link org.kuali.rice.kew.framework.document.attribute.SearchableAttribute} from which the fields are derived. This 039 * is essentially used as a grouping mechanism in order to identify which fields are sourced from which attributes. 040 * 041 * <p>Since this class serves primarily as a simple wrapper for use by {@link DocumentSearchCriteriaConfiguration}, 042 * it does not have a builder, only a single static create method that is used for constructing instances of it.</p> 043 * 044 * @author Kuali Rice Team (rice.collab@kuali.org) 045 */ 046@XmlRootElement(name = AttributeFields.Constants.ROOT_ELEMENT_NAME) 047@XmlAccessorType(XmlAccessType.NONE) 048@XmlType(name = AttributeFields.Constants.TYPE_NAME, propOrder = { 049 AttributeFields.Elements.ATTRIBUTE_NAME, 050 AttributeFields.Elements.REMOTABLE_ATTRIBUTE_FIELDS, 051 CoreConstants.CommonElements.FUTURE_ELEMENTS 052}) 053public final class AttributeFields extends AbstractDataTransferObject { 054 055 @XmlElement(name = Elements.ATTRIBUTE_NAME, required = true) 056 private final String attributeName; 057 058 @XmlElementWrapper(name = Elements.REMOTABLE_ATTRIBUTE_FIELDS, required = true) 059 @XmlElement(name = Elements.REMOTABLE_ATTRIBUTE_FIELD, required = false) 060 private final List<RemotableAttributeField> remotableAttributeFields; 061 062 @SuppressWarnings("unused") 063 @XmlAnyElement 064 private final Collection<Element> _futureElements = null; 065 066 /** 067 * Private constructor used only by JAXB. 068 */ 069 @SuppressWarnings("unused") 070 private AttributeFields() { 071 this.attributeName = null; 072 this.remotableAttributeFields = null; 073 } 074 075 private AttributeFields(String attributeName, List<RemotableAttributeField> remotableAttributeFields) { 076 if (StringUtils.isBlank(attributeName)) { 077 throw new IllegalArgumentException("attributeName was blank or null"); 078 } 079 if (remotableAttributeFields == null) { 080 throw new IllegalArgumentException("attributeFields was blank or null"); 081 } 082 this.attributeName = attributeName; 083 this.remotableAttributeFields = Collections.unmodifiableList(new ArrayList<RemotableAttributeField>(remotableAttributeFields)); 084 } 085 086 /** 087 * Construct a new instance of {@code AttributeFields} with the given attribute name and list of remotable attribute 088 * fields. 089 * 090 * @param attributeName the name of the attribute, must not be a null or blank value 091 * @param attributeFields the remotable attribute fields to associate with the given attribute name 092 * 093 * @return a new AttributeFields instance containing the given values 094 * @throws IllegalArgumentException if the given attributeName is blank or null 095 */ 096 public static AttributeFields create(String attributeName, List<RemotableAttributeField> attributeFields) { 097 if (attributeFields == null) { 098 attributeFields = Collections.emptyList(); 099 } 100 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 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 return remotableAttributeFields; 121 } 122 123 /** 124 * Defines some internal constants used on this class. 125 */ 126 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 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}