View Javadoc

1   /**
2    * Copyright 2005-2012 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.coreservice.api.parameter;
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.w3c.dom.Element;
22  
23  import javax.xml.bind.annotation.XmlAccessType;
24  import javax.xml.bind.annotation.XmlAccessorType;
25  import javax.xml.bind.annotation.XmlAnyElement;
26  import javax.xml.bind.annotation.XmlElement;
27  import javax.xml.bind.annotation.XmlRootElement;
28  import javax.xml.bind.annotation.XmlType;
29  import java.util.Collection;
30  
31  /**
32  *  This class represents the 4-part key which uniquely identifies a parameter.
33  *  
34  *  @see ParameterContract
35  *  @see Parameter
36  */
37  @XmlRootElement(name = ParameterKey.Constants.ROOT_ELEMENT_NAME)
38  @XmlAccessorType(XmlAccessType.NONE)
39  @XmlType(name = ParameterKey.Constants.TYPE_NAME, propOrder = {
40      ParameterKey.Elements.APPLICATION_ID,
41      ParameterKey.Elements.NAMESPACE_CODE,
42      ParameterKey.Elements.COMPONENT_CODE,
43      ParameterKey.Elements.NAME,
44      CoreConstants.CommonElements.FUTURE_ELEMENTS
45  })
46  public final class ParameterKey extends AbstractDataTransferObject {
47  
48  	private static final long serialVersionUID = -4405355319548951283L;
49  
50  	@XmlElement(name = Elements.APPLICATION_ID, required=true)
51  	private final String applicationId;
52  
53  	@XmlElement(name = Elements.NAMESPACE_CODE, required=true)
54  	private final String namespaceCode;
55  
56  	@XmlElement(name = Elements.COMPONENT_CODE, required=true)
57  	private final String componentCode;
58  	
59      @XmlElement(name = Elements.NAME, required=true)
60      private final String name;
61  
62      @SuppressWarnings("unused")
63  	@XmlAnyElement
64      private final Collection<Element> _futureElements = null;
65  
66      /** 
67       * This constructor should never be called except during JAXB unmarshalling. 
68       */
69      private ParameterKey() {
70      	this.applicationId = null;
71      	this.namespaceCode = null;
72      	this.componentCode = null;
73      	this.name = null;
74      }
75  
76  	/**
77  	 * Constructs a ParameterKey from the given values.
78  	 */
79      private ParameterKey(String applicationId, String namespaceCode, String componentCode, String name) {
80          if (StringUtils.isBlank(applicationId)) {
81              throw new IllegalArgumentException("applicationId is blank");
82          }
83          if (StringUtils.isBlank(namespaceCode)) {
84              throw new IllegalArgumentException("namespaceCode is blank");
85          }
86          if (StringUtils.isBlank(componentCode)) {
87              throw new IllegalArgumentException("componentCode is blank");
88          }
89  		if (StringUtils.isBlank(name)) {
90  			throw new IllegalArgumentException("name is blank");
91  		}
92          this.applicationId = applicationId;
93          this.namespaceCode = namespaceCode;
94          this.componentCode = componentCode;
95  		this.name = name;
96      }
97  
98      /**
99       * Creates a ParameterKey from the given required values.
100      * 
101      * @param applicationId the application id, cannot be null or blank
102      * @param namespaceCode the namespace code, cannot be null or blank
103      * @param componentCode the component code, cannot be null or blank
104 	 * @param name the parameter name, cannot be null or blank
105      * @return the fully-constructed ParameterKey
106      * @throws IllegalArgumentException if any arguments are null or blank
107      */
108     public static ParameterKey create(String applicationId, String namespaceCode, String componentCode, String name) {
109         return new ParameterKey(applicationId, namespaceCode, componentCode, name);
110     }
111 	
112     public String getApplicationId() {
113 		return applicationId;
114 	}
115 
116 	public String getNamespaceCode() {
117 		return namespaceCode;
118 	}
119 
120 	public String getComponentCode() {
121 		return componentCode;
122 	}
123 
124 	public String getName() {
125 		return name;
126 	}
127 
128     public String getCacheKey() {
129         return this.applicationId + ":" + this.namespaceCode + ":" + this.componentCode + ":" + this.name;
130     }
131     
132 	/**
133 	 * Defines some internal constants used on this class.
134 	 */
135 	static class Constants {
136 		final static String ROOT_ELEMENT_NAME = "parameterKey";
137 		final static String TYPE_NAME = "ParameterKeyType";
138 	}
139   
140 	/**
141 	 * A private class which exposes constants which define the XML element names to use
142 	 * when this object is marshalled to XML.
143 	 */
144 	static class Elements {
145 		final static String APPLICATION_ID = "applicationId";
146 		final static String NAMESPACE_CODE = "namespaceCode";
147 		final static String COMPONENT_CODE = "componentCode";
148 		final static String NAME = "name";
149 	}
150   
151 }