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