001/** 002 * Copyright 2005-2014 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.kim.api.identity.principal; 017 018import org.kuali.rice.core.api.CoreConstants; 019import org.kuali.rice.core.api.mo.AbstractDataTransferObject; 020import org.kuali.rice.core.api.mo.ModelBuilder; 021import org.kuali.rice.kim.api.identity.name.EntityName; 022import org.kuali.rice.kim.api.KimConstants; 023import org.w3c.dom.Element; 024 025import javax.xml.bind.annotation.XmlAccessType; 026import javax.xml.bind.annotation.XmlAccessorType; 027import javax.xml.bind.annotation.XmlAnyElement; 028import javax.xml.bind.annotation.XmlElement; 029import javax.xml.bind.annotation.XmlRootElement; 030import javax.xml.bind.annotation.XmlType; 031import java.io.Serializable; 032import java.util.Collection; 033 034@XmlRootElement(name = EntityNamePrincipalName.Constants.ROOT_ELEMENT_NAME) 035@XmlAccessorType(XmlAccessType.NONE) 036@XmlType(name = EntityNamePrincipalName.Constants.TYPE_NAME, propOrder = { 037 EntityNamePrincipalName.Elements.DEFAULT_NAME, 038 EntityNamePrincipalName.Elements.PRINCIPAL_NAME, 039 CoreConstants.CommonElements.FUTURE_ELEMENTS 040}) 041public class EntityNamePrincipalName extends AbstractDataTransferObject { 042 @XmlElement(name = Elements.PRINCIPAL_NAME, required = false) 043 private final String principalName; 044 @XmlElement(name = Elements.DEFAULT_NAME, required = false) 045 private final EntityName defaultName; 046 @SuppressWarnings("unused") 047 @XmlAnyElement 048 private final Collection<Element> _futureElements = null; 049 050 051 private EntityNamePrincipalName() { 052 this.principalName = null; 053 this.defaultName = null; 054 } 055 056 private EntityNamePrincipalName(Builder builder) { 057 this.principalName = builder.getPrincipalName(); 058 this.defaultName = builder.getDefaultName() == null ? null : builder.getDefaultName().build(); 059 } 060 061 public String getPrincipalName() { 062 return principalName; 063 } 064 065 public EntityName getDefaultName() { 066 return defaultName; 067 } 068 /** 069 * A builder which can be used to construct {@link EntityDefault} instances. 070 * 071 */ 072 public final static class Builder 073 implements Serializable, ModelBuilder 074 { 075 private String principalName; 076 private EntityName.Builder defaultName; 077 078 public static Builder create() { 079 return new Builder(); 080 } 081 082 public static Builder create(String principalName, EntityName.Builder defaultName) { 083 Builder builder = new Builder(); 084 builder.setPrincipalName(principalName); 085 builder.setDefaultName(defaultName); 086 return builder; 087 } 088 089 public static Builder create(EntityNamePrincipalName immutable) { 090 if (immutable == null) { 091 throw new IllegalArgumentException("contract was null"); 092 } 093 Builder builder = new Builder(); 094 if (immutable.getDefaultName() != null) { 095 builder.setDefaultName(EntityName.Builder.create(immutable.getDefaultName())); 096 } 097 return builder; 098 } 099 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}