Coverage Report - org.kuali.rice.location.api.campus.CampusType
 
Classes in this File Line Coverage Branch Coverage Complexity
CampusType
100%
21/21
N/A
1.19
CampusType$1
N/A
N/A
1.19
CampusType$Builder
100%
32/32
100%
4/4
1.19
CampusType$Cache
0%
0/1
N/A
1.19
CampusType$Constants
0%
0/1
N/A
1.19
CampusType$Elements
0%
0/1
N/A
1.19
 
 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.location.api.campus;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.core.api.CoreConstants;
 20  
 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
 21  
 import org.kuali.rice.core.api.mo.ModelBuilder;
 22  
 import org.kuali.rice.location.api.LocationConstants;
 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  
 /**
 35  
  * An immutable representation of a {@link CampusTypeContract}.
 36  
  *
 37  
  * <p>To construct an instance of a CampusType, use the {@link CampusType.Builder} class.
 38  
  *
 39  
  * @see CampusTypeContract
 40  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 41  
  */
 42  
 @XmlRootElement(name = CampusType.Constants.ROOT_ELEMENT_NAME)
 43  
 @XmlAccessorType(XmlAccessType.NONE)
 44  
 @XmlType(name = CampusType.Constants.TYPE_NAME, propOrder = {
 45  
                 CampusType.Elements.CODE,
 46  
                 CampusType.Elements.NAME,
 47  
                 CampusType.Elements.ACTIVE,
 48  
         CoreConstants.CommonElements.VERSION_NUMBER,
 49  
         CoreConstants.CommonElements.OBJECT_ID,
 50  
                 CoreConstants.CommonElements.FUTURE_ELEMENTS
 51  
 })
 52  10
 public final class CampusType extends AbstractDataTransferObject implements CampusTypeContract {
 53  
         private static final long serialVersionUID = -6325716665728047946L;
 54  
 
 55  
         @XmlElement(name = Elements.CODE, required=true)
 56  
         private final String code;
 57  
 
 58  
     @XmlElement(name = Elements.NAME, required=false)
 59  
         private final String name;
 60  
 
 61  
         @XmlElement(name = Elements.ACTIVE, required=false)
 62  
         private final boolean active;
 63  
 
 64  
     @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
 65  
     private final Long versionNumber;
 66  
 
 67  
     @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
 68  
         private final String objectId;
 69  
     
 70  16
         @SuppressWarnings("unused")
 71  
     @XmlAnyElement
 72  
     private final Collection<Element> _futureElements = null;
 73  
         
 74  
          /** 
 75  
      * This constructor should never be called.  It is only present for use during JAXB unmarshalling. 
 76  
      */
 77  6
     private CampusType() {
 78  6
             this.code = null;
 79  6
             this.name = null;
 80  6
             this.active = false;
 81  6
         this.versionNumber = null;
 82  6
         this.objectId = null;
 83  6
     }
 84  
     
 85  
     /**
 86  
          * Constructs a CampusType from the given builder.  This constructor is private and should only
 87  
          * ever be invoked from the builder.
 88  
          * 
 89  
          * @param builder the Builder from which to construct the campus type
 90  
          */
 91  10
     private CampusType(Builder builder) {
 92  10
         this.code = builder.getCode();
 93  10
         this.name = builder.getName();
 94  10
         this.active = builder.isActive();
 95  10
         this.versionNumber = builder.getVersionNumber();
 96  10
         this.objectId = builder.getObjectId();
 97  10
     }
 98  
     
 99  
         /** {@inheritDoc} */
 100  
         @Override
 101  
         public String getCode() {
 102  4
                 return this.code;
 103  
         }
 104  
 
 105  
         /** {@inheritDoc} */
 106  
         @Override
 107  
         public String getName() {
 108  4
                 return this.name;
 109  
         }
 110  
 
 111  
         /** {@inheritDoc} */
 112  
         @Override
 113  
         public boolean isActive() {
 114  4
                 return this.active; 
 115  
         }
 116  
 
 117  
     /** {@inheritDoc} */
 118  
     @Override
 119  
     public Long getVersionNumber() {
 120  4
         return this.versionNumber;
 121  
     }
 122  
     
 123  
     /** {@inheritDoc} */
 124  
     @Override
 125  
         public String getObjectId() {
 126  4
                 return objectId;
 127  
         }
 128  
 
 129  
         /**
 130  
      * This builder is used to construct instances of CampusType.  It enforces the constraints of the {@link CampusTypeContract}.
 131  
      */
 132  8
     public static class Builder implements CampusTypeContract, ModelBuilder, Serializable {
 133  
                 private static final long serialVersionUID = 1807428861457935238L;
 134  
                 
 135  
                 private String code;
 136  
         private String name;
 137  
         private boolean active;
 138  
         private Long versionNumber;
 139  
         private String objectId;
 140  
 
 141  
                 /**
 142  
                  * Private constructor for creating a builder with all of it's required attributes.
 143  
                  */
 144  12
         private Builder(String code) {
 145  12
             setCode(code);
 146  11
                         setActive(true);
 147  11
         }
 148  
 
 149  
         /**
 150  
          * Creates a builder from the given campus type code.
 151  
          * 
 152  
          * @param code the campus type code
 153  
          * @return an instance of the builder with the code already populated
 154  
          * @throws IllegalArgumentException if the code is null or blank
 155  
          */
 156  
         public static Builder create(String code) {
 157  3
             return new Builder(code);
 158  
         }
 159  
 
 160  
         /**
 161  
          * Creates a builder by populating it with data from the given {@link CampusTypeContract}.
 162  
          * 
 163  
          * @param contract the contract from which to populate this builder
 164  
          * @return an instance of the builder populated with data from the contract
 165  
          */
 166  
         public static Builder create(CampusTypeContract contract) {
 167  10
                 if (contract == null) {
 168  1
                 throw new IllegalArgumentException("contract is null");
 169  
             }
 170  9
             Builder builder =  new Builder(contract.getCode());
 171  9
             builder.setName(contract.getName());
 172  9
             builder.setActive(contract.isActive());
 173  9
             builder.setVersionNumber(contract.getVersionNumber());
 174  9
             builder.setObjectId(contract.getObjectId());
 175  9
             return builder;
 176  
         }
 177  
 
 178  
                 /**
 179  
                  * Sets the value of the code on this builder to the given value.
 180  
                  * 
 181  
                  * @param code the code value to set, must not be null or blank
 182  
                  * @throws IllegalArgumentException if the code is null or blank
 183  
                  */
 184  
         public void setCode(String code) {
 185  12
             if (StringUtils.isBlank(code)) {
 186  1
                 throw new IllegalArgumentException("code is blank");
 187  
             }
 188  11
             this.code = code;
 189  11
         }
 190  
 
 191  
                 public void setName(String name) {
 192  9
                         this.name = name;
 193  9
                 }
 194  
 
 195  
                 public void setActive(boolean active) {
 196  20
                         this.active = active;
 197  20
                 }
 198  
 
 199  
         public void setVersionNumber(Long versionNumber) {
 200  9
             this.versionNumber = versionNumber;
 201  9
         }
 202  
         
 203  
         public void setObjectId(String objectId) {
 204  9
                 this.objectId = objectId;
 205  9
         }
 206  
 
 207  
                 @Override
 208  
                 public String getCode() {
 209  11
                         return code;
 210  
                 }
 211  
 
 212  
                 @Override
 213  
                 public String getName() {
 214  11
                         return name;
 215  
                 }
 216  
 
 217  
                 @Override
 218  
                 public boolean isActive() {
 219  11
                         return active;
 220  
                 }
 221  
 
 222  
         @Override
 223  
         public Long getVersionNumber() {
 224  11
             return versionNumber;
 225  
         }
 226  
         
 227  
         @Override
 228  
             public String getObjectId() {
 229  11
                     return objectId;
 230  
             }
 231  
 
 232  
                 /**
 233  
                  * Builds an instance of a CampusType based on the current state of the builder.
 234  
                  * 
 235  
                  * @return the fully-constructed CampusType
 236  
                  */
 237  
         @Override
 238  
         public CampusType build() {
 239  10
             return new CampusType(this);
 240  
         }
 241  
                 
 242  
     }
 243  
 
 244  
         /**
 245  
          * Defines some internal constants used on this class.
 246  
          */
 247  0
         static class Constants {
 248  
                 final static String ROOT_ELEMENT_NAME = "campusType";
 249  
                 final static String TYPE_NAME = "CampusTypeType";
 250  
         }
 251  
         
 252  
         /**
 253  
          * A private class which exposes constants which define the XML element names to use
 254  
          * when this object is marshalled to XML.
 255  
          */
 256  0
         static class Elements {
 257  
                 final static String CODE = "code";
 258  
                 final static String NAME = "name";
 259  
                 final static String ACTIVE = "active";
 260  
         }
 261  
 
 262  0
     public static class Cache {
 263  
         public static final String NAME = LocationConstants.Namespaces.LOCATION_NAMESPACE_2_0 + "/" + CampusType.Constants.TYPE_NAME;
 264  
     }
 265  
 }