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