Coverage Report - org.kuali.rice.core.api.parameter.ParameterKey
 
Classes in this File Line Coverage Branch Coverage Complexity
ParameterKey
79%
23/29
100%
8/8
1.8
ParameterKey$Constants
50%
1/2
N/A
1.8
ParameterKey$Elements
0%
0/1
N/A
1.8
 
 1  
 /*
 2  
  * Copyright 2006-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  
 
 17  
 package org.kuali.rice.core.api.parameter;
 18  
 
 19  
 import org.apache.commons.lang.StringUtils;
 20  
 import org.apache.commons.lang.builder.EqualsBuilder;
 21  
 import org.apache.commons.lang.builder.HashCodeBuilder;
 22  
 import org.apache.commons.lang.builder.ToStringBuilder;
 23  
 import org.kuali.rice.core.api.CoreConstants;
 24  
 import org.w3c.dom.Element;
 25  
 
 26  
 import javax.xml.bind.annotation.XmlAccessType;
 27  
 import javax.xml.bind.annotation.XmlAccessorType;
 28  
 import javax.xml.bind.annotation.XmlAnyElement;
 29  
 import javax.xml.bind.annotation.XmlElement;
 30  
 import javax.xml.bind.annotation.XmlRootElement;
 31  
 import javax.xml.bind.annotation.XmlType;
 32  
 import java.io.Serializable;
 33  
 import java.util.Collection;
 34  
 
 35  
 /**
 36  
 *  This class represents the 4-part key which uniquely identifies a parameter.
 37  
 *  
 38  
 *  @see ParameterContract
 39  
 *  @see Parameter
 40  
 */
 41  
 @XmlRootElement(name = ParameterKey.Constants.ROOT_ELEMENT_NAME)
 42  
 @XmlAccessorType(XmlAccessType.NONE)
 43  
 @XmlType(name = ParameterKey.Constants.TYPE_NAME, propOrder = {
 44  
     ParameterKey.Elements.APPLICATION_ID,
 45  
     ParameterKey.Elements.NAMESPACE_CODE,
 46  
     ParameterKey.Elements.COMPONENT_CODE,
 47  
     ParameterKey.Elements.NAME,
 48  
     CoreConstants.CommonElements.FUTURE_ELEMENTS
 49  
 })
 50  
 public final class ParameterKey implements Serializable {
 51  
 
 52  
         private static final long serialVersionUID = -4405355319548951283L;
 53  
 
 54  
         @XmlElement(name = Elements.APPLICATION_ID, required=true)
 55  
         private final String applicationId;
 56  
 
 57  
         @XmlElement(name = Elements.NAMESPACE_CODE, required=true)
 58  
         private final String namespaceCode;
 59  
 
 60  
         @XmlElement(name = Elements.COMPONENT_CODE, required=true)
 61  
         private final String componentCode;
 62  
         
 63  
     @XmlElement(name = Elements.NAME, required=true)
 64  
     private final String name;
 65  
 
 66  17
     @SuppressWarnings("unused")
 67  
         @XmlAnyElement
 68  
     private final Collection<Element> _futureElements = null;
 69  
 
 70  
     /** 
 71  
      * This constructor should never be called except during JAXB unmarshalling. 
 72  
      */
 73  2
     private ParameterKey() {
 74  2
             this.applicationId = null;
 75  2
             this.namespaceCode = null;
 76  2
             this.componentCode = null;
 77  2
             this.name = null;
 78  2
     }
 79  
 
 80  
         /**
 81  
          * Constructs a ParameterKey from the given values.
 82  
          */
 83  15
     private ParameterKey(String applicationId, String namespaceCode, String componentCode, String name) {
 84  15
         if (StringUtils.isBlank(applicationId)) {
 85  4
             throw new IllegalArgumentException("applicationId is blank");
 86  
         }
 87  11
         if (StringUtils.isBlank(namespaceCode)) {
 88  3
             throw new IllegalArgumentException("namespaceCode is blank");
 89  
         }
 90  8
         if (StringUtils.isBlank(componentCode)) {
 91  3
             throw new IllegalArgumentException("componentCode is blank");
 92  
         }
 93  5
                 if (StringUtils.isBlank(name)) {
 94  3
                         throw new IllegalArgumentException("name is blank");
 95  
                 }
 96  2
         this.applicationId = applicationId;
 97  2
         this.namespaceCode = namespaceCode;
 98  2
         this.componentCode = componentCode;
 99  2
                 this.name = name;
 100  2
     }
 101  
 
 102  
     /**
 103  
      * Creates a ParameterKey from the given required values.
 104  
      * 
 105  
      * @param applicationId the application id, cannot be null or blank
 106  
      * @param namespaceCode the namespace code, cannot be null or blank
 107  
      * @param componentCode the component code, cannot be null or blank
 108  
          * @param name the parameter name, cannot be null or blank
 109  
      * @return the fully-constructed ParameterKey
 110  
      * @throws IllegalArgumentException if any arguments are null or blank
 111  
      */
 112  
     public static ParameterKey create(String applicationId, String namespaceCode, String componentCode, String name) {
 113  15
         return new ParameterKey(applicationId, namespaceCode, componentCode, name);
 114  
     }
 115  
         
 116  
     public String getApplicationId() {
 117  0
                 return applicationId;
 118  
         }
 119  
 
 120  
         public String getNamespaceCode() {
 121  0
                 return namespaceCode;
 122  
         }
 123  
 
 124  
         public String getComponentCode() {
 125  0
                 return componentCode;
 126  
         }
 127  
 
 128  
         public String getName() {
 129  0
                 return name;
 130  
         }
 131  
 
 132  
         @Override
 133  
         public int hashCode() {
 134  0
                 return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 135  
         }
 136  
 
 137  
         @Override
 138  
         public boolean equals(Object obj) {
 139  2
                 return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 140  
         }
 141  
 
 142  
         @Override
 143  
         public String toString() {
 144  0
                 return ToStringBuilder.reflectionToString(this);
 145  
         }
 146  
     
 147  
         /**
 148  
          * Defines some internal constants used on this class.
 149  
          */
 150  0
         static class Constants {
 151  
                 final static String ROOT_ELEMENT_NAME = "parameterKey";
 152  
                 final static String TYPE_NAME = "ParameterKeyType";
 153  1
                 final static String[] HASH_CODE_EQUALS_EXCLUDE = { CoreConstants.CommonElements.FUTURE_ELEMENTS};
 154  
         }
 155  
   
 156  
         /**
 157  
          * A private class which exposes constants which define the XML element names to use
 158  
          * when this object is marshalled to XML.
 159  
          */
 160  0
         static class Elements {
 161  
                 final static String APPLICATION_ID = "applicationId";
 162  
                 final static String NAMESPACE_CODE = "namespaceCode";
 163  
                 final static String COMPONENT_CODE = "componentCode";
 164  
                 final static String NAME = "name";
 165  
         }
 166  
   
 167  
 }