001 /** 002 * Copyright 2005-2013 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.visa; 017 018 import java.io.Serializable; 019 import java.util.Collection; 020 import javax.xml.bind.annotation.XmlAccessType; 021 import javax.xml.bind.annotation.XmlAccessorType; 022 import javax.xml.bind.annotation.XmlAnyElement; 023 import javax.xml.bind.annotation.XmlElement; 024 import javax.xml.bind.annotation.XmlRootElement; 025 import javax.xml.bind.annotation.XmlType; 026 027 import org.apache.commons.lang.StringUtils; 028 import org.kuali.rice.core.api.CoreConstants; 029 import org.kuali.rice.core.api.mo.AbstractDataTransferObject; 030 import org.kuali.rice.core.api.mo.ModelBuilder; 031 import org.w3c.dom.Element; 032 033 @XmlRootElement(name = EntityVisa.Constants.ROOT_ELEMENT_NAME) 034 @XmlAccessorType(XmlAccessType.NONE) 035 @XmlType(name = EntityVisa.Constants.TYPE_NAME, propOrder = { 036 EntityVisa.Elements.ID, 037 EntityVisa.Elements.ENTITY_ID, 038 EntityVisa.Elements.VISA_TYPE_KEY, 039 EntityVisa.Elements.VISA_ENTRY, 040 EntityVisa.Elements.VISA_ID, 041 CoreConstants.CommonElements.VERSION_NUMBER, 042 CoreConstants.CommonElements.OBJECT_ID, 043 CoreConstants.CommonElements.FUTURE_ELEMENTS 044 }) 045 public final class EntityVisa extends AbstractDataTransferObject 046 implements EntityVisaContract 047 { 048 049 @XmlElement(name = Elements.ENTITY_ID, required = false) 050 private final String entityId; 051 @XmlElement(name = Elements.VISA_TYPE_KEY, required = false) 052 private final String visaTypeKey; 053 @XmlElement(name = Elements.VISA_ENTRY, required = false) 054 private final String visaEntry; 055 @XmlElement(name = Elements.VISA_ID, required = false) 056 private final String visaId; 057 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false) 058 private final Long versionNumber; 059 @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false) 060 private final String objectId; 061 @XmlElement(name = Elements.ID, required = false) 062 private final String id; 063 @SuppressWarnings("unused") 064 @XmlAnyElement 065 private final Collection<Element> _futureElements = null; 066 067 /** 068 * Private constructor used only by JAXB. 069 * 070 */ 071 private EntityVisa() { 072 this.entityId = null; 073 this.visaTypeKey = null; 074 this.visaEntry = null; 075 this.visaId = null; 076 this.versionNumber = null; 077 this.objectId = null; 078 this.id = null; 079 } 080 081 private EntityVisa(Builder builder) { 082 this.entityId = builder.getEntityId(); 083 this.visaTypeKey = builder.getVisaTypeKey(); 084 this.visaEntry = builder.getVisaEntry(); 085 this.visaId = builder.getVisaId(); 086 this.versionNumber = builder.getVersionNumber(); 087 this.objectId = builder.getObjectId(); 088 this.id = builder.getId(); 089 } 090 091 @Override 092 public String getEntityId() { 093 return this.entityId; 094 } 095 096 @Override 097 public String getVisaTypeKey() { 098 return this.visaTypeKey; 099 } 100 101 @Override 102 public String getVisaEntry() { 103 return this.visaEntry; 104 } 105 106 @Override 107 public String getVisaId() { 108 return this.visaId; 109 } 110 111 @Override 112 public Long getVersionNumber() { 113 return this.versionNumber; 114 } 115 116 @Override 117 public String getObjectId() { 118 return this.objectId; 119 } 120 121 @Override 122 public String getId() { 123 return this.id; 124 } 125 126 127 128 /** 129 * A builder which can be used to construct {@link EntityVisa} instances. Enforces the constraints of the {@link EntityVisaContract}. 130 * 131 */ 132 public final static class Builder 133 implements Serializable, ModelBuilder, EntityVisaContract 134 { 135 136 private String entityId; 137 private String visaTypeKey; 138 private String visaEntry; 139 private String visaId; 140 private Long versionNumber; 141 private String objectId; 142 private String id; 143 144 private Builder() { } 145 146 public static Builder create() { 147 return new Builder(); 148 } 149 150 public static Builder create(EntityVisaContract contract) { 151 if (contract == null) { 152 throw new IllegalArgumentException("contract was null"); 153 } 154 Builder builder = create(); 155 builder.setEntityId(contract.getEntityId()); 156 builder.setVisaTypeKey(contract.getVisaTypeKey()); 157 builder.setVisaEntry(contract.getVisaEntry()); 158 builder.setVisaId(contract.getVisaId()); 159 builder.setVersionNumber(contract.getVersionNumber()); 160 builder.setObjectId(contract.getObjectId()); 161 builder.setId(contract.getId()); 162 return builder; 163 } 164 165 public EntityVisa build() { 166 return new EntityVisa(this); 167 } 168 169 @Override 170 public String getEntityId() { 171 return this.entityId; 172 } 173 174 @Override 175 public String getVisaTypeKey() { 176 return this.visaTypeKey; 177 } 178 179 @Override 180 public String getVisaEntry() { 181 return this.visaEntry; 182 } 183 184 @Override 185 public String getVisaId() { 186 return this.visaId; 187 } 188 189 @Override 190 public Long getVersionNumber() { 191 return this.versionNumber; 192 } 193 194 @Override 195 public String getObjectId() { 196 return this.objectId; 197 } 198 199 @Override 200 public String getId() { 201 return this.id; 202 } 203 204 public void setEntityId(String entityId) { 205 this.entityId = entityId; 206 } 207 208 public void setVisaTypeKey(String visaTypeKey) { 209 this.visaTypeKey = visaTypeKey; 210 } 211 212 public void setVisaEntry(String visaEntry) { 213 this.visaEntry = visaEntry; 214 } 215 216 public void setVisaId(String visaId) { 217 this.visaId = visaId; 218 } 219 220 public void setVersionNumber(Long versionNumber) { 221 this.versionNumber = versionNumber; 222 } 223 224 public void setObjectId(String objectId) { 225 this.objectId = objectId; 226 } 227 228 public void setId(String id) { 229 if (StringUtils.isWhitespace(id)) { 230 throw new IllegalArgumentException("id is blank"); 231 } 232 this.id = id; 233 } 234 235 } 236 237 238 /** 239 * Defines some internal constants used on this class. 240 * 241 */ 242 static class Constants { 243 244 final static String ROOT_ELEMENT_NAME = "entityVisa"; 245 final static String TYPE_NAME = "EntityVisaType"; 246 } 247 248 249 /** 250 * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML. 251 * 252 */ 253 static class Elements { 254 255 final static String ENTITY_ID = "entityId"; 256 final static String VISA_TYPE_KEY = "visaTypeKey"; 257 final static String VISA_ENTRY = "visaEntry"; 258 final static String VISA_ID = "visaId"; 259 final static String ID = "id"; 260 261 } 262 263 }