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.kim.api.identity.principal;
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.mo.ModelBuilder;
21  import org.kuali.rice.kim.api.identity.name.EntityName;
22  import org.kuali.rice.kim.api.KimConstants;
23  import org.w3c.dom.Element;
24  
25  import javax.xml.bind.annotation.XmlAccessType;
26  import javax.xml.bind.annotation.XmlAccessorType;
27  import javax.xml.bind.annotation.XmlAnyElement;
28  import javax.xml.bind.annotation.XmlElement;
29  import javax.xml.bind.annotation.XmlRootElement;
30  import javax.xml.bind.annotation.XmlType;
31  import java.io.Serializable;
32  import java.util.Collection;
33  
34  @XmlRootElement(name = EntityNamePrincipalName.Constants.ROOT_ELEMENT_NAME)
35  @XmlAccessorType(XmlAccessType.NONE)
36  @XmlType(name = EntityNamePrincipalName.Constants.TYPE_NAME, propOrder = {
37      EntityNamePrincipalName.Elements.DEFAULT_NAME,
38      EntityNamePrincipalName.Elements.PRINCIPAL_NAME,
39      CoreConstants.CommonElements.FUTURE_ELEMENTS
40  })
41  public class EntityNamePrincipalName extends AbstractDataTransferObject {
42      @XmlElement(name = Elements.PRINCIPAL_NAME, required = false)
43      private final String principalName;
44      @XmlElement(name = Elements.DEFAULT_NAME, required = false)
45      private final EntityName defaultName;
46      @SuppressWarnings("unused")
47      @XmlAnyElement
48      private final Collection<Element> _futureElements = null;
49  
50  
51      private EntityNamePrincipalName() {
52          this.principalName = null;
53          this.defaultName = null;
54      }
55  
56      private EntityNamePrincipalName(Builder builder) {
57          this.principalName = builder.getPrincipalName();
58          this.defaultName = builder.getDefaultName() == null ? null : builder.getDefaultName().build();
59      }
60  
61      public String getPrincipalName() {
62          return principalName;
63      }
64  
65      public EntityName getDefaultName() {
66          return defaultName;
67      }
68      /**
69       * A builder which can be used to construct {@link EntityDefault} instances.
70       *
71       */
72      public final static class Builder
73          implements Serializable, ModelBuilder
74      {
75          private String principalName;
76          private EntityName.Builder defaultName;
77  
78          public static Builder create() {
79              return new Builder();
80          }
81  
82          public static Builder create(String principalName, EntityName.Builder defaultName) {
83              Builder builder = new Builder();
84              builder.setPrincipalName(principalName);
85              builder.setDefaultName(defaultName);
86              return builder;
87          }
88  
89          public static Builder create(EntityNamePrincipalName immutable) {
90              if (immutable == null) {
91                  throw new IllegalArgumentException("contract was null");
92              }
93              Builder builder = new Builder();
94              if (immutable.getDefaultName() != null) {
95                  builder.setDefaultName(EntityName.Builder.create(immutable.getDefaultName()));
96              }
97              return builder;
98          }
99  
100         public String getPrincipalName() {
101             return principalName;
102         }
103 
104         public void setPrincipalName(String principalName) {
105             this.principalName = principalName;
106         }
107 
108         public EntityName.Builder getDefaultName() {
109             return defaultName;
110         }
111 
112         public void setDefaultName(EntityName.Builder defaultName) {
113             this.defaultName = defaultName;
114         }
115 
116         public EntityNamePrincipalName build() {
117             return new EntityNamePrincipalName(this);
118         }
119 
120     }
121 
122     /**
123      * Defines some internal constants used on this class.
124      *
125      */
126     static class Constants {
127 
128         final static String ROOT_ELEMENT_NAME = "entityNamePrincipalName";
129         final static String TYPE_NAME = "EntityNamePrincipalNameType";
130     }
131 
132 
133     /**
134      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
135      *
136      */
137     static class Elements {
138         final static String DEFAULT_NAME = "defaultName";
139         final static String PRINCIPAL_NAME = "principalName";
140     }
141 
142     public static class Cache {
143     	public final static String NAME = KimConstants.Namespaces.KIM_NAMESPACE_2_0 + "/" + EntityNamePrincipalName.Constants.TYPE_NAME;
144     }
145 }