Coverage Report - org.kuali.rice.core.api.parameter.Parameter
 
Classes in this File Line Coverage Branch Coverage Complexity
Parameter
100%
38/38
100%
2/2
1.306
Parameter$1
N/A
N/A
1.306
Parameter$Builder
98%
56/57
100%
10/10
1.306
Parameter$Cache
0%
0/1
N/A
1.306
Parameter$Constants
0%
0/1
N/A
1.306
Parameter$Elements
0%
0/1
N/A
1.306
 
 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.core.api.parameter;
 17  
 
 18  
 import java.io.Serializable;
 19  
 import java.util.Collection;
 20  
 
 21  
 import javax.xml.bind.annotation.XmlAccessType;
 22  
 import javax.xml.bind.annotation.XmlAccessorType;
 23  
 import javax.xml.bind.annotation.XmlAnyElement;
 24  
 import javax.xml.bind.annotation.XmlElement;
 25  
 import javax.xml.bind.annotation.XmlRootElement;
 26  
 import javax.xml.bind.annotation.XmlType;
 27  
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
 28  
 
 29  
 import org.apache.commons.lang.StringUtils;
 30  
 import org.kuali.rice.core.api.CoreConstants;
 31  
 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
 32  
 import org.kuali.rice.core.api.mo.ModelBuilder;
 33  
 import org.w3c.dom.Element;
 34  
 
 35  
 /**
 36  
  * An immutable representation of a {@link ParameterContract}.
 37  
  * <p/>
 38  
  * <p>To construct an instance of a Parameter, use the {@link Parameter.Builder} class.
 39  
  *
 40  
  * @see ParameterContract
 41  
  */
 42  1
 @XmlRootElement(name = Parameter.Constants.ROOT_ELEMENT_NAME)
 43  
 @XmlAccessorType(XmlAccessType.NONE)
 44  
 @XmlType(name = Parameter.Constants.TYPE_NAME, propOrder = {
 45  
         Parameter.Elements.APPLICATION_ID,
 46  
         Parameter.Elements.NAMESPACE_CODE,
 47  
         Parameter.Elements.COMPONENT_CODE,
 48  
         Parameter.Elements.NAME,
 49  
         Parameter.Elements.VALUE,
 50  
         Parameter.Elements.DESCRIPTION,
 51  
         Parameter.Elements.PARAMETER_TYPE,
 52  
         Parameter.Elements.EVALUATION_OPERATOR,
 53  
         CoreConstants.CommonElements.VERSION_NUMBER,
 54  
         CoreConstants.CommonElements.OBJECT_ID,
 55  
         CoreConstants.CommonElements.FUTURE_ELEMENTS
 56  
 })
 57  3
 public final class Parameter extends AbstractDataTransferObject implements ParameterContract {
 58  
 
 59  
     private static final long serialVersionUID = 6097498602725305353L;
 60  
 
 61  
     @XmlElement(name = Elements.APPLICATION_ID, required = true)
 62  
     private final String applicationId;
 63  
 
 64  
     @XmlElement(name = Elements.NAMESPACE_CODE, required = true)
 65  
     private final String namespaceCode;
 66  
 
 67  
     @XmlElement(name = Elements.COMPONENT_CODE, required = true)
 68  
     private final String componentCode;
 69  
 
 70  
     @XmlElement(name = Elements.NAME, required = true)
 71  
     private final String name;
 72  
 
 73  
     @XmlElement(name = Elements.VALUE, nillable = true, required = false)
 74  
     private final String value;
 75  
 
 76  
     @XmlElement(name = Elements.DESCRIPTION, required = false)
 77  
     private final String description;
 78  
 
 79  
     @XmlElement(name = Elements.PARAMETER_TYPE, required = true)
 80  
     private final ParameterType parameterType;
 81  
 
 82  
     @XmlJavaTypeAdapter(EvaluationOperator.Adapter.class)
 83  
     @XmlElement(name = Elements.EVALUATION_OPERATOR, required = false)
 84  
     private final String evaluationOperator;
 85  
 
 86  
     @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
 87  
     private final Long versionNumber;
 88  
 
 89  
     @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
 90  
     private final String objectId;
 91  
 
 92  5
     @SuppressWarnings("unused")
 93  
     @XmlAnyElement
 94  
     private final Collection<Element> _futureElements = null;
 95  
 
 96  
     /**
 97  
      * This constructor should never be called except during JAXB unmarshalling.
 98  
      */
 99  2
     private Parameter() {
 100  2
         this.applicationId = null;
 101  2
         this.namespaceCode = null;
 102  2
         this.componentCode = null;
 103  2
         this.name = null;
 104  2
         this.value = null;
 105  2
         this.description = null;
 106  2
         this.parameterType = null;
 107  2
         this.evaluationOperator = null;
 108  2
         this.versionNumber = null;
 109  2
         this.objectId = null;
 110  2
     }
 111  
 
 112  3
     private Parameter(Builder builder) {
 113  3
         applicationId = builder.getApplicationId();
 114  3
         namespaceCode = builder.getNamespaceCode();
 115  3
         componentCode = builder.getComponentCode();
 116  3
         name = builder.getName();
 117  3
         value = builder.getValue();
 118  3
         description = builder.getDescription();
 119  3
         parameterType = builder.parameterType.build();
 120  3
         EvaluationOperator evaluationOperatorEnum = builder.getEvaluationOperator();
 121  3
         evaluationOperator = evaluationOperatorEnum == null ? null : evaluationOperatorEnum.getCode(); 
 122  3
         versionNumber = builder.getVersionNumber();
 123  3
         objectId = builder.getObjectId();
 124  3
     }
 125  
 
 126  
     @Override
 127  
     public String getApplicationId() {
 128  1
         return applicationId;
 129  
     }
 130  
 
 131  
     @Override
 132  
     public String getNamespaceCode() {
 133  1
         return namespaceCode;
 134  
     }
 135  
 
 136  
     @Override
 137  
     public String getComponentCode() {
 138  1
         return componentCode;
 139  
     }
 140  
 
 141  
     @Override
 142  
     public String getName() {
 143  1
         return name;
 144  
     }
 145  
 
 146  
     @Override
 147  
     public String getValue() {
 148  1
         return value;
 149  
     }
 150  
 
 151  
     @Override
 152  
     public String getDescription() {
 153  1
         return description;
 154  
     }
 155  
 
 156  
     @Override
 157  
     public ParameterType getParameterType() {
 158  1
         return parameterType;
 159  
     }
 160  
 
 161  
     @Override
 162  
     public EvaluationOperator getEvaluationOperator() {
 163  1
         return EvaluationOperator.fromCode(evaluationOperator);
 164  
     }
 165  
 
 166  
     @Override
 167  
     public Long getVersionNumber() {
 168  1
         return versionNumber;
 169  
     }
 170  
 
 171  
     @Override
 172  
     public String getObjectId() {
 173  1
         return objectId;
 174  
     }
 175  
 
 176  
     /**
 177  
      * This builder constructs an Parameter enforcing the constraints of the {@link ParameterContract}.
 178  
      */
 179  6
     public static final class Builder implements ParameterContract, ModelBuilder, Serializable {
 180  
 
 181  
         private static final long serialVersionUID = 7077484401017765844L;
 182  
 
 183  
         private String applicationId;
 184  
         private String namespaceCode;
 185  
         private String componentCode;
 186  
         private String name;
 187  
         private String value;
 188  
         private String description;
 189  
         private ParameterType.Builder parameterType;
 190  
         private EvaluationOperator evaluationOperator;
 191  
         private Long versionNumber;
 192  
         private String objectId;
 193  
 
 194  18
         private Builder(String applicationId, String namespaceCode, String componentCode, String name, ParameterType.Builder parameterType) {
 195  18
             setApplicationId(applicationId);
 196  14
             setNamespaceCode(namespaceCode);
 197  11
             setComponentCode(componentCode);
 198  8
             setName(name);
 199  5
             setParameterType(parameterType);
 200  4
         }
 201  
 
 202  
         /**
 203  
          * creates a Parameter with the required fields.
 204  
          */
 205  
         public static Builder create(String applicationId, String namespaceCode, String componentCode, String name, ParameterType.Builder parameterType) {
 206  16
             return new Builder(applicationId, namespaceCode, componentCode, name, parameterType);
 207  
         }
 208  
 
 209  
         /**
 210  
          * creates a Parameter from an existing {@link ParameterContract}.
 211  
          */
 212  
         public static Builder create(ParameterContract contract) {
 213  2
             Builder builder = new Builder(contract.getApplicationId(), contract.getNamespaceCode(), contract.getComponentCode(), contract.getName(), ParameterType.Builder.create(contract.getParameterType()));
 214  2
             builder.setValue(contract.getValue());
 215  2
             builder.setDescription(contract.getDescription());
 216  2
             builder.setEvaluationOperator(contract.getEvaluationOperator());
 217  2
             builder.setVersionNumber(contract.getVersionNumber());
 218  2
             builder.setObjectId(contract.getObjectId());
 219  2
             return builder;
 220  
         }
 221  
 
 222  
         public void setApplicationId(String applicationId) {
 223  18
             if (StringUtils.isBlank(applicationId)) {
 224  4
                 throw new IllegalArgumentException("applicationId is blank");
 225  
             }
 226  14
             this.applicationId = applicationId;
 227  14
         }
 228  
 
 229  
         public void setNamespaceCode(String namespaceCode) {
 230  14
             if (StringUtils.isBlank(namespaceCode)) {
 231  3
                 throw new IllegalArgumentException("namespaceCode is blank");
 232  
             }
 233  11
             this.namespaceCode = namespaceCode;
 234  11
         }
 235  
 
 236  
         public void setComponentCode(String componentCode) {
 237  11
             if (StringUtils.isBlank(componentCode)) {
 238  3
                 throw new IllegalArgumentException("componentCode is blank");
 239  
             }
 240  8
             this.componentCode = componentCode;
 241  8
         }
 242  
 
 243  
         public void setName(String name) {
 244  8
             if (StringUtils.isBlank(name)) {
 245  3
                 throw new IllegalArgumentException("name is blank");
 246  
             }
 247  5
             this.name = name;
 248  5
         }
 249  
 
 250  
         public void setParameterType(ParameterType.Builder parameterType) {
 251  5
             if (parameterType == null) {
 252  1
                 throw new IllegalArgumentException("parameterType is null");
 253  
             }
 254  4
             this.parameterType = parameterType;
 255  4
         }
 256  
 
 257  
         public void setValue(String value) {
 258  2
             this.value = value;
 259  2
         }
 260  
 
 261  
         public void setDescription(String description) {
 262  2
             this.description = description;
 263  2
         }
 264  
 
 265  
         public void setEvaluationOperator(EvaluationOperator evaluationOperator) {
 266  2
             this.evaluationOperator = evaluationOperator;
 267  2
         }
 268  
 
 269  
         public void setVersionNumber(Long versionNumber) {
 270  2
             this.versionNumber = versionNumber;
 271  2
         }
 272  
 
 273  
         public void setObjectId(String objectId) {
 274  2
             this.objectId = objectId;
 275  2
         }
 276  
 
 277  
         @Override
 278  
         public String getApplicationId() {
 279  3
             return applicationId;
 280  
         }
 281  
 
 282  
         @Override
 283  
         public String getNamespaceCode() {
 284  3
             return namespaceCode;
 285  
         }
 286  
 
 287  
         @Override
 288  
         public String getComponentCode() {
 289  3
             return componentCode;
 290  
         }
 291  
 
 292  
         @Override
 293  
         public String getName() {
 294  3
             return name;
 295  
         }
 296  
 
 297  
         @Override
 298  
         public String getValue() {
 299  3
             return value;
 300  
         }
 301  
 
 302  
         @Override
 303  
         public String getDescription() {
 304  3
             return description;
 305  
         }
 306  
 
 307  
         @Override
 308  
         public EvaluationOperator getEvaluationOperator() {
 309  3
             return evaluationOperator;
 310  
         }
 311  
 
 312  
         @Override
 313  
         public Parameter build() {
 314  3
             return new Parameter(this);
 315  
         }
 316  
 
 317  
         @Override
 318  
         public ParameterType.Builder getParameterType() {
 319  0
             return parameterType;
 320  
         }
 321  
 
 322  
         @Override
 323  
         public Long getVersionNumber() {
 324  3
             return versionNumber;
 325  
         }
 326  
 
 327  
         @Override
 328  
         public String getObjectId() {
 329  3
             return objectId;
 330  
         }
 331  
 
 332  
     }
 333  
 
 334  
     /**
 335  
      * Defines some internal constants used on this class.
 336  
      */
 337  0
     static class Constants {
 338  
         final static String ROOT_ELEMENT_NAME = "parameter";
 339  
         final static String TYPE_NAME = "ParameterType";
 340  
     }
 341  
 
 342  
     /**
 343  
      * A private class which exposes constants which define the XML element names to use
 344  
      * when this object is marshalled to XML.
 345  
      */
 346  0
     static class Elements {
 347  
         final static String APPLICATION_ID = "applicationId";
 348  
         final static String NAMESPACE_CODE = "namespaceCode";
 349  
         final static String COMPONENT_CODE = "componentCode";
 350  
         final static String NAME = "name";
 351  
         final static String VALUE = "value";
 352  
         final static String DESCRIPTION = "description";
 353  
         final static String PARAMETER_TYPE = "parameterType";
 354  
         final static String EVALUATION_OPERATOR = "evaluationOperator";
 355  
     }
 356  
 
 357  0
     public static class Cache {
 358  
         public static final String NAME = CoreConstants.Namespaces.CORE_NAMESPACE_2_0 + "/" + Parameter.Constants.TYPE_NAME;
 359  
     }
 360  
 
 361  
 }