View Javadoc

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.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  	private ContextSelectionCriteria(String namespaceCode, String name, Map<String, String> contextQualifiers) {
75  		this.namespaceCode = namespaceCode;
76  		this.name = name;
77  		this.contextQualifiers = new HashMap<String, String>();
78  		if (contextQualifiers != null) {
79  			this.contextQualifiers.putAll(contextQualifiers);
80  		}
81  	}
82  	
83  	public static ContextSelectionCriteria newCriteria(String namespaceCode, String name, Map<String, String> contextQualifiers) {
84  		return new ContextSelectionCriteria(namespaceCode, name, contextQualifiers);
85  	}
86  	
87  	public static ContextSelectionCriteria newCriteria(String namespaceCode, Map<String, String> contextQualifiers) {
88  		return newCriteria(namespaceCode, null, contextQualifiers);
89  	}
90  	
91  	public static ContextSelectionCriteria newCriteria(Map<String, String> contextQualifiers) {
92  		return newCriteria(null, contextQualifiers);
93  	}
94  	
95  	public String getNamespaceCode() {
96  		return this.namespaceCode;
97  	}
98  
99  	public String getName() {
100 		return this.name;
101 	}
102 
103 	public Map<String, String> getContextQualifiers() {
104 		return this.contextQualifiers;
105 	}
106 	
107     /**
108      * Defines some internal constants used on this class.
109      */
110     static class Constants {
111         final static String ROOT_ELEMENT_NAME = "contextSelectionCriteria";
112         final static String TYPE_NAME = "ContextSelectionCriteriaType";
113     }
114     
115 	/**
116      * A private class which exposes constants which define the XML element names to use
117      * when this object is marshaled to XML.
118      */
119     static class Elements {
120         final static String NAMESPACE_CODE = "namespaceCode";
121         final static String NAME = "name";
122         final static String CONTEXT_QUALIFIERS = "contextQualifiers";
123     }
124 	
125 }