Coverage Report - org.kuali.rice.krms.api.repository.category.CategoryDefinition
 
Classes in this File Line Coverage Branch Coverage Complexity
CategoryDefinition
0%
0/18
N/A
1.5
CategoryDefinition$1
N/A
N/A
1.5
CategoryDefinition$Builder
0%
0/31
0%
0/10
1.5
CategoryDefinition$Constants
0%
0/1
N/A
1.5
CategoryDefinition$Elements
0%
0/1
N/A
1.5
 
 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.category;
 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  
 @XmlRootElement(name = CategoryDefinition.Constants.ROOT_ELEMENT_NAME)
 34  
 @XmlAccessorType(XmlAccessType.NONE)
 35  
 @XmlType(name = CategoryDefinition.Constants.TYPE_NAME, propOrder = {
 36  
                 CategoryDefinition.Elements.ID,
 37  
                 CategoryDefinition.Elements.NAME,
 38  
                 CategoryDefinition.Elements.NAMESPACE,
 39  
         CoreConstants.CommonElements.VERSION_NUMBER,
 40  
                 CoreConstants.CommonElements.FUTURE_ELEMENTS
 41  
 })
 42  0
 public class CategoryDefinition extends AbstractDataTransferObject implements CategoryDefinitionContract {
 43  
 
 44  
     private static final long serialVersionUID = -4748818967880857017L;
 45  
 
 46  
     @XmlElement(name = Elements.ID, required=true)
 47  
     private final String id;
 48  
     @XmlElement(name = Elements.NAME, required=true)
 49  
     private final String name;
 50  
     @XmlElement(name = Elements.NAMESPACE, required=true)
 51  
     private final String namespace;
 52  
     @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
 53  
     private final Long versionNumber;
 54  
 
 55  0
     @SuppressWarnings("unused")
 56  
     @XmlAnyElement
 57  
     private final Collection<Element> _futureElements = null;
 58  
 
 59  
     /**
 60  
     * This constructor should never be called.  It is only present for use during JAXB unmarshalling.
 61  
     */
 62  0
    private CategoryDefinition() {
 63  0
        this.id = null;
 64  0
        this.name = null;
 65  0
        this.namespace = null;
 66  0
        this.versionNumber = null;
 67  0
    }
 68  
 
 69  
     /**
 70  
          * Constructs a CategoryDefinition from the given builder.  This constructor is private and should only
 71  
          * ever be invoked from the builder.
 72  
          *
 73  
          * @param builder the Builder from which to construct the CategoryDefinition
 74  
          */
 75  0
     private CategoryDefinition(Builder builder) {
 76  0
         this.id = builder.getId();
 77  0
         this.name = builder.getName();
 78  0
         this.namespace = builder.getNamespace();
 79  0
         this.versionNumber = builder.getVersionNumber();
 80  0
     }
 81  
 
 82  
         public String getId() {
 83  0
                 return this.id;
 84  
         }
 85  
 
 86  
         public String getName() {
 87  0
                 return this.name;
 88  
         }
 89  
 
 90  
         public String getNamespace() {
 91  0
                 return this.namespace;
 92  
         }
 93  
 
 94  
     @Override
 95  
     public Long getVersionNumber() {
 96  0
         return versionNumber;
 97  
     }
 98  
 
 99  
     /**
 100  
      * This builder is used to construct instances of CategoryDefinition.  It enforces the constraints of the {@link org.kuali.rice.krms.api.repository.category.CategoryDefinitionContract}.
 101  
      */
 102  0
     public static class Builder implements CategoryDefinitionContract, ModelBuilder, Serializable {
 103  
 
 104  
         private static final long serialVersionUID = -5775478956373560840L;
 105  
 
 106  
         private String id;
 107  
         private String name;
 108  
         private String namespace;
 109  
         private Long versionNumber;
 110  
 
 111  
         /**
 112  
          * Private constructor for creating a builder with all of it's required attributes.
 113  
          */
 114  0
         private Builder(String id, String name, String namespace) {
 115  0
             setId(id);
 116  0
             setName(name);
 117  0
             setNamespace(namespace);
 118  0
         }
 119  
 
 120  
         /**
 121  
          * Creates a builder from the given parameters.
 122  
          *
 123  
          * @param id the CategoryDefinition id
 124  
          * @param name the CategoryDefinition name
 125  
          * @param namespace the CategoryDefinition namespace
 126  
          * @return an instance of the builder with the fields already populated
 127  
          * @throws IllegalArgumentException if the either the id, name or namespace is null or blank
 128  
          */
 129  
         public static Builder create(String id, String name, String namespace) {
 130  0
             return new Builder(id, name, namespace);
 131  
         }
 132  
 
 133  
         /**
 134  
          * Creates a builder by populating it with data from the given {@link CategoryDefinition}.
 135  
          *
 136  
          * @param category the category from which to populate this builder
 137  
          * @return an instance of the builder populated with data from the contract
 138  
          */
 139  
         public static Builder create(CategoryDefinitionContract category) {
 140  0
             if (category == null) {
 141  0
                 throw new IllegalArgumentException("contract is null");
 142  
             }
 143  0
             Builder builder =  new Builder(category.getId(), category.getName(), category.getNamespace());
 144  0
             builder.setVersionNumber(category.getVersionNumber());
 145  0
             return builder;
 146  
         }
 147  
 
 148  
         /**
 149  
          * Sets the value of the id on this builder to the given value.
 150  
          *
 151  
          * @param id the id value to set, must be null or non-blank
 152  
          * @throws IllegalArgumentException if the id is non-null and blank
 153  
          */
 154  
         public void setId(String id) {
 155  0
             if (null != id && StringUtils.isBlank(id)) {
 156  0
                 throw new IllegalArgumentException("id must be null or non-blank");
 157  
             }
 158  0
             this.id = id;
 159  0
         }
 160  
 
 161  
         /**
 162  
          * Sets the name for the category definition that will be returned by this builder.
 163  
          * The name must not be null or blank.
 164  
          *
 165  
          * @param name the name to set on this builder, must not be null or blank
 166  
          *
 167  
          * @throws IllegalArgumentException if the given name is null or blank
 168  
          */
 169  
         public void setName(String name) {
 170  0
             if (StringUtils.isBlank(name)) {
 171  0
                 throw new IllegalArgumentException("name is blank");
 172  
             }
 173  0
             this.name = name;
 174  0
         }
 175  
 
 176  
         /**
 177  
          * Sets the namespace code for the category definition that will be returned by this builder.
 178  
          * The namespace must not be null or blank.
 179  
          *
 180  
          * @param namespace the namespace code to set on this builder, must not be null or blank
 181  
          *
 182  
          * @throws IllegalArgumentException if the given namespace is null or blank
 183  
          */
 184  
         public void setNamespace(String namespace) {
 185  0
             if (StringUtils.isBlank(namespace)) {
 186  0
                 throw new IllegalArgumentException("namespace is blank");
 187  
             }
 188  0
             this.namespace = namespace;
 189  0
         }
 190  
 
 191  
         public void setVersionNumber(Long versionNumber){
 192  0
             this.versionNumber = versionNumber;
 193  0
         }
 194  
 
 195  
         @Override
 196  
         public String getId() {
 197  0
             return this.id;
 198  
         }
 199  
 
 200  
         @Override
 201  
         public String getName() {
 202  0
             return this.name;
 203  
         }
 204  
 
 205  
         @Override
 206  
         public String getNamespace() {
 207  0
             return this.namespace;
 208  
         }
 209  
 
 210  
         @Override
 211  
         public Long getVersionNumber() {
 212  0
             return this.versionNumber;
 213  
         }
 214  
 
 215  
         /**
 216  
          * Builds an instance of a CategoryDefinition based on the current state of the builder.
 217  
          *
 218  
          * @return the fully-constructed CampusType
 219  
          */
 220  
         @Override
 221  
         public CategoryDefinition build() {
 222  0
             return new CategoryDefinition(this);
 223  
         }
 224  
 
 225  
     }
 226  
 
 227  
     /**
 228  
      * Defines some internal constants used on this class.
 229  
      */
 230  0
     static class Constants {
 231  
         final static String ROOT_ELEMENT_NAME = "category";
 232  
         final static String TYPE_NAME = "CategoryType";
 233  
     }
 234  
 
 235  
     /**
 236  
      * A private class which exposes constants which define the XML element names to use
 237  
      * when this object is marshalled to XML.
 238  
      */
 239  0
     public static class Elements {
 240  
         final static String ID = "id";
 241  
         final static String NAME = "name";
 242  
         final static String NAMESPACE = "namespace";
 243  
     }
 244  
 }
 245  
 
 246