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