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