001 /** 002 * Copyright 2005-2011 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 */ 016 package org.kuali.rice.kim.api.identity.principal; 017 018 import org.kuali.rice.core.api.CoreConstants; 019 import org.kuali.rice.core.api.mo.AbstractDataTransferObject; 020 import org.kuali.rice.core.api.mo.ModelBuilder; 021 import org.kuali.rice.kim.api.identity.name.EntityName; 022 import org.w3c.dom.Element; 023 024 import javax.xml.bind.annotation.XmlAccessType; 025 import javax.xml.bind.annotation.XmlAccessorType; 026 import javax.xml.bind.annotation.XmlAnyElement; 027 import javax.xml.bind.annotation.XmlElement; 028 import javax.xml.bind.annotation.XmlRootElement; 029 import javax.xml.bind.annotation.XmlType; 030 import java.io.Serializable; 031 import java.util.Collection; 032 033 @XmlRootElement(name = EntityNamePrincipalName.Constants.ROOT_ELEMENT_NAME) 034 @XmlAccessorType(XmlAccessType.NONE) 035 @XmlType(name = EntityNamePrincipalName.Constants.TYPE_NAME, propOrder = { 036 EntityNamePrincipalName.Elements.DEFAULT_NAME, 037 EntityNamePrincipalName.Elements.PRINCIPAL_NAME, 038 CoreConstants.CommonElements.FUTURE_ELEMENTS 039 }) 040 public class EntityNamePrincipalName extends AbstractDataTransferObject { 041 @XmlElement(name = Elements.PRINCIPAL_NAME, required = false) 042 private final String principalName; 043 @XmlElement(name = Elements.DEFAULT_NAME, required = false) 044 private final EntityName defaultName; 045 @SuppressWarnings("unused") 046 @XmlAnyElement 047 private final Collection<Element> _futureElements = null; 048 049 050 private EntityNamePrincipalName() { 051 this.principalName = null; 052 this.defaultName = null; 053 } 054 055 private EntityNamePrincipalName(Builder builder) { 056 this.principalName = builder.getPrincipalName(); 057 this.defaultName = builder.getDefaultName() == null ? null : builder.getDefaultName().build(); 058 } 059 060 public String getPrincipalName() { 061 return principalName; 062 } 063 064 public EntityName getDefaultName() { 065 return defaultName; 066 } 067 /** 068 * A builder which can be used to construct {@link EntityDefault} instances. 069 * 070 */ 071 public final static class Builder 072 implements Serializable, ModelBuilder 073 { 074 private String principalName; 075 private EntityName.Builder defaultName; 076 077 public static Builder create() { 078 return new Builder(); 079 } 080 081 public static Builder create(String principalName, EntityName.Builder defaultName) { 082 Builder builder = new Builder(); 083 builder.setPrincipalName(principalName); 084 builder.setDefaultName(defaultName); 085 return builder; 086 } 087 088 public static Builder create(EntityNamePrincipalName immutable) { 089 if (immutable == null) { 090 throw new IllegalArgumentException("contract was null"); 091 } 092 Builder builder = new Builder(); 093 if (immutable.getDefaultName() != null) { 094 builder.setDefaultName(EntityName.Builder.create(immutable.getDefaultName())); 095 } 096 return builder; 097 } 098 099 public String getPrincipalName() { 100 return principalName; 101 } 102 103 public void setPrincipalName(String principalName) { 104 this.principalName = principalName; 105 } 106 107 public EntityName.Builder getDefaultName() { 108 return defaultName; 109 } 110 111 public void setDefaultName(EntityName.Builder defaultName) { 112 this.defaultName = defaultName; 113 } 114 115 public EntityNamePrincipalName build() { 116 return new EntityNamePrincipalName(this); 117 } 118 119 } 120 121 /** 122 * Defines some internal constants used on this class. 123 * 124 */ 125 static class Constants { 126 127 final static String ROOT_ELEMENT_NAME = "entityNamePrincipalName"; 128 final static String TYPE_NAME = "EntityNamePrincipalNameType"; 129 } 130 131 132 /** 133 * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML. 134 * 135 */ 136 static class Elements { 137 final static String DEFAULT_NAME = "defaultName"; 138 final static String PRINCIPAL_NAME = "principalName"; 139 } 140 141 }