Coverage Report - org.kuali.rice.krms.api.repository.function.FunctionDefinition
 
Classes in this File Line Coverage Branch Coverage Complexity
FunctionDefinition
100%
43/43
100%
4/4
1.462
FunctionDefinition$1
N/A
N/A
1.462
FunctionDefinition$Builder
95%
63/66
83%
15/18
1.462
FunctionDefinition$Constants
50%
1/2
N/A
1.462
FunctionDefinition$Elements
0%
0/1
N/A
1.462
 
 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.ArrayList;
 20  
 import java.util.Collection;
 21  
 import java.util.Collections;
 22  
 import java.util.List;
 23  
 
 24  
 import javax.xml.bind.annotation.XmlAccessType;
 25  
 import javax.xml.bind.annotation.XmlAccessorType;
 26  
 import javax.xml.bind.annotation.XmlAnyElement;
 27  
 import javax.xml.bind.annotation.XmlElement;
 28  
 import javax.xml.bind.annotation.XmlElementWrapper;
 29  
 import javax.xml.bind.annotation.XmlRootElement;
 30  
 import javax.xml.bind.annotation.XmlType;
 31  
 
 32  
 import org.apache.commons.lang.StringUtils;
 33  
 import org.apache.commons.lang.builder.EqualsBuilder;
 34  
 import org.apache.commons.lang.builder.HashCodeBuilder;
 35  
 import org.apache.commons.lang.builder.ToStringBuilder;
 36  
 import org.kuali.rice.core.api.CoreConstants;
 37  
 import org.kuali.rice.core.api.mo.ModelBuilder;
 38  
 import org.kuali.rice.core.api.mo.ModelObjectComplete;
 39  
 import org.kuali.rice.krms.api.repository.category.CategoryDefinition;
 40  
 import org.kuali.rice.krms.api.repository.category.CategoryDefinitionContract;
 41  
 import org.kuali.rice.krms.api.repository.type.KrmsTypeDefinition;
 42  
 import org.w3c.dom.Element;
 43  
 
 44  
 /**
 45  
  * An immutable representation of a function definition.
 46  
  * 
 47  
  * @see FunctionDefinitionContract
 48  
  * 
 49  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 50  
  *
 51  
  */
 52  
 @XmlRootElement(name = FunctionDefinition.Constants.ROOT_ELEMENT_NAME)
 53  
 @XmlAccessorType(XmlAccessType.NONE)
 54  
 @XmlType(name = FunctionDefinition.Constants.TYPE_NAME, propOrder = {
 55  
                 FunctionDefinition.Elements.ID,
 56  
                 FunctionDefinition.Elements.NAMESPACE,
 57  
                 FunctionDefinition.Elements.NAME,
 58  
                 FunctionParameterDefinition.Elements.DESCRIPTION,
 59  
                 FunctionDefinition.Elements.RETURN_TYPE,
 60  
                 FunctionDefinition.Elements.TYPE_ID,
 61  
                 FunctionDefinition.Elements.ACTIVE,
 62  
         CoreConstants.CommonElements.VERSION_NUMBER,
 63  
         FunctionDefinition.Elements.PARAMETERS,
 64  
         FunctionDefinition.Elements.CATEGORIES,
 65  
         CoreConstants.CommonElements.FUTURE_ELEMENTS
 66  
 })
 67  4
 public class FunctionDefinition implements FunctionDefinitionContract, ModelObjectComplete {
 68  
 
 69  
         private static final long serialVersionUID = 1391030685309770560L;
 70  
 
 71  
         @XmlElement(name = Elements.ID, required = false)
 72  
         private final String id;
 73  
         
 74  
         @XmlElement(name = Elements.NAMESPACE, required = true)
 75  
         private final String namespace;
 76  
         
 77  
         @XmlElement(name = Elements.NAME, required = true)
 78  
         private final String name;
 79  
         
 80  
         @XmlElement(name = Elements.DESCRIPTION, required = false)
 81  
         private final String description;
 82  
         
 83  
         @XmlElement(name = Elements.RETURN_TYPE, required = true)
 84  
         private final String returnType;
 85  
         
 86  
         @XmlElement(name = Elements.TYPE_ID, required = true)
 87  
         private final String typeId;
 88  
         
 89  
         @XmlElement(name = Elements.ACTIVE, required = true)
 90  
         private final boolean active;
 91  
         
 92  
         @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
 93  
         private final Long versionNumber;
 94  
         
 95  
         @XmlElementWrapper(name = Elements.PARAMETERS, required = false)
 96  
         @XmlElement(name = Elements.PARAMETER, required = false)
 97  
         private final List<FunctionParameterDefinition> parameters;
 98  
 
 99  
     @XmlElementWrapper(name = Elements.CATEGORIES, required = false)
 100  
     @XmlElement(name = Elements.CATEGORY, required = false)
 101  
     private final List<CategoryDefinition> categories;
 102  
         
 103  6
         @SuppressWarnings("unused")
 104  
     @XmlAnyElement
 105  
     private final Collection<Element> _futureElements = null;
 106  
         
 107  
         /**
 108  
      * Private constructor used only by JAXB.
 109  
      */
 110  2
     private FunctionDefinition() {
 111  2
             this.id = null;
 112  2
             this.namespace = null;
 113  2
             this.name = null;
 114  2
             this.description = null;
 115  2
             this.returnType = null;
 116  2
             this.typeId = null;
 117  2
             this.active = false;
 118  2
             this.versionNumber = null;
 119  2
             this.parameters = null;
 120  2
         this.categories = null;
 121  2
     }
 122  
     
 123  4
     private FunctionDefinition(Builder builder) {
 124  4
             this.id = builder.getId();
 125  4
             this.namespace = builder.getNamespace();
 126  4
             this.name = builder.getName();
 127  4
             this.description = builder.getDescription();
 128  4
             this.returnType = builder.getReturnType();
 129  4
             this.typeId = builder.getTypeId();
 130  4
             this.active = builder.isActive();
 131  4
             this.versionNumber = builder.getVersionNumber();
 132  4
             this.parameters = new ArrayList<FunctionParameterDefinition>();
 133  4
             for (FunctionParameterDefinition.Builder parameter : builder.getParameters()) {
 134  6
                     this.parameters.add(parameter.build());
 135  
             }
 136  4
         this.categories = new ArrayList<CategoryDefinition>();
 137  4
         for (CategoryDefinition.Builder category : builder.getCategories()) {
 138  6
             this.categories.add(category.build());
 139  
         }
 140  4
     }
 141  
     
 142  
         @Override
 143  
         public String getId() {
 144  2
                 return id;
 145  
         }
 146  
 
 147  
         @Override
 148  
         public String getNamespace() {
 149  2
                 return namespace;
 150  
         }
 151  
 
 152  
         @Override
 153  
         public String getName() {
 154  2
                 return name;
 155  
         }
 156  
 
 157  
         @Override
 158  
         public String getDescription() {
 159  2
                 return description;
 160  
         }
 161  
         
 162  
         @Override
 163  
         public String getReturnType() {
 164  2
                 return returnType;
 165  
         }
 166  
 
 167  
         @Override
 168  
         public String getTypeId() {
 169  2
                 return typeId;
 170  
         }
 171  
 
 172  
         @Override
 173  
         public boolean isActive() {
 174  2
                 return active;
 175  
         }
 176  
         
 177  
         @Override
 178  
         public Long getVersionNumber() {
 179  2
                 return versionNumber;
 180  
         }
 181  
         
 182  
         @Override
 183  
         public List<FunctionParameterDefinition> getParameters() {
 184  4
                 return Collections.unmodifiableList(parameters);
 185  
         }
 186  
 
 187  
     @Override
 188  
     public List<CategoryDefinition> getCategories() {
 189  2
         return Collections.unmodifiableList(categories);
 190  
     }
 191  
 
 192  
         /**
 193  
          * A builder which can be used to construct {@link FunctionDefinition}
 194  
          * instances.  Enforces the constraints of the {@link FunctionDefinitionContract}.
 195  
          * 
 196  
          * @author Kuali Rice Team (rice.collab@kuali.org)
 197  
          *
 198  
          */
 199  4
         public static final class Builder implements FunctionDefinitionContract, ModelBuilder, Serializable  {
 200  
                         
 201  
             private static final long serialVersionUID = -4470376239998290245L;
 202  
             
 203  
                 private String id;
 204  
             private String namespace;
 205  
             private String name;
 206  
             private String description;
 207  
             private String returnType;
 208  
             private String typeId;
 209  
             private boolean active;
 210  
             private Long versionNumber;
 211  
             private List<FunctionParameterDefinition.Builder> parameters;
 212  
         private List<CategoryDefinition.Builder> categories;
 213  
             
 214  16
         private Builder(String namespace, String name, String returnType, String typeId) {
 215  16
                 setNamespace(namespace);
 216  13
                 setName(name);
 217  10
                 setReturnType(returnType);
 218  7
                 setTypeId(typeId);
 219  4
                 setActive(true);
 220  4
                 setParameters(new ArrayList<FunctionParameterDefinition.Builder>());
 221  4
             setCategories(new ArrayList<CategoryDefinition.Builder>());
 222  4
         }
 223  
         
 224  
         /**
 225  
          * Creates a function definition builder with the given required values.  This builder
 226  
          * is the only means by which a {@link FunctionDefinition} object should be created.
 227  
          * 
 228  
          * <p>Will default the active flag to true.
 229  
          * 
 230  
          * @param namespace the namespace of the function definition to create, must not be null or blank
 231  
          * @param name the name of the function definition to create, must not be null or blank
 232  
          * @param returnType the return type of the function definition to create, must not be null or blank
 233  
          * @param typeId the return type id of the function definition to create, must not be null or blank
 234  
          * 
 235  
          * @return a builder with the required values already initialized
 236  
          * 
 237  
          * @throws IllegalArgumentException if any of the given arguments is null or blank
 238  
          */
 239  
         public static Builder create(String namespace, String name, String returnType, String typeId) {
 240  16
                 return new Builder(namespace, name, returnType, typeId);
 241  
         }
 242  
         
 243  
         /**
 244  
          * Creates and populates a builder with the data on the given {@link FunctionDefinitionContract}.
 245  
          * This is similar in nature to a "copy constructor" for {@link FunctionDefinition}.
 246  
          * 
 247  
          * @param contract an object implementing the {@link FunctionDefinitionContract} from which
 248  
          * to copy property values
 249  
          *  
 250  
          * @return a builder with the values from the contract already initialized
 251  
          * 
 252  
          * @throws IllegalArgumentException if the given contract is null
 253  
          */
 254  
         public static Builder create(FunctionDefinitionContract contract) {
 255  3
                 if (contract == null) {
 256  0
                         throw new IllegalArgumentException("contract was null");
 257  
                 }
 258  3
                 Builder builder = create(contract.getNamespace(), contract.getName(), contract.getReturnType(), contract.getTypeId());
 259  3
                 builder.setId(contract.getId());
 260  3
                 builder.setDescription(contract.getDescription());
 261  3
                 builder.setActive(contract.isActive());
 262  3
                 builder.setVersionNumber(contract.getVersionNumber());
 263  3
                 for (FunctionParameterDefinitionContract parameter : contract.getParameters()) {
 264  6
                         builder.getParameters().add(FunctionParameterDefinition.Builder.create(parameter));
 265  
                 }
 266  3
             for (CategoryDefinitionContract category : contract.getCategories()) {
 267  6
                 builder.getCategories().add(CategoryDefinition.Builder.create(category));
 268  
             }
 269  3
                 return builder;
 270  
         }
 271  
 
 272  
         @Override
 273  
         public FunctionDefinition build() {
 274  4
                 return new FunctionDefinition(this);
 275  
         }
 276  
         
 277  
         @Override
 278  
                 public String getId() {
 279  4
                         return this.id;
 280  
                 }
 281  
 
 282  
         /**
 283  
          * Sets the id for the function definition that will be returned by this builder.
 284  
          * 
 285  
          * @param id the function definition id to set
 286  
          */
 287  
                 public void setId(String id) {
 288  3
                         this.id = id;
 289  3
                 }
 290  
 
 291  
                 @Override
 292  
                 public String getNamespace() {
 293  4
                         return this.namespace;
 294  
                 }
 295  
 
 296  
         /**
 297  
          * Sets the namespace code for the function definition that will be returned by this builder.
 298  
          * The namespace must not be null or blank.
 299  
          * 
 300  
          * @param namespace the namespace code to set on this builder, must not be null or blank
 301  
          * 
 302  
          * @throws IllegalArgumentException if the given namespace is null or blank
 303  
          */
 304  
                 public void setNamespace(String namespace) {
 305  16
                         if (StringUtils.isBlank(namespace)) {
 306  3
                                 throw new IllegalArgumentException("namespace was blank");
 307  
                         }
 308  13
                         this.namespace = namespace;
 309  13
                 }
 310  
 
 311  
                 @Override
 312  
                 public String getName() {
 313  4
                         return this.name;
 314  
                 }
 315  
 
 316  
                 /**
 317  
          * Sets the name for the function definition that will be returned by this builder.
 318  
          * The name must not be null or blank.
 319  
          * 
 320  
          * @param name the name to set on this builder, must not be null or blank
 321  
          * 
 322  
          * @throws IllegalArgumentException if the given name is null or blank
 323  
          */
 324  
                 public void setName(String name) {
 325  13
                         if (StringUtils.isBlank(name)) {
 326  3
                                 throw new IllegalArgumentException("name was blank");
 327  
                         }
 328  10
                         this.name = name;
 329  10
                 }
 330  
                 
 331  
                 @Override
 332  
                 public String getDescription() {
 333  4
                         return this.description;
 334  
                 }
 335  
 
 336  
         /**
 337  
          * Sets the description for the function definition that will be returned by this builder.
 338  
          * 
 339  
          * @param description the description to set on this builder
 340  
          */
 341  
                 public void setDescription(String description) {
 342  3
                         this.description = description;
 343  3
                 }
 344  
 
 345  
                 @Override
 346  
                 public String getReturnType() {
 347  4
                         return this.returnType;
 348  
                 }
 349  
 
 350  
                 /**
 351  
          * Sets the return type for the function definition that will be
 352  
          * returned by this builder.  This can be one of a set of "built-in"
 353  
          * data types or a custom datatype represented as a fully qualified
 354  
          * java class name.  The returnType must not be null or blank.
 355  
          * 
 356  
          * @param returnType the returnType to set on this builder, must not be null or blank
 357  
          * 
 358  
          * @throws IllegalArgumentException if the given returnType is null or blank
 359  
          */
 360  
                 public void setReturnType(String returnType) {
 361  10
                         if (StringUtils.isBlank(returnType)) {
 362  3
                                 throw new IllegalArgumentException("returnType was blank");
 363  
                         }
 364  7
                         this.returnType = returnType;
 365  7
                 }
 366  
 
 367  
                 @Override
 368  
                 public String getTypeId() {
 369  4
                         return this.typeId;
 370  
                 }
 371  
 
 372  
                 /**
 373  
          * Sets the id of the {@link KrmsTypeDefinition} which defines the
 374  
          * actual implementation of this function.  The typeId must not be
 375  
          * null or blank.
 376  
          * 
 377  
          * @param typeId the typeId to set on this builder, must not be null or blank
 378  
          * 
 379  
          * @throws IllegalArgumentException if the given typeId is null or blank
 380  
          */
 381  
                 public void setTypeId(String typeId) {
 382  7
                         if (StringUtils.isBlank(typeId)) {
 383  3
                                 throw new IllegalArgumentException("typeId was blank");
 384  
                         }
 385  4
                         this.typeId = typeId;
 386  4
                 }
 387  
 
 388  
                 @Override
 389  
                 public boolean isActive() {
 390  4
                         return this.active;
 391  
                 }
 392  
 
 393  
                 /**
 394  
          * Sets the active flag for the function definition that will be
 395  
          * returned by this builder.
 396  
          * 
 397  
          * @param active the active flag to set
 398  
          */
 399  
                 public void setActive(boolean active) {
 400  7
                         this.active = active;
 401  7
                 }
 402  
 
 403  
                 @Override
 404  
                 public Long getVersionNumber() {
 405  4
                         return this.versionNumber;
 406  
                 }
 407  
 
 408  
                 /**
 409  
          * Sets the version number for the function definition that will be
 410  
          * returned by this builder.
 411  
          * 
 412  
          * <p>In general, this value should not be manually set on the builder,
 413  
          * but rather copied from an existing {@link FunctionDefinitionContract} when
 414  
          * invoking {@link Builder#create(FunctionDefinitionContract)}.
 415  
          * 
 416  
          * @param versionNumber the version number to set
 417  
          */
 418  
                 public void setVersionNumber(Long versionNumber) {
 419  3
                         this.versionNumber = versionNumber;
 420  3
                 }
 421  
                 
 422  
                 @Override
 423  
                 public List<FunctionParameterDefinition.Builder> getParameters() {
 424  10
                         return this.parameters;
 425  
                 }
 426  
 
 427  
                 /**
 428  
          * Sets the parameters for the function definition that will be returned by this builder.
 429  
          * This list is a list of builders for each of the {@link FunctionParameterDefinition}
 430  
          * instances that will form the parameters of this function definition.  The given list
 431  
          * must not be null.
 432  
          * 
 433  
          * @param parameters a list of builders for the parameters which will be specified on this function definition
 434  
          * 
 435  
          * @throws IllegalArgumentException if the given parameters list is null 
 436  
          */
 437  
                 public void setParameters(List<FunctionParameterDefinition.Builder> parameters) {
 438  4
                         if (parameters == null) {
 439  0
                                 throw new IllegalArgumentException("parameters was null");
 440  
                         }
 441  4
                         this.parameters = parameters;
 442  4
                 }
 443  
 
 444  
         @Override
 445  
         public List<CategoryDefinition.Builder> getCategories() {
 446  10
             return this.categories;
 447  
         }
 448  
 
 449  
         /**
 450  
          * Sets the category for the function definition that will be returned by this builder.
 451  
          * This list is a list of builders for each of the {@link CategoryDefinition}
 452  
          * instances that will form the categories of this function definition.  The given list
 453  
          * must not be null.
 454  
          *
 455  
          * @param categories a list of builders for the categories which will be specified on this function definition
 456  
          *
 457  
          * @throws IllegalArgumentException if the given categories list is null
 458  
          */
 459  
         public void setCategories(List<CategoryDefinition.Builder> categories) {
 460  4
             if (categories == null) {
 461  0
                 throw new IllegalArgumentException("categories was null");
 462  
             }
 463  4
             this.categories = categories;
 464  4
         }
 465  
 
 466  
         }
 467  
         
 468  
         @Override
 469  
     public int hashCode() {
 470  3
         return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 471  
     }
 472  
 
 473  
     @Override
 474  
     public boolean equals(Object obj) {
 475  2
         return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 476  
     }
 477  
 
 478  
     @Override
 479  
     public String toString() {
 480  1
         return ToStringBuilder.reflectionToString(this);
 481  
     }
 482  
         
 483  
         /**
 484  
      * Defines some internal constants used on this class.
 485  
      */
 486  0
     static class Constants {
 487  
         final static String ROOT_ELEMENT_NAME = "function";
 488  
         final static String TYPE_NAME = "FunctionType";
 489  1
         final static String[] HASH_CODE_EQUALS_EXCLUDE = {CoreConstants.CommonElements.FUTURE_ELEMENTS};
 490  
     }
 491  
 
 492  
     /**
 493  
      * A private class which exposes constants which define the XML element names to use
 494  
      * when this object is marshalled to XML.
 495  
      */
 496  0
     static class Elements {
 497  
         final static String ID = "id";
 498  
         final static String NAMESPACE = "namespace";
 499  
         final static String NAME = "name";
 500  
         final static String DESCRIPTION = "description";
 501  
         final static String RETURN_TYPE = "returnType";
 502  
         final static String TYPE_ID = "typeId";
 503  
         final static String ACTIVE = "active";
 504  
         final static String PARAMETERS = "parameters";
 505  
         final static String PARAMETER = "parameter";
 506  
         final static String CATEGORIES = "categories";
 507  
         final static String CATEGORY = "category";
 508  
     }
 509  
     
 510  
 }