Coverage Report - org.kuali.rice.kim.api.common.attribute.KimAttribute
 
Classes in this File Line Coverage Branch Coverage Complexity
KimAttribute
100%
30/30
N/A
1.3
KimAttribute$1
N/A
N/A
1.3
KimAttribute$Builder
100%
48/48
100%
10/10
1.3
KimAttribute$Constants
0%
0/1
N/A
1.3
KimAttribute$Elements
0%
0/1
N/A
1.3
 
 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.kim.api.common.attribute;
 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 a {@link KimAttributeContract}.
 36  
  *
 37  
  * <p>To construct an instance of a KimAttribute, use the {@link KimAttribute.Builder} class.<p/>
 38  
  *
 39  
  * @see KimAttributeContract
 40  
  */
 41  
 @XmlRootElement(name = KimAttribute.Constants.ROOT_ELEMENT_NAME)
 42  
 @XmlAccessorType(XmlAccessType.NONE)
 43  
 @XmlType(name = KimAttribute.Constants.TYPE_NAME, propOrder = {
 44  
         KimAttribute.Elements.ID,
 45  
         KimAttribute.Elements.COMPONENT_NAME,
 46  
         KimAttribute.Elements.ATTRIBUTE_NAME,
 47  
         KimAttribute.Elements.NAMESPACE_CODE,
 48  
         KimAttribute.Elements.ATTRIBUTE_LABEL,
 49  
         KimAttribute.Elements.ACTIVE,
 50  
         CoreConstants.CommonElements.VERSION_NUMBER,
 51  
         CoreConstants.CommonElements.OBJECT_ID,
 52  
         CoreConstants.CommonElements.FUTURE_ELEMENTS
 53  
 })
 54  9
 public final class KimAttribute extends AbstractDataTransferObject implements KimAttributeContract {
 55  
     private static final long serialVersionUID = 1L;
 56  
 
 57  
     @XmlElement(name = KimAttribute.Elements.ID, required = false)
 58  
     private final String id;
 59  
 
 60  
     @XmlElement(name = KimAttribute.Elements.COMPONENT_NAME, required = true)
 61  
     private final String componentName;
 62  
 
 63  
     @XmlElement(name = KimAttribute.Elements.ATTRIBUTE_NAME, required = true)
 64  
     private final String attributeName;
 65  
 
 66  
     @XmlElement(name = KimAttribute.Elements.NAMESPACE_CODE, required = true)
 67  
     private final String namespaceCode;
 68  
 
 69  
     @XmlElement(name = KimAttribute.Elements.ATTRIBUTE_LABEL, required = false)
 70  
     private final String attributeLabel;
 71  
 
 72  
     @XmlElement(name = KimAttribute.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  14
     @SuppressWarnings("unused")
 82  
     @XmlAnyElement
 83  
     private final Collection<Element> _futureElements = null;
 84  
 
 85  
     /**
 86  
      * This constructor should never be called except during JAXB unmarshalling.
 87  
      */
 88  5
     private KimAttribute() {
 89  5
         this.id = null;
 90  5
         this.componentName = null;
 91  5
         this.attributeName = null;
 92  5
         this.namespaceCode = null;
 93  5
         this.attributeLabel = null;
 94  5
         this.active = false;
 95  5
         this.versionNumber = Long.valueOf(1L);
 96  5
         this.objectId = null;
 97  5
     }
 98  
 
 99  9
     private KimAttribute(Builder builder) {
 100  9
         this.id = builder.getId();
 101  9
         this.componentName = builder.getComponentName();
 102  9
         this.attributeName = builder.getAttributeName();
 103  9
         this.namespaceCode = builder.getNamespaceCode();
 104  9
         this.attributeLabel = builder.getAttributeLabel();
 105  9
         this.active = builder.isActive();
 106  9
         this.versionNumber = builder.getVersionNumber();
 107  9
         this.objectId = builder.getObjectId();
 108  9
     }
 109  
 
 110  
     @Override
 111  
     public String getId() {
 112  3
         return id;
 113  
     }
 114  
 
 115  
     @Override
 116  
     public String getComponentName() {
 117  3
         return componentName;
 118  
     }
 119  
 
 120  
     @Override
 121  
     public String getAttributeName() {
 122  3
         return attributeName;
 123  
     }
 124  
 
 125  
     @Override
 126  
     public String getNamespaceCode() {
 127  3
         return namespaceCode;
 128  
     }
 129  
 
 130  
     @Override
 131  
     public String getAttributeLabel() {
 132  2
         return attributeLabel;
 133  
     }
 134  
 
 135  
     @Override
 136  
     public Long getVersionNumber() {
 137  2
         return versionNumber;
 138  
     }
 139  
 
 140  
     @Override
 141  
     public boolean isActive() {
 142  2
         return active;
 143  
     }
 144  
 
 145  
     @Override
 146  
     public String getObjectId() {
 147  2
         return objectId;
 148  
     }
 149  
 
 150  
     /**
 151  
      * This builder constructs an KimAttribute enforcing the constraints of the {@link KimAttributeContract}.
 152  
      */
 153  8
     public static final class Builder implements KimAttributeContract, ModelBuilder, Serializable {
 154  
         private String id;
 155  
         private String componentName;
 156  
         private String attributeName;
 157  
         private String namespaceCode;
 158  
         private String attributeLabel;
 159  
         private boolean active;
 160  22
         private Long versionNumber = 1L;
 161  
         private String objectId;
 162  
 
 163  22
         private Builder(String componentName, String attributeName, String namespaceCode) {
 164  22
             setComponentName(componentName);
 165  18
             setAttributeName(attributeName);
 166  15
             setNamespaceCode(namespaceCode);
 167  12
         }
 168  
 
 169  
         /**
 170  
          * creates a KimAttribute with the required fields.
 171  
          */
 172  
         public static Builder create(String componentName, String attributeName, String namespaceCode) {
 173  19
             return new Builder(componentName, attributeName, namespaceCode);
 174  
         }
 175  
 
 176  
         /**
 177  
          * creates a KimAttribute from an existing {@link KimAttributeContract}.
 178  
          */
 179  
         public static Builder create(KimAttributeContract contract) {
 180  3
             Builder builder = new Builder(contract.getComponentName(), contract.getAttributeName(), contract.getNamespaceCode());
 181  3
             builder.setId(contract.getId());
 182  3
             builder.setAttributeLabel(contract.getAttributeLabel());
 183  3
             builder.setActive(contract.isActive());
 184  3
             builder.setVersionNumber(contract.getVersionNumber());
 185  3
             builder.setObjectId(contract.getObjectId());
 186  3
             return builder;
 187  
         }
 188  
 
 189  
 
 190  
         @Override
 191  
         public String getId() {
 192  9
             return id;
 193  
         }
 194  
 
 195  
         public void setId(final String id) {
 196  8
             this.id = id;
 197  8
         }
 198  
 
 199  
         @Override
 200  
         public String getComponentName() {
 201  9
             return componentName;
 202  
         }
 203  
 
 204  
         public void setComponentName(final String componentName) {
 205  22
             if (StringUtils.isBlank(componentName)) {
 206  4
                 throw new IllegalArgumentException("componentName is blank");
 207  
             }
 208  
 
 209  18
             this.componentName = componentName;
 210  18
         }
 211  
 
 212  
         @Override
 213  
         public String getAttributeName() {
 214  9
             return attributeName;
 215  
         }
 216  
 
 217  
         public void setAttributeName(final String attributeName) {
 218  18
             if (StringUtils.isBlank(attributeName)) {
 219  3
                 throw new IllegalArgumentException("attributeName is blank");
 220  
             }
 221  
 
 222  15
             this.attributeName = attributeName;
 223  15
         }
 224  
 
 225  
         @Override
 226  
         public String getNamespaceCode() {
 227  9
             return namespaceCode;
 228  
         }
 229  
 
 230  
         public void setNamespaceCode(final String namespaceCode) {
 231  15
             if (StringUtils.isBlank(namespaceCode)) {
 232  3
                 throw new IllegalArgumentException("namespaceCode is blank");
 233  
             }
 234  
 
 235  12
             this.namespaceCode = namespaceCode;
 236  12
         }
 237  
 
 238  
         @Override
 239  
         public String getAttributeLabel() {
 240  9
             return attributeLabel;
 241  
         }
 242  
 
 243  
         public void setAttributeLabel(final String attributeLabel) {
 244  3
             this.attributeLabel = attributeLabel;
 245  3
         }
 246  
 
 247  
         @Override
 248  
         public boolean isActive() {
 249  9
             return active;
 250  
         }
 251  
 
 252  
         public void setActive(final boolean active) {
 253  3
             this.active = active;
 254  3
         }
 255  
 
 256  
         @Override
 257  
         public Long getVersionNumber() {
 258  9
             return versionNumber;
 259  
         }
 260  
 
 261  
         public void setVersionNumber(final Long versionNumber) {
 262  5
             if (versionNumber == null || versionNumber <= 0) {
 263  2
                 throw new IllegalArgumentException("versionNumber is invalid");
 264  
             }
 265  
 
 266  3
             this.versionNumber = versionNumber;
 267  3
         }
 268  
 
 269  
         @Override
 270  
         public String getObjectId() {
 271  9
             return objectId;
 272  
         }
 273  
 
 274  
         public void setObjectId(final String objectId) {
 275  3
             this.objectId = objectId;
 276  3
         }
 277  
 
 278  
         @Override
 279  
         public KimAttribute build() {
 280  9
             return new KimAttribute(this);
 281  
         }
 282  
     }
 283  
 
 284  
 
 285  
     /**
 286  
      * Defines some internal constants used on this class.
 287  
      */
 288  0
     static class Constants {
 289  
         static final String ROOT_ELEMENT_NAME = "kimAttribute";
 290  
         static final String TYPE_NAME = "KimAttributeType";
 291  
     }
 292  
 
 293  
     /**
 294  
      * A private class which exposes constants which define the XML element names to use
 295  
      * when this object is marshalled to XML.
 296  
      */
 297  0
     static class Elements {
 298  
         static final String ID = "id";
 299  
         static final String COMPONENT_NAME = "componentName";
 300  
         static final String ATTRIBUTE_NAME = "attributeName";
 301  
         static final String NAMESPACE_CODE = "namespaceCode";
 302  
         static final String ATTRIBUTE_LABEL = "attributeLabel";
 303  
         static final String ACTIVE = "active";
 304  
     }
 305  
 
 306  
 }