Coverage Report - org.kuali.rice.krms.api.repository.BaseAttribute
 
Classes in this File Line Coverage Branch Coverage Complexity
BaseAttribute
0%
0/20
0%
0/2
1.188
BaseAttribute$Builder
0%
0/22
0%
0/2
1.188
BaseAttribute$Elements
0%
0/1
N/A
1.188
 
 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;
 17  
 
 18  
 import java.io.Serializable;
 19  
 import java.util.Collection;
 20  
 
 21  
 import javax.xml.bind.annotation.XmlAnyElement;
 22  
 import javax.xml.bind.annotation.XmlElement;
 23  
 import javax.xml.bind.annotation.XmlTransient;
 24  
 
 25  
 import org.apache.commons.lang.StringUtils;
 26  
 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
 27  
 import org.kuali.rice.core.api.mo.ModelBuilder;
 28  
 import org.kuali.rice.krms.api.repository.type.KrmsAttributeDefinition;
 29  
 
 30  
 /**
 31  
  * abstract base model object for KRMS Attribute immutables. 
 32  
  *
 33  
  */
 34  0
 @XmlTransient
 35  
 public abstract class BaseAttribute extends AbstractDataTransferObject implements BaseAttributeContract {
 36  
         private static final long serialVersionUID = -6126133049308968098L;
 37  
         
 38  
         @XmlElement(name = Elements.ID, required=true)
 39  
         private final String id;
 40  
 
 41  
         @XmlElement(name = Elements.ATTR_DEFN_ID, required=false)
 42  
         private final String attributeDefinitionId;
 43  
 
 44  
         @XmlElement(name = Elements.VALUE, required=false)
 45  
         private final String value;
 46  
         
 47  
         @XmlElement(name = Elements.ATTR_DEFN, required=false)
 48  
         private final KrmsAttributeDefinition attributeDefinition;
 49  
         
 50  0
     @SuppressWarnings("unused")
 51  
         @XmlAnyElement
 52  
         private final Collection<org.w3c.dom.Element> _futureElements = null;
 53  
         
 54  
          /** 
 55  
      * This constructor should only be called by the private default constructor of subclasses,
 56  
      * which should only be used by JAXB and never invoked directly.
 57  
      */
 58  0
     protected BaseAttribute() {
 59  0
             this.id = null;
 60  0
             this.attributeDefinitionId = null;
 61  0
             this.value = null;
 62  0
             this.attributeDefinition = null;
 63  0
     }
 64  
     
 65  
     /**
 66  
          * Constructs a BaseAttribute from the given builder.  
 67  
          * This constructor is protected and should only ever be invoked from the builder.
 68  
          * 
 69  
          * @param builder the Builder from which to construct the BaseAttribute
 70  
          */
 71  0
     protected BaseAttribute(Builder builder) {
 72  0
         this.id = builder.getId();
 73  0
         this.attributeDefinitionId = builder.getAttributeDefinitionId();
 74  0
         this.value = builder.getValue();
 75  0
         if (builder.getAttributeDefinition() != null) {
 76  0
                 this.attributeDefinition = builder.getAttributeDefinition().build();
 77  
         } else {
 78  0
                 this.attributeDefinition = null;
 79  
         }
 80  0
     }
 81  
     
 82  
         @Override
 83  
         public String getId() {
 84  0
                 return this.id;
 85  
         }
 86  
         
 87  
         @Override
 88  
         public String getAttributeDefinitionId() {
 89  0
                 return this.attributeDefinitionId;
 90  
         }
 91  
 
 92  
         @Override
 93  
         public String getValue() {
 94  0
                 return this.value;
 95  
         }
 96  
         
 97  
         @Override
 98  
         public KrmsAttributeDefinition getAttributeDefinition() {
 99  0
                 return this.attributeDefinition;
 100  
         }
 101  
         
 102  
         /**
 103  
      * This builder is used to construct the fields that {@link BaseAttribute} is responsible for.  It is abstract,
 104  
      * and intended to be subclassed by extenders of {@link BaseAttribute}.
 105  
      */
 106  0
     public abstract static class Builder implements BaseAttributeContract, ModelBuilder, Serializable {                
 107  
                 private static final long serialVersionUID = 5799994031051731535L;
 108  
 
 109  
                 private String id;
 110  
         private String attributeDefinitionId;
 111  
         private String value;
 112  
         private KrmsAttributeDefinition.Builder attributeDefinition;
 113  
         
 114  
                 /**
 115  
                  * Private constructor for creating a builder with all of it's required attributes.
 116  
                  */
 117  0
         protected Builder(String id, String attributeDefinitionId, String value) {
 118  0
             setId(id);
 119  0
             setAttributeDefinitionId(attributeDefinitionId);
 120  0
             setValue(value);
 121  0
         }
 122  
 
 123  
         protected Builder(BaseAttributeContract attr) {
 124  0
                 this (attr.getId(), attr.getAttributeDefinitionId(), attr.getValue());
 125  0
         }
 126  
 
 127  
                 /**
 128  
                  * Sets the value of the id on this builder to the given value.
 129  
                  * 
 130  
                  * @param id the id value to set, must not be null or blank
 131  
                  * @throws IllegalArgumentException if the id is null or blank
 132  
                  */
 133  
         public void setId(String id) {
 134  
 //            if (StringUtils.isBlank(id)) {
 135  
 //                throw new IllegalArgumentException("id is blank");
 136  
 //            }
 137  0
             this.id = id;
 138  0
         }
 139  
 
 140  
                 public void setAttributeDefinitionId(String attributeDefinitionId) {
 141  0
             if (StringUtils.isBlank(attributeDefinitionId)) {
 142  0
                 throw new IllegalArgumentException("the attribute definition id is blank");
 143  
             }
 144  0
                         this.attributeDefinitionId = attributeDefinitionId;
 145  0
                 }
 146  
                 
 147  
                 public void setValue(String value) {
 148  0
                         this.value = value;
 149  0
                 }
 150  
                 
 151  
                 public void setAttributeDefinition(KrmsAttributeDefinition.Builder attributeDefinition) {
 152  0
                         this.attributeDefinition = attributeDefinition;
 153  0
                 }
 154  
                 
 155  
                 @Override
 156  
                 public String getId() {
 157  0
                         return id;
 158  
                 }
 159  
 
 160  
                 @Override
 161  
                 public String getAttributeDefinitionId() {
 162  0
                         return attributeDefinitionId;
 163  
                 }
 164  
                 
 165  
                 @Override
 166  
                 public String getValue() {
 167  0
                         return value;
 168  
                 }
 169  
 
 170  
                 @Override
 171  
                 public KrmsAttributeDefinition.Builder getAttributeDefinition() {
 172  0
                         return attributeDefinition;
 173  
                 }
 174  
 
 175  
     }
 176  
         
 177  
         /**
 178  
          * A protected class which exposes constants which define the XML element names to use
 179  
          * when this object is marshalled to XML.
 180  
          */
 181  0
         public static class Elements {
 182  
                 public final static String ID = "id";
 183  
                 public final static String ATTR_DEFN_ID = "attributeDefinitionId";
 184  
                 public final static String VALUE = "value";
 185  
                 public final static String ATTR_DEFN = "attributeDefinition";
 186  
         }
 187  
 }