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