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