Coverage Report - org.kuali.rice.kew.api.document.attribute.DocumentAttribute
 
Classes in this File Line Coverage Branch Coverage Complexity
DocumentAttribute
0%
0/10
0%
0/2
1.444
DocumentAttribute$AbstractBuilder
0%
0/12
0%
0/2
1.444
DocumentAttribute$Constants
0%
0/1
N/A
1.444
DocumentAttribute$Elements
0%
0/1
N/A
1.444
 
 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.kew.api.document.attribute;
 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.XmlSeeAlso;
 29  
 import javax.xml.bind.annotation.XmlType;
 30  
 import java.io.Serializable;
 31  
 import java.util.Collection;
 32  
 
 33  
 /**
 34  
  * An abstract representation of the {@code DocumentAttributeContract} which can be used as the super class for
 35  
  * concrete immutable data transfer object implementations of document attributes.  This class also defines an abstract
 36  
  * builder implementation which can be extended by it's subclasses to create their own internal builder implementations.
 37  
  *
 38  
  * <p>The KEW api defines the understood set of document attribute implementations, so it is not generally of value for
 39  
  * a client of the api to subclass this class.</p>
 40  
  *
 41  
  * @author Kuali Rice Team (rice.collab@kuali.org).
 42  
  */
 43  
 @XmlAccessorType(XmlAccessType.NONE)
 44  
 @XmlType(name = DocumentAttribute.Constants.TYPE_NAME, propOrder = {
 45  
     DocumentAttribute.Elements.NAME,
 46  
     CoreConstants.CommonElements.FUTURE_ELEMENTS
 47  
 })
 48  
 @XmlSeeAlso( { DocumentAttributeString.class, DocumentAttributeDateTime.class, DocumentAttributeInteger.class, DocumentAttributeDecimal.class } )
 49  
 public abstract class DocumentAttribute extends AbstractDataTransferObject implements DocumentAttributeContract {
 50  
 
 51  
     private static final long serialVersionUID = -1935235225791818090L;
 52  
     
 53  
     @XmlElement(name = Elements.NAME, required = true)
 54  
     private final String name;
 55  
 
 56  0
     @SuppressWarnings("unused")
 57  
     @XmlAnyElement
 58  
     private final Collection<Element> _futureElements = null;
 59  
 
 60  0
     protected DocumentAttribute() {
 61  0
         this.name = null;
 62  0
     }
 63  
 
 64  0
     DocumentAttribute(String name) {
 65  0
         if (StringUtils.isBlank(name)) {
 66  0
             throw new IllegalArgumentException("name was null or blank");
 67  
         }
 68  0
         this.name = name;
 69  0
     }
 70  
 
 71  
     @Override
 72  
     public String getName() {
 73  0
         return name;
 74  
     }
 75  
 
 76  
     /**
 77  
      * An abstract base class that can be extended by concrete builder implementations of subclasses of
 78  
      * {@code DocumentAttribute}.
 79  
      *
 80  
      * @param <T> the type of the value contained within the document attribute that is built by this builder
 81  
      */
 82  0
     public abstract static class AbstractBuilder<T> implements Serializable, ModelBuilder, DocumentAttributeContract {
 83  
 
 84  
         private static final long serialVersionUID = -4402662354421207678L;
 85  
         
 86  
         private String name;
 87  
         private T value;
 88  
 
 89  0
         protected AbstractBuilder(String name) {
 90  0
             setName(name);
 91  0
         }
 92  
 
 93  
         @Override
 94  
         public String getName() {
 95  0
             return name;
 96  
         }
 97  
 
 98  
         /**
 99  
          * Sets the name of the document attribute that will be built by this builder.
 100  
          *
 101  
          * @param name the name of the document attribute to set, must not be a null or blank value
 102  
          * @throws IllegalArgumentException if the given name is a null or blank value.
 103  
          */
 104  
         public void setName(String name) {
 105  0
             if (StringUtils.isBlank(name)) {
 106  0
                 throw new IllegalArgumentException("name was null or blank");
 107  
             }
 108  0
             this.name = name;
 109  0
         }
 110  
 
 111  
         @Override
 112  
         public T getValue() {
 113  0
             return value;
 114  
         }
 115  
 
 116  
         /**
 117  
          * Sets the value of the document attribute that will be built by this builder.
 118  
          *
 119  
          * @param value the value of the document attribute to set
 120  
          */
 121  
         public void setValue(T value) {
 122  0
             this.value = value;
 123  0
         }
 124  
 
 125  
         /**
 126  
          * Build the {@code DocumentAttribute} for this builder based on it's current state.
 127  
          *
 128  
          * @return the instantiated instance of {@code DocumentAttribute} which was built by this builder
 129  
          */
 130  
         public abstract DocumentAttribute build();
 131  
         
 132  
     }
 133  
 
 134  
     /**
 135  
      * Defines some internal constants used on this class.
 136  
      */
 137  0
     static class Constants {
 138  
         final static String TYPE_NAME = "DocumentAttributeType";
 139  
     }
 140  
 
 141  
     /**
 142  
      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
 143  
      */
 144  0
     static class Elements {
 145  
         final static String NAME = "name";
 146  
     }
 147  
 
 148  
 }