Coverage Report - org.kuali.rice.kim.api.type.KimAttributeField
 
Classes in this File Line Coverage Branch Coverage Complexity
KimAttributeField
0%
0/24
0%
0/8
1.812
KimAttributeField$1
N/A
N/A
1.812
KimAttributeField$Builder
0%
0/25
0%
0/6
1.812
KimAttributeField$Constants
0%
0/1
N/A
1.812
KimAttributeField$Elements
0%
0/1
N/A
1.812
 
 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.kim.api.type;
 17  
 
 18  
 import java.io.Serializable;
 19  
 import java.util.Collection;
 20  
 import javax.xml.bind.annotation.XmlAccessType;
 21  
 import javax.xml.bind.annotation.XmlAccessorType;
 22  
 import javax.xml.bind.annotation.XmlAnyElement;
 23  
 import javax.xml.bind.annotation.XmlElement;
 24  
 import javax.xml.bind.annotation.XmlRootElement;
 25  
 import javax.xml.bind.annotation.XmlType;
 26  
 
 27  
 import org.apache.commons.lang.StringUtils;
 28  
 import org.kuali.rice.core.api.CoreConstants;
 29  
 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
 30  
 import org.kuali.rice.core.api.mo.ModelBuilder;
 31  
 import org.kuali.rice.core.api.uif.AttributeField;
 32  
 import org.kuali.rice.core.api.uif.RemotableAttributeField;
 33  
 import org.w3c.dom.Element;
 34  
 
 35  0
 @XmlRootElement(name = KimAttributeField.Constants.ROOT_ELEMENT_NAME)
 36  
 @XmlAccessorType(XmlAccessType.NONE)
 37  
 @XmlType(name = KimAttributeField.Constants.TYPE_NAME, propOrder = {
 38  
     KimAttributeField.Elements.ATTRIBUTE_FIELD,
 39  
     KimAttributeField.Elements.ID,
 40  
     KimAttributeField.Elements.UNIQUE,
 41  
     CoreConstants.CommonElements.FUTURE_ELEMENTS
 42  
 })
 43  0
 public final class KimAttributeField
 44  
     extends AbstractDataTransferObject
 45  
     implements KimAttributeFieldContract
 46  
 {
 47  
 
 48  
     @XmlElement(name = Elements.ATTRIBUTE_FIELD, required = true)
 49  
     private final RemotableAttributeField attributeField;
 50  
     @XmlElement(name = Elements.ID, required = true)
 51  
     private final String id;
 52  
     @XmlElement(name = Elements.UNIQUE, required = false)
 53  
     private final boolean unique;
 54  
 
 55  0
     @SuppressWarnings("unused")
 56  
     @XmlAnyElement
 57  
     private final Collection<Element> _futureElements = null;
 58  
 
 59  
     /**
 60  
      * Private constructor used only by JAXB.
 61  
      * 
 62  
      */
 63  0
     private KimAttributeField() {
 64  0
         this.attributeField = null;
 65  0
         this.id = null;
 66  0
         this.unique = false;
 67  0
     }
 68  
 
 69  0
     private KimAttributeField(Builder builder) {
 70  0
         this.attributeField = builder.getAttributeField().build();
 71  0
         this.id = builder.getId();
 72  0
         this.unique = builder.isUnique();
 73  0
     }
 74  
 
 75  
     @Override
 76  
     public RemotableAttributeField getAttributeField() {
 77  0
         return this.attributeField;
 78  
     }
 79  
 
 80  
     @Override
 81  
     public String getId() {
 82  0
         return this.id;
 83  
     }
 84  
 
 85  
     @Override
 86  
     public boolean isUnique() {
 87  0
         return this.unique;
 88  
     }
 89  
 
 90  
     /**
 91  
      * Utility method to search a collection of attribute fields and returns
 92  
      * a field for a give attribute name.
 93  
      *
 94  
      * @param attributeName the name of the attribute to search for.  Cannot be blank or null.
 95  
      * @param fields cannot be null.
 96  
      *
 97  
      * @return the attribute field or null if not found.
 98  
      */
 99  
     public static KimAttributeField findAttribute(String attributeName, Collection<KimAttributeField> fields) {
 100  0
         if (StringUtils.isBlank(attributeName)) {
 101  0
             throw new IllegalArgumentException("attributeName is blank");
 102  
         }
 103  
 
 104  0
         if (fields == null) {
 105  0
             throw new IllegalArgumentException("errors is null");
 106  
         }
 107  
 
 108  0
         for (KimAttributeField field : fields) {
 109  0
             if (attributeName.equals(field.getAttributeField().getName())) {
 110  0
                 return field;
 111  
             }
 112  
         }
 113  0
         return null;
 114  
     }
 115  
 
 116  
     /**
 117  
      * A builder which can be used to construct {@link KimAttributeField} instances.  Enforces the constraints of the {@link KimAttributeFieldContract}.
 118  
      * 
 119  
      */
 120  0
     public final static class Builder
 121  
         implements Serializable, ModelBuilder, KimAttributeFieldContract
 122  
     {
 123  
 
 124  
         private RemotableAttributeField.Builder attributeField;
 125  
         private String id;
 126  
         private boolean unique;
 127  
 
 128  0
         private Builder(RemotableAttributeField.Builder attributeField, String id) {
 129  0
             setAttributeField(attributeField);
 130  0
             setId(id);
 131  0
         }
 132  
 
 133  
         public static Builder create(RemotableAttributeField.Builder attributeField, String id) {
 134  0
             return new Builder(attributeField, id);
 135  
         }
 136  
 
 137  
         public static Builder create(KimAttributeFieldContract contract) {
 138  0
             if (contract == null) {
 139  0
                 throw new IllegalArgumentException("contract was null");
 140  
             }
 141  0
             Builder b = create(RemotableAttributeField.Builder.create(contract.getAttributeField()), contract.getId());
 142  0
             b.setUnique(contract.isUnique());
 143  0
             return b;
 144  
         }
 145  
 
 146  
         public KimAttributeField build() {
 147  0
             return new KimAttributeField(this);
 148  
         }
 149  
 
 150  
         @Override
 151  
         public RemotableAttributeField.Builder getAttributeField() {
 152  0
             return this.attributeField;
 153  
         }
 154  
 
 155  
         @Override
 156  
         public String getId() {
 157  0
             return this.id;
 158  
         }
 159  
 
 160  
         @Override
 161  
         public boolean isUnique() {
 162  0
             return this.unique;
 163  
         }
 164  
 
 165  
         public void setAttributeField(RemotableAttributeField.Builder attributeField) {
 166  0
             if (attributeField == null) {
 167  0
                 throw new IllegalArgumentException("attributeField is null");
 168  
             }
 169  
 
 170  0
             this.attributeField = attributeField;
 171  0
         }
 172  
 
 173  
         public void setId(String id) {
 174  0
             if (StringUtils.isBlank(id)) {
 175  0
                 throw new IllegalArgumentException("id is blank");
 176  
             }
 177  0
             this.id = id;
 178  0
         }
 179  
 
 180  
         public void setUnique(boolean unique) {
 181  0
             this.unique = unique;
 182  0
         }
 183  
 
 184  
     }
 185  
 
 186  
 
 187  
     /**
 188  
      * Defines some internal constants used on this class.
 189  
      * 
 190  
      */
 191  0
     static class Constants {
 192  
 
 193  
         final static String ROOT_ELEMENT_NAME = "kimAttributeField";
 194  
         final static String TYPE_NAME = "KimAttributeFieldType";
 195  
 
 196  
     }
 197  
 
 198  
 
 199  
     /**
 200  
      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
 201  
      * 
 202  
      */
 203  0
     static class Elements {
 204  
 
 205  
         final static String ATTRIBUTE_FIELD = "attributeField";
 206  
         final static String ID = "id";
 207  
         final static String UNIQUE = "unique";
 208  
     }
 209  
 
 210  
 }