Coverage Report - org.kuali.rice.core.api.parameter.Parameter
 
Classes in this File Line Coverage Branch Coverage Complexity
Parameter
0%
0/38
0%
0/2
1.306
Parameter$1
N/A
N/A
1.306
Parameter$Builder
0%
0/57
0%
0/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  0
 @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  0
 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  0
     @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  0
     private Parameter() {
 100  0
         this.applicationId = null;
 101  0
         this.namespaceCode = null;
 102  0
         this.componentCode = null;
 103  0
         this.name = null;
 104  0
         this.value = null;
 105  0
         this.description = null;
 106  0
         this.parameterType = null;
 107  0
         this.evaluationOperator = null;
 108  0
         this.versionNumber = null;
 109  0
         this.objectId = null;
 110  0
     }
 111  
 
 112  0
     private Parameter(Builder builder) {
 113  0
         applicationId = builder.getApplicationId();
 114  0
         namespaceCode = builder.getNamespaceCode();
 115  0
         componentCode = builder.getComponentCode();
 116  0
         name = builder.getName();
 117  0
         value = builder.getValue();
 118  0
         description = builder.getDescription();
 119  0
         parameterType = builder.parameterType.build();
 120  0
         EvaluationOperator evaluationOperatorEnum = builder.getEvaluationOperator();
 121  0
         evaluationOperator = evaluationOperatorEnum == null ? null : evaluationOperatorEnum.getCode(); 
 122  0
         versionNumber = builder.getVersionNumber();
 123  0
         objectId = builder.getObjectId();
 124  0
     }
 125  
 
 126  
     @Override
 127  
     public String getApplicationId() {
 128  0
         return applicationId;
 129  
     }
 130  
 
 131  
     @Override
 132  
     public String getNamespaceCode() {
 133  0
         return namespaceCode;
 134  
     }
 135  
 
 136  
     @Override
 137  
     public String getComponentCode() {
 138  0
         return componentCode;
 139  
     }
 140  
 
 141  
     @Override
 142  
     public String getName() {
 143  0
         return name;
 144  
     }
 145  
 
 146  
     @Override
 147  
     public String getValue() {
 148  0
         return value;
 149  
     }
 150  
 
 151  
     @Override
 152  
     public String getDescription() {
 153  0
         return description;
 154  
     }
 155  
 
 156  
     @Override
 157  
     public ParameterType getParameterType() {
 158  0
         return parameterType;
 159  
     }
 160  
 
 161  
     @Override
 162  
     public EvaluationOperator getEvaluationOperator() {
 163  0
         return EvaluationOperator.fromCode(evaluationOperator);
 164  
     }
 165  
 
 166  
     @Override
 167  
     public Long getVersionNumber() {
 168  0
         return versionNumber;
 169  
     }
 170  
 
 171  
     @Override
 172  
     public String getObjectId() {
 173  0
         return objectId;
 174  
     }
 175  
 
 176  
     /**
 177  
      * This builder constructs an Parameter enforcing the constraints of the {@link ParameterContract}.
 178  
      */
 179  0
     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  0
         private Builder(String applicationId, String namespaceCode, String componentCode, String name, ParameterType.Builder parameterType) {
 195  0
             setApplicationId(applicationId);
 196  0
             setNamespaceCode(namespaceCode);
 197  0
             setComponentCode(componentCode);
 198  0
             setName(name);
 199  0
             setParameterType(parameterType);
 200  0
         }
 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  0
             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  0
             Builder builder = new Builder(contract.getApplicationId(), contract.getNamespaceCode(), contract.getComponentCode(), contract.getName(), ParameterType.Builder.create(contract.getParameterType()));
 214  0
             builder.setValue(contract.getValue());
 215  0
             builder.setDescription(contract.getDescription());
 216  0
             builder.setEvaluationOperator(contract.getEvaluationOperator());
 217  0
             builder.setVersionNumber(contract.getVersionNumber());
 218  0
             builder.setObjectId(contract.getObjectId());
 219  0
             return builder;
 220  
         }
 221  
 
 222  
         public void setApplicationId(String applicationId) {
 223  0
             if (StringUtils.isBlank(applicationId)) {
 224  0
                 throw new IllegalArgumentException("applicationId is blank");
 225  
             }
 226  0
             this.applicationId = applicationId;
 227  0
         }
 228  
 
 229  
         public void setNamespaceCode(String namespaceCode) {
 230  0
             if (StringUtils.isBlank(namespaceCode)) {
 231  0
                 throw new IllegalArgumentException("namespaceCode is blank");
 232  
             }
 233  0
             this.namespaceCode = namespaceCode;
 234  0
         }
 235  
 
 236  
         public void setComponentCode(String componentCode) {
 237  0
             if (StringUtils.isBlank(componentCode)) {
 238  0
                 throw new IllegalArgumentException("componentCode is blank");
 239  
             }
 240  0
             this.componentCode = componentCode;
 241  0
         }
 242  
 
 243  
         public void setName(String name) {
 244  0
             if (StringUtils.isBlank(name)) {
 245  0
                 throw new IllegalArgumentException("name is blank");
 246  
             }
 247  0
             this.name = name;
 248  0
         }
 249  
 
 250  
         public void setParameterType(ParameterType.Builder parameterType) {
 251  0
             if (parameterType == null) {
 252  0
                 throw new IllegalArgumentException("parameterType is null");
 253  
             }
 254  0
             this.parameterType = parameterType;
 255  0
         }
 256  
 
 257  
         public void setValue(String value) {
 258  0
             this.value = value;
 259  0
         }
 260  
 
 261  
         public void setDescription(String description) {
 262  0
             this.description = description;
 263  0
         }
 264  
 
 265  
         public void setEvaluationOperator(EvaluationOperator evaluationOperator) {
 266  0
             this.evaluationOperator = evaluationOperator;
 267  0
         }
 268  
 
 269  
         public void setVersionNumber(Long versionNumber) {
 270  0
             this.versionNumber = versionNumber;
 271  0
         }
 272  
 
 273  
         public void setObjectId(String objectId) {
 274  0
             this.objectId = objectId;
 275  0
         }
 276  
 
 277  
         @Override
 278  
         public String getApplicationId() {
 279  0
             return applicationId;
 280  
         }
 281  
 
 282  
         @Override
 283  
         public String getNamespaceCode() {
 284  0
             return namespaceCode;
 285  
         }
 286  
 
 287  
         @Override
 288  
         public String getComponentCode() {
 289  0
             return componentCode;
 290  
         }
 291  
 
 292  
         @Override
 293  
         public String getName() {
 294  0
             return name;
 295  
         }
 296  
 
 297  
         @Override
 298  
         public String getValue() {
 299  0
             return value;
 300  
         }
 301  
 
 302  
         @Override
 303  
         public String getDescription() {
 304  0
             return description;
 305  
         }
 306  
 
 307  
         @Override
 308  
         public EvaluationOperator getEvaluationOperator() {
 309  0
             return evaluationOperator;
 310  
         }
 311  
 
 312  
         @Override
 313  
         public Parameter build() {
 314  0
             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  0
             return versionNumber;
 325  
         }
 326  
 
 327  
         @Override
 328  
         public String getObjectId() {
 329  0
             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  
 }