View Javadoc

1   /**
2    * Copyright 2005-2013 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.krms.api.repository.context;
17  
18  import org.kuali.rice.core.api.CoreConstants;
19  import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
20  import org.kuali.rice.core.api.util.jaxb.MapStringStringAdapter;
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 javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
30  import java.util.Collection;
31  import java.util.HashMap;
32  import java.util.Map;
33  
34  /**
35   * A set of criteria for selecting a {@link ContextDefinition}.
36   * 
37   * @author Kuali Rice Team (rice.collab@kuali.org)
38   *
39   */
40  @XmlRootElement(name = ContextSelectionCriteria.Constants.ROOT_ELEMENT_NAME)
41  @XmlAccessorType(XmlAccessType.NONE)
42  @XmlType(name = ContextSelectionCriteria.Constants.TYPE_NAME, propOrder = {
43  		ContextSelectionCriteria.Elements.NAMESPACE_CODE,
44  		ContextSelectionCriteria.Elements.NAME,
45  		ContextSelectionCriteria.Elements.CONTEXT_QUALIFIERS,
46          CoreConstants.CommonElements.FUTURE_ELEMENTS
47  })
48  public final class ContextSelectionCriteria extends AbstractDataTransferObject {
49  
50  	@XmlElement(name = Elements.NAMESPACE_CODE, required = true)
51  	private final String namespaceCode;
52  	
53  	@XmlElement(name = Elements.NAME, required = false)
54  	private final String name;
55  	
56  	@XmlElement(name = Elements.CONTEXT_QUALIFIERS)
57  	@XmlJavaTypeAdapter(value = MapStringStringAdapter.class)
58  	private final Map<String, String> contextQualifiers;
59  	
60      @SuppressWarnings("unused")
61      @XmlAnyElement
62      private final Collection<Element> _futureElements = null;
63  	
64      /**
65       * Only used by JAXB.
66       */
67      @SuppressWarnings("unused")
68  	private ContextSelectionCriteria() {
69  		this.namespaceCode = null;
70  		this.name = null;
71  		this.contextQualifiers = null;
72  	}
73  
74      /**
75       * Private constructor used by factory methods
76       */
77      private ContextSelectionCriteria(String namespaceCode, String name, Map<String, String> contextQualifiers) {
78  		this.namespaceCode = namespaceCode;
79  		this.name = name;
80  		this.contextQualifiers = new HashMap<String, String>();
81  		if (contextQualifiers != null) {
82  			this.contextQualifiers.putAll(contextQualifiers);
83  		}
84  	}
85  	
86      /**
87       * Factory method returns a new context selection criteria object with the fields set to
88       * the parameters provided.
89       * @param namespaceCode the namespace of the context
90       * @param name the name of the context
91       * @param contextQualifiers a Map of name value pair strings representing the list of qualifiers
92       * to use as selection criteria.
93       */
94  	public static ContextSelectionCriteria newCriteria(String namespaceCode, String name, Map<String, String> contextQualifiers) {
95  		return new ContextSelectionCriteria(namespaceCode, name, contextQualifiers);
96  	}
97  	
98      /**
99       * Factory method returns a new context selection criteria object with the namespace and contextQualifiers fields
100      * set to the parameters provided. The name field is set to null.
101      * @param namespaceCode the namespace of the context
102      * @param contextQualifiers a Map of name value pair strings representing the list of qualifiers
103      * to use as selection criteria.
104      */
105 	public static ContextSelectionCriteria newCriteria(String namespaceCode, Map<String, String> contextQualifiers) {
106 		return newCriteria(namespaceCode, null, contextQualifiers);
107 	}
108 	
109     /**
110     * Factory method returns a new context selection criteria object with the contextQualifiers property
111     * set to the parameter provided. The name and namespace properties are set to null.
112     * @param contextQualifiers a Map of name value pair strings representing the list of qualifiers
113     * to use as selection criteria.
114     */
115 	public static ContextSelectionCriteria newCriteria(Map<String, String> contextQualifiers) {
116 		return newCriteria(null, contextQualifiers);
117 	}
118 
119     /**
120      * Returns the namespace of the context.
121      * @return the namespace code of the context
122      */
123 	public String getNamespaceCode() {
124 		return this.namespaceCode;
125 	}
126 
127     /**
128      * Returns the name of the context
129      * @return the name of the context
130      */
131 	public String getName() {
132 		return this.name;
133 	}
134 
135     /**
136      * Returns the list of qualifiers as a map to name, value pair strings.
137      * @return a map containing the qualifier name, value pairs.
138      */
139 	public Map<String, String> getContextQualifiers() {
140 		return this.contextQualifiers;
141 	}
142 	
143     /**
144      * Defines some internal constants used on this class.
145      */
146     static class Constants {
147         final static String ROOT_ELEMENT_NAME = "contextSelectionCriteria";
148         final static String TYPE_NAME = "ContextSelectionCriteriaType";
149     }
150     
151 	/**
152      * A private class which exposes constants which define the XML element names to use
153      * when this object is marshaled to XML.
154      */
155     static class Elements {
156         final static String NAMESPACE_CODE = "namespaceCode";
157         final static String NAME = "name";
158         final static String CONTEXT_QUALIFIERS = "contextQualifiers";
159     }
160 	
161 }