Coverage Report - org.kuali.rice.krms.api.repository.type.KrmsTypeDefinition
 
Classes in this File Line Coverage Branch Coverage Complexity
KrmsTypeDefinition
0%
0/27
N/A
1.276
KrmsTypeDefinition$1
N/A
N/A
1.276
KrmsTypeDefinition$Builder
0%
0/55
0%
0/10
1.276
KrmsTypeDefinition$Constants
0%
0/1
N/A
1.276
KrmsTypeDefinition$Elements
0%
0/1
N/A
1.276
 
 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.krms.api.repository.type;
 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.kuali.rice.core.api.mo.ModelObjectUtils;
 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.ArrayList;
 32  
 import java.util.Collection;
 33  
 import java.util.List;
 34  
 
 35  
 /**
 36  
  * Concrete model object implementation of KRMS KrmsType.
 37  
  * immutable.
 38  
  * Instances of KrmsType can be (un)marshalled to and from XML.
 39  
  *
 40  
  * @see KrmsTypeDefinitionContract
 41  
  */
 42  
 @XmlRootElement(name = KrmsTypeDefinition.Constants.ROOT_ELEMENT_NAME)
 43  
 @XmlAccessorType(XmlAccessType.NONE)
 44  
 @XmlType(name = KrmsTypeDefinition.Constants.TYPE_NAME, propOrder = {
 45  
                 KrmsTypeDefinition.Elements.ID,
 46  
                 KrmsTypeDefinition.Elements.NAME,
 47  
                 KrmsTypeDefinition.Elements.NAMESPACE,
 48  
                 KrmsTypeDefinition.Elements.SERVICENAME,
 49  
                 KrmsTypeDefinition.Elements.ACTIVE,
 50  
                 KrmsTypeDefinition.Elements.ATTRIBUTES,
 51  
         CoreConstants.CommonElements.VERSION_NUMBER,
 52  
                 CoreConstants.CommonElements.FUTURE_ELEMENTS
 53  
 })
 54  0
 public final class KrmsTypeDefinition extends AbstractDataTransferObject implements KrmsTypeDefinitionContract{
 55  
         private static final long serialVersionUID = -8314397393380856301L;
 56  
 
 57  
         @XmlElement(name = Elements.ID, required = false)
 58  
         private String id;
 59  
         @XmlElement(name = Elements.NAME, required = true)
 60  
         private String name;
 61  
         @XmlElement(name = Elements.NAMESPACE, required = true)
 62  
         private String namespace;
 63  
         @XmlElement(name = Elements.SERVICENAME, required = false)
 64  
         private String serviceName;
 65  
         @XmlElement(name = Elements.ACTIVE, required = false)
 66  
         private boolean active;
 67  
         @XmlElement(name = Elements.ATTRIBUTE, required = false)
 68  
         private List<KrmsTypeAttribute> attributes;
 69  
     @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
 70  
     private final Long versionNumber;
 71  
 
 72  0
         @SuppressWarnings("unused")
 73  
     @XmlAnyElement
 74  
     private final Collection<org.w3c.dom.Element> _futureElements = null;
 75  
 
 76  
          /**
 77  
      * This constructor should never be called.  It is only present for use during JAXB unmarshalling.
 78  
      */
 79  0
     private KrmsTypeDefinition() {
 80  0
             this.id = null;
 81  0
             this.name = null;
 82  0
             this.namespace = null;
 83  0
             this.serviceName = null;
 84  0
             this.active = false;
 85  0
             this.attributes = null;
 86  0
         this.versionNumber = null;
 87  0
     }
 88  
 
 89  
     /**
 90  
          * Constructs a KRMS KrmsType from the given builder.  This constructor is private and should only
 91  
          * ever be invoked from the builder.
 92  
          *
 93  
          * @param builder the Builder from which to construct the KRMS type
 94  
          */
 95  0
     private KrmsTypeDefinition(Builder builder) {
 96  0
         this.id = builder.getId();
 97  0
         this.name = builder.getName();
 98  0
         this.namespace = builder.getNamespace();
 99  0
         this.serviceName = builder.getServiceName();
 100  0
         this.active = builder.isActive();
 101  0
         this.attributes = ModelObjectUtils.buildImmutableCopy(builder.attributes);
 102  0
         this.versionNumber = builder.getVersionNumber();
 103  0
     }
 104  
 
 105  
         @Override
 106  
         public String getId() {
 107  0
                 return this.id;
 108  
         }
 109  
 
 110  
         @Override
 111  
         public String getName() {
 112  0
                 return this.name;
 113  
         }
 114  
 
 115  
         @Override
 116  
         public String getNamespace() {
 117  0
                 return this.namespace;
 118  
         }
 119  
 
 120  
         @Override
 121  
         public String getServiceName() {
 122  0
                 return this.serviceName;
 123  
         }
 124  
 
 125  
         @Override
 126  
         public boolean isActive() {
 127  0
                 return this.active;
 128  
         }
 129  
 
 130  
         @Override
 131  
         public List<KrmsTypeAttribute> getAttributes() {
 132  0
                 return this.attributes;
 133  
         }
 134  
 
 135  
     @Override
 136  
     public Long getVersionNumber() {
 137  0
         return versionNumber;
 138  
     }
 139  
 
 140  
         /**
 141  
      * This builder is used to construct instances of KRMS KrmsType.  It enforces the constraints of the {@link KrmsTypeDefinitionContract}.
 142  
      */
 143  0
     public static class Builder implements KrmsTypeDefinitionContract, ModelBuilder, Serializable {
 144  
                 private static final long serialVersionUID = -3469525730879441547L;
 145  
 
 146  
                 private String id;
 147  
         private String name;
 148  
         private String namespace;
 149  0
         private String serviceName = "";
 150  
         private boolean active;
 151  
         private List<KrmsTypeAttribute.Builder> attributes;
 152  
         private Long versionNumber;
 153  
 
 154  
                 /**
 155  
                  * Private constructor for creating a builder with all of it's required attributes.
 156  
                  */
 157  0
         private Builder(String name, String namespace) {
 158  0
             setName(name);
 159  0
             setNamespace(namespace);
 160  0
                         setActive(true);
 161  0
             setAttributes(new ArrayList<KrmsTypeAttribute.Builder>());
 162  0
         }
 163  
 
 164  
         public Builder serviceName(String serviceName){
 165  0
                 this.serviceName = serviceName;
 166  0
                 return this;
 167  
         }
 168  
 
 169  
         public Builder attributes(List<KrmsTypeAttribute.Builder> attributes){
 170  0
                 setAttributes(attributes);
 171  0
                 return this;
 172  
         }
 173  
 
 174  
         /**
 175  
          * Creates a builder from the given parameters.
 176  
          *
 177  
          * @param name the KRMS type name
 178  
          * @param namespace the KRMS type namespace
 179  
          * @return an instance of the builder with the fields already populated
 180  
          * @throws IllegalArgumentException if the either the id, name or namespace is null or blank
 181  
          */
 182  
         public static Builder create(String name, String namespace) {
 183  0
             return new Builder(name, namespace);
 184  
         }
 185  
 
 186  
         /**
 187  
          * Creates a builder by populating it with data from the given {@link KrmsTypeDefinitionContract}.
 188  
          *
 189  
          * @param contract the contract from which to populate this builder
 190  
          * @return an instance of the builder populated with data from the contract
 191  
          */
 192  
         public static Builder create(KrmsTypeDefinitionContract contract) {
 193  0
                 if (contract == null) {
 194  0
                 throw new IllegalArgumentException("contract is null");
 195  
             }
 196  0
             Builder builder =  new Builder(contract.getName(), contract.getNamespace());
 197  0
             builder.setId(contract.getId());
 198  0
             builder.setNamespace(contract.getNamespace());
 199  0
             builder.setActive(contract.isActive());
 200  0
             builder.setServiceName(contract.getServiceName());
 201  0
             List <KrmsTypeAttribute.Builder> attrBuilderList = new ArrayList<KrmsTypeAttribute.Builder>();
 202  0
             if (contract.getAttributes() != null) {
 203  0
                     for(KrmsTypeAttributeContract attr : contract.getAttributes()){
 204  0
                             KrmsTypeAttribute.Builder myBuilder =
 205  
                                     KrmsTypeAttribute.Builder.create(attr);
 206  0
                             attrBuilderList.add(myBuilder);
 207  0
                     }
 208  
             }
 209  0
             builder.setAttributes(attrBuilderList);
 210  0
             builder.setVersionNumber(contract.getVersionNumber());
 211  0
             return builder;
 212  
         }
 213  
 
 214  
                 /**
 215  
                  * Sets the value of the id on this builder to the given value.
 216  
                  *
 217  
                  * @param id the id value to set
 218  
                  */
 219  
         public void setId(String id) {
 220  0
             this.id = id;
 221  0
         }
 222  
 
 223  
                 public void setName(String name) {
 224  0
             if (StringUtils.isBlank(name)) {
 225  0
                 throw new IllegalArgumentException("name is blank");
 226  
             }
 227  0
                         this.name = name;
 228  0
                 }
 229  
 
 230  
                 public void setNamespace(String namespace) {
 231  0
             if (StringUtils.isBlank(namespace)) {
 232  0
                 throw new IllegalArgumentException("namespace is blank");
 233  
             }
 234  0
                         this.namespace = namespace;
 235  0
                 }
 236  
 
 237  
                 public void setServiceName(String serviceName) {
 238  0
                         this.serviceName = serviceName;
 239  0
                 }
 240  
 
 241  
                 public void setAttributes(List<KrmsTypeAttribute.Builder> attributes){
 242  0
                         this.attributes = attributes;
 243  0
                 }
 244  
 
 245  
                 public void setActive(boolean active) {
 246  0
                         this.active = active;
 247  0
                 }
 248  
 
 249  
         public void setVersionNumber(Long versionNumber){
 250  0
             this.versionNumber = versionNumber;
 251  0
         }
 252  
 
 253  
                 @Override
 254  
                 public String getId() {
 255  0
                         return id;
 256  
                 }
 257  
 
 258  
                 @Override
 259  
                 public String getName() {
 260  0
                         return name;
 261  
                 }
 262  
 
 263  
                 @Override
 264  
                 public String getNamespace() {
 265  0
                         return namespace;
 266  
                 }
 267  
 
 268  
                 @Override
 269  
                 public String getServiceName() {
 270  0
                         return serviceName;
 271  
                 }
 272  
 
 273  
                 @Override
 274  
                 public List<KrmsTypeAttribute.Builder> getAttributes(){
 275  0
                         return attributes;
 276  
                 }
 277  
 
 278  
                 @Override
 279  
                 public boolean isActive() {
 280  0
                         return active;
 281  
                 }
 282  
 
 283  
         @Override
 284  
         public Long getVersionNumber() {
 285  0
             return versionNumber;
 286  
         }
 287  
 
 288  
                 /**
 289  
                  * Builds an instance of a KrmsType based on the current state of the builder.
 290  
                  *
 291  
                  * @return the fully-constructed KrmsType
 292  
                  */
 293  
         @Override
 294  
         public KrmsTypeDefinition build() {
 295  0
             return new KrmsTypeDefinition(this);
 296  
         }
 297  
 
 298  
     }
 299  
 
 300  
         /**
 301  
          * Defines some internal constants used on this class.
 302  
          */
 303  0
         static class Constants {
 304  
                 final static String ROOT_ELEMENT_NAME = "KRMSType";
 305  
                 final static String TYPE_NAME = "KRMSTypeType";
 306  
         }
 307  
 
 308  
         /**
 309  
          * A private class which exposes constants which define the XML element names to use
 310  
          * when this object is marshalled to XML.
 311  
          */
 312  0
         public static class Elements {
 313  
                 final static String ID = "id";
 314  
                 final static String NAME = "name";
 315  
                 final static String NAMESPACE = "namespace";
 316  
                 final static String SERVICENAME = "serviceName";
 317  
                 final static String ACTIVE = "active";
 318  
                 final static String ATTRIBUTE = "attribute";
 319  
                 final static String ATTRIBUTES = "attributes";
 320  
         }
 321  
 }