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