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