Coverage Report - org.kuali.rice.krms.api.repository.function.FunctionParameterDefinition
 
Classes in this File Line Coverage Branch Coverage Complexity
FunctionParameterDefinition
93%
28/30
N/A
1.3
FunctionParameterDefinition$1
N/A
N/A
1.3
FunctionParameterDefinition$Builder
88%
39/44
50%
5/10
1.3
FunctionParameterDefinition$Constants
50%
1/2
N/A
1.3
FunctionParameterDefinition$Elements
0%
0/1
N/A
1.3
 
 1  
 /*
 2  
  * Copyright 2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 1.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/ecl1.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.krms.api.repository.function;
 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  
 
 28  
 import org.apache.commons.lang.StringUtils;
 29  
 import org.apache.commons.lang.builder.EqualsBuilder;
 30  
 import org.apache.commons.lang.builder.HashCodeBuilder;
 31  
 import org.apache.commons.lang.builder.ToStringBuilder;
 32  
 import org.kuali.rice.core.api.CoreConstants;
 33  
 import org.kuali.rice.core.api.mo.ModelBuilder;
 34  
 import org.kuali.rice.core.api.mo.ModelObjectComplete;
 35  
 import org.kuali.rice.krms.api.repository.proposition.PropositionParameter.Elements;
 36  
 import org.w3c.dom.Element;
 37  
 
 38  
 /**
 39  
  * An immutable representation of a function parameter definition.
 40  
  * 
 41  
  * @see FunctionParameterDefinitionContract
 42  
  * 
 43  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 44  
  *
 45  
  */
 46  
 @XmlRootElement(name = FunctionParameterDefinition.Constants.ROOT_ELEMENT_NAME)
 47  
 @XmlAccessorType(XmlAccessType.NONE)
 48  
 @XmlType(name = FunctionParameterDefinition.Constants.TYPE_NAME, propOrder = {
 49  
                 FunctionParameterDefinition.Elements.ID,
 50  
                 FunctionParameterDefinition.Elements.NAME,
 51  
                 FunctionParameterDefinition.Elements.DESCRIPTION,
 52  
                 FunctionParameterDefinition.Elements.PARAMETER_TYPE,
 53  
                 FunctionParameterDefinition.Elements.SEQUENCE,
 54  
                 FunctionParameterDefinition.Elements.FUNCTION_ID,
 55  
         CoreConstants.CommonElements.VERSION_NUMBER,
 56  
         CoreConstants.CommonElements.FUTURE_ELEMENTS
 57  
 })
 58  6
 public class FunctionParameterDefinition implements FunctionParameterDefinitionContract, ModelObjectComplete {
 59  
 
 60  
         private static final long serialVersionUID = 1391030685309770560L;
 61  
 
 62  
         @XmlElement(name = Elements.ID, required = false)
 63  
         private final String id;
 64  
                 
 65  
         @XmlElement(name = Elements.NAME, required = true)
 66  
         private final String name;
 67  
         
 68  
         @XmlElement(name = Elements.DESCRIPTION, required = false)
 69  
         private final String description;
 70  
         
 71  
         @XmlElement(name = Elements.TYPE, required = true)
 72  
         private final String parameterType;
 73  
         
 74  
         @XmlElement(name = Elements.FUNCTION_ID, required = true)
 75  
         private final String functionId;
 76  
         
 77  
         @XmlElement(name = Elements.SEQUENCE, required=true)
 78  
         private Integer sequenceNumber;
 79  
 
 80  
         @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
 81  
         private final Long versionNumber;
 82  
         
 83  10
         @SuppressWarnings("unused")
 84  
     @XmlAnyElement
 85  
     private final Collection<Element> _futureElements = null;
 86  
         
 87  
         /**
 88  
      * Private constructor used only by JAXB.
 89  
      */
 90  4
     private FunctionParameterDefinition() {
 91  4
             this.id = null;
 92  4
             this.name = null;
 93  4
             this.description = null;
 94  4
             this.parameterType = null;
 95  4
             this.functionId = null;
 96  4
             this.sequenceNumber = null;
 97  4
             this.versionNumber = null;
 98  4
     }
 99  
     
 100  6
     private FunctionParameterDefinition(Builder builder) {
 101  6
             this.id = builder.getId();
 102  6
             this.name = builder.getName();
 103  6
             this.description = builder.getDescription();
 104  6
             this.parameterType = builder.getParameterType();
 105  6
             this.functionId = builder.getFunctionId();
 106  6
             this.sequenceNumber = builder.getSequenceNumber();
 107  6
             this.versionNumber = builder.getVersionNumber();
 108  6
     }
 109  
     
 110  
         @Override
 111  
         public String getId() {
 112  2
                 return id;
 113  
         }
 114  
 
 115  
         @Override
 116  
         public String getName() {
 117  2
                 return name;
 118  
         }
 119  
 
 120  
         @Override
 121  
         public String getDescription() {
 122  2
                 return description;
 123  
         }
 124  
         
 125  
         @Override
 126  
         public String getParameterType() {
 127  2
                 return parameterType;
 128  
         }
 129  
         
 130  
         @Override
 131  
         public String getFunctionId() {
 132  0
                 return functionId;
 133  
         }
 134  
         
 135  
         @Override
 136  
         public Long getVersionNumber() {
 137  2
                 return versionNumber;
 138  
         }
 139  
 
 140  
         @Override
 141  
         public Integer getSequenceNumber() {
 142  0
                 return sequenceNumber;
 143  
         }
 144  
 
 145  
         /**
 146  
          * A builder which can be used to construct {@link FunctionParameterDefinition}
 147  
          * instances.  Enforces the constraints of the {@link FunctionParameterDefinitionContract}.
 148  
          * 
 149  
          * @author Kuali Rice Team (rice.collab@kuali.org)
 150  
          *
 151  
          */
 152  0
         public static final class Builder implements FunctionParameterDefinitionContract, ModelBuilder, Serializable  {
 153  
                         
 154  
             private static final long serialVersionUID = -4470376239998290245L;
 155  
             
 156  
                 private String id;
 157  
             private String name;
 158  
             private String description;
 159  
             private String functionId;
 160  
             private String parameterType;
 161  
             private Integer sequenceNumber;
 162  
             private Long versionNumber;
 163  
             
 164  12
         private Builder(String name, String type, Integer sequenceNumber) {
 165  12
                 setName(name);
 166  12
                 setParameterType(type);
 167  12
                 setSequenceNumber(sequenceNumber);
 168  12
         }
 169  
         
 170  
         /**
 171  
          * Creates a function parameter definition builder with the given required values.  This builder
 172  
          * is the only means by which a {@link FunctionParameterDefinition} object should be created.
 173  
          * 
 174  
          * @param name the name of the function parameter definition to create, must not be null or blank
 175  
          * @param type the type of the function parameter definition to create, must not be null or blank
 176  
          * 
 177  
          * @return a builder with the required values already initialized
 178  
          * 
 179  
          * @throws IllegalArgumentException if any of the given arguments is null or blank
 180  
          */
 181  
         public static Builder create(String name, String type, Integer sequenceNumber) {
 182  12
                 return new Builder(name, type, sequenceNumber);
 183  
         }
 184  
         
 185  
         /**
 186  
          * Creates and populates a builder with the data on the given {@link FunctionParameterDefinitionContract}.
 187  
          * This is similar in nature to a "copy constructor" for {@link FunctionParameterDefinition}.
 188  
          * 
 189  
          * @param contract an object implementing the {@link FunctionParameterDefinitionContract} from which
 190  
          * to copy property values
 191  
          *  
 192  
          * @return a builder with the values from the contract already initialized
 193  
          * 
 194  
          * @throws IllegalArgumentException if the given contract is null
 195  
          */
 196  
         public static Builder create(FunctionParameterDefinitionContract contract) {
 197  12
                 if (contract == null) {
 198  0
                         throw new IllegalArgumentException("contract was null");
 199  
                 }
 200  12
                 Builder builder = create(contract.getName(), contract.getParameterType(), contract.getSequenceNumber());
 201  12
                 builder.setId(contract.getId());
 202  12
                 builder.setDescription(contract.getDescription());
 203  12
                 builder.setParameterType(contract.getParameterType());
 204  12
                 builder.setFunctionId(contract.getFunctionId());
 205  12
                 builder.setVersionNumber(contract.getVersionNumber());
 206  12
                 return builder;
 207  
         }
 208  
 
 209  
         @Override
 210  
         public FunctionParameterDefinition build() {
 211  6
                 return new FunctionParameterDefinition(this);
 212  
         }
 213  
         
 214  
         @Override
 215  
                 public String getId() {
 216  12
                         return this.id;
 217  
                 }
 218  
 
 219  
         /**
 220  
          * Sets the id for the function parameter definition that will be returned by this builder.
 221  
          * 
 222  
          * @param id the function parameter definition id to set
 223  
          */
 224  
                 public void setId(String id) {
 225  12
                         this.id = id;
 226  12
                 }
 227  
 
 228  
                 @Override
 229  
                 public String getName() {
 230  12
                         return this.name;
 231  
                 }
 232  
 
 233  
                 /**
 234  
          * Sets the name for the function parameter definition that will be returned by this builder.
 235  
          * The name must not be null or blank.
 236  
          * 
 237  
          * @param name the name to set on this builder, must not be null or blank
 238  
          */
 239  
                 public void setName(String name) {
 240  12
                         if (StringUtils.isBlank(name)) {
 241  0
                                 throw new IllegalArgumentException("name was blank");
 242  
                         }
 243  12
                         this.name = name;
 244  12
                 }
 245  
                 
 246  
                 @Override
 247  
                 public String getDescription() {
 248  12
                         return this.description;
 249  
                 }
 250  
 
 251  
         /**
 252  
          * Sets the description for the function parameter definition that will be returned by this builder.
 253  
          * 
 254  
          * @param description the description to set on this builder
 255  
          */
 256  
                 public void setDescription(String description) {
 257  12
                         this.description = description;
 258  12
                 }
 259  
 
 260  
                 @Override
 261  
                 public String getParameterType() {
 262  18
                         return this.parameterType;
 263  
                 }
 264  
 
 265  
                 /**
 266  
          * Sets the type for the function parameter definition that will be
 267  
          * returned by this builder.  This can be one of a set of "built-in"
 268  
          * data types or a custom datatype represented as a fully qualified
 269  
          * java class name.  The type must not be null or blank.
 270  
          * 
 271  
          * @param type the type to set on this builder, must not be null or blank
 272  
          */
 273  
                 public void setParameterType(String type) {
 274  24
                         if (StringUtils.isBlank(type)) {
 275  0
                                 throw new IllegalArgumentException("type was blank");
 276  
                         }
 277  24
                         this.parameterType = type;
 278  24
                 }
 279  
 
 280  
                 @Override
 281  
                 public String getFunctionId() {
 282  12
                         return this.functionId;
 283  
                 }
 284  
 
 285  
                 /**
 286  
          * Sets the type for the function id
 287  
          * If provided, the function id must be non-blank.
 288  
          * Must allow id to be null, to prevent chicken/egg problems.
 289  
          * 
 290  
          * @param type the type to set on this builder, must be either null or non-blank
 291  
          */
 292  
                 public void setFunctionId(String functionId) {
 293  12
                         if (functionId != null && StringUtils.isBlank(functionId)) {
 294  0
                                 throw new IllegalArgumentException("functionId must be null or non-blank");
 295  
                         }
 296  12
                         this.functionId = functionId;
 297  12
                 }
 298  
 
 299  
                 @Override
 300  
                 public Integer getSequenceNumber() {
 301  12
                         return this.sequenceNumber;
 302  
                 }
 303  
 
 304  
                 /**
 305  
          * Sets the sequence number for the function parameter definition that
 306  
          * will be returned by this builder. This is the position in the functions
 307  
          * parameter list.
 308  
          * 
 309  
          * @param sequenceNumber the position of the parameter in the function parameter list
 310  
          */
 311  
                 public void setSequenceNumber(Integer sequenceNumber) {
 312  12
                         this.sequenceNumber = sequenceNumber;
 313  12
                 }
 314  
 
 315  
                 @Override
 316  
                 public Long getVersionNumber() {
 317  12
                         return this.versionNumber;
 318  
                 }
 319  
 
 320  
                 /**
 321  
          * Sets the version number for the function parameter definition that
 322  
          * will be returned by this builder.
 323  
          * 
 324  
          * <p>In general, this value should not be manually set on the builder,
 325  
          * but rather copied from an existing {@link FunctionParameterDefinitionContract} when
 326  
          * invoking {@link Builder#create(FunctionParameterDefinitionContract)}.
 327  
          * 
 328  
          * @param versionNumber the version number to set
 329  
          */
 330  
                 public void setVersionNumber(Long versionNumber) {
 331  12
                         this.versionNumber = versionNumber;
 332  12
                 }
 333  
 
 334  
         }
 335  
         
 336  
         @Override
 337  
     public int hashCode() {
 338  18
         return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 339  
     }
 340  
 
 341  
     @Override
 342  
     public boolean equals(Object obj) {
 343  4
         return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 344  
     }
 345  
 
 346  
     @Override
 347  
     public String toString() {
 348  2
         return ToStringBuilder.reflectionToString(this);
 349  
     }
 350  
         
 351  
         /**
 352  
      * Defines some internal constants used on this class.
 353  
      */
 354  0
     static class Constants {
 355  
         final static String ROOT_ELEMENT_NAME = "functionParameter";
 356  
         final static String TYPE_NAME = "FunctionParameterType";
 357  1
         final static String[] HASH_CODE_EQUALS_EXCLUDE = {CoreConstants.CommonElements.FUTURE_ELEMENTS};
 358  
     }
 359  
 
 360  
     /**
 361  
      * A private class which exposes constants which define the XML element names to use
 362  
      * when this object is marshalled to XML.
 363  
      */
 364  0
     static class Elements {
 365  
         final static String ID = "id";
 366  
         final static String NAME = "name";
 367  
         final static String DESCRIPTION = "description";
 368  
         final static String PARAMETER_TYPE = "parameterType";
 369  
         final static String TYPE = "type";
 370  
         final static String FUNCTION_ID = "functionId";
 371  
                 final static String SEQUENCE = "sequenceNumber";
 372  
     }
 373  
     
 374  
 }