Coverage Report - org.kuali.rice.kew.api.rule.RuleExtension
 
Classes in this File Line Coverage Branch Coverage Complexity
RuleExtension
0%
0/19
0%
0/8
1.562
RuleExtension$1
N/A
N/A
1.562
RuleExtension$Builder
0%
0/23
0%
0/4
1.562
RuleExtension$Constants
0%
0/1
N/A
1.562
RuleExtension$Elements
0%
0/1
N/A
1.562
 
 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.kew.api.rule;
 17  
 
 18  
 import java.io.Serializable;
 19  
 import java.util.Collection;
 20  
 import java.util.Map;
 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.ObjectUtils;
 30  
 import org.kuali.rice.core.api.CoreConstants;
 31  
 import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
 32  
 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
 33  
 import org.kuali.rice.core.api.mo.ModelBuilder;
 34  
 import org.kuali.rice.core.api.util.collect.CollectionUtils;
 35  
 import org.kuali.rice.core.api.util.jaxb.MapStringStringAdapter;
 36  
 import org.w3c.dom.Element;
 37  
 
 38  
 @XmlRootElement(name = RuleExtension.Constants.ROOT_ELEMENT_NAME)
 39  
 @XmlAccessorType(XmlAccessType.NONE)
 40  
 @XmlType(name = RuleExtension.Constants.TYPE_NAME, propOrder = {
 41  
     RuleExtension.Elements.RULE_TEMPLATE_ATTRIBUTE,
 42  
     RuleExtension.Elements.EXTENSION_VALUES_MAP,
 43  
     CoreConstants.CommonElements.VERSION_NUMBER,
 44  
     CoreConstants.CommonElements.FUTURE_ELEMENTS
 45  
 })
 46  0
 public final class RuleExtension
 47  
     extends AbstractDataTransferObject
 48  
     implements RuleExtensionContract
 49  
 {
 50  
 
 51  
     @XmlElement(name = Elements.RULE_TEMPLATE_ATTRIBUTE, required = true)
 52  
     private final RuleTemplateAttribute ruleTemplateAttribute;
 53  
     @XmlElement(name = Elements.EXTENSION_VALUES_MAP, required = false)
 54  
     @XmlJavaTypeAdapter(MapStringStringAdapter.class)
 55  
     private final Map<String, String> extensionValuesMap;
 56  
     @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
 57  
     private final Long versionNumber;
 58  0
     @SuppressWarnings("unused")
 59  
     @XmlAnyElement
 60  
     private final Collection<Element> _futureElements = null;
 61  
 
 62  
     /**
 63  
      * Private constructor used only by JAXB.
 64  
      * 
 65  
      */
 66  0
     private RuleExtension() {
 67  0
         this.ruleTemplateAttribute = null;
 68  0
         this.extensionValuesMap = null;
 69  0
         this.versionNumber = null;
 70  0
     }
 71  
 
 72  0
     private RuleExtension(Builder builder) {
 73  0
         this.ruleTemplateAttribute = builder.getRuleTemplateAttribute().build();
 74  0
         this.extensionValuesMap = builder.getExtensionValuesMap();
 75  0
         this.versionNumber = builder.getVersionNumber();
 76  0
     }
 77  
 
 78  
     @Override
 79  
     public RuleTemplateAttributeContract getRuleTemplateAttribute() {
 80  0
         return this.ruleTemplateAttribute;
 81  
     }
 82  
 
 83  
     @Override
 84  
     public Map<String, String> getExtensionValuesMap() {
 85  0
         return this.extensionValuesMap;
 86  
     }
 87  
 
 88  
     @Override
 89  
     public Long getVersionNumber() {
 90  0
         return this.versionNumber;
 91  
     }
 92  
 
 93  
 
 94  
     /**
 95  
      * A builder which can be used to construct {@link RuleExtension} instances.  Enforces the constraints of the {@link RuleExtensionContract}.
 96  
      * 
 97  
      */
 98  0
     public final static class Builder
 99  
         implements Serializable, ModelBuilder, RuleExtensionContract
 100  
     {
 101  
 
 102  
         private RuleTemplateAttribute.Builder ruleTemplateAttribute;
 103  
         private Map<String, String> extensionValuesMap;
 104  
         private Long versionNumber;
 105  
 
 106  0
         private Builder(RuleTemplateAttribute.Builder ruleTemplateAttribute) {
 107  0
             setRuleTemplateAttribute(ruleTemplateAttribute);
 108  0
         }
 109  
 
 110  
         public static Builder create(RuleTemplateAttribute.Builder ruleTemplateAttribute) {
 111  0
             return new Builder(ruleTemplateAttribute);
 112  
         }
 113  
 
 114  
         public static Builder create(RuleExtensionContract contract) {
 115  0
             if (contract == null) {
 116  0
                 throw new IllegalArgumentException("contract was null");
 117  
             }
 118  
             // TODO if create() is modified to accept required parameters, this will need to be modified
 119  0
             Builder builder = create(RuleTemplateAttribute.Builder.create(contract.getRuleTemplateAttribute()));
 120  0
             builder.setExtensionValuesMap(contract.getExtensionValuesMap());
 121  0
             builder.setVersionNumber(contract.getVersionNumber());
 122  0
             return builder;
 123  
         }
 124  
 
 125  
         public RuleExtension build() {
 126  0
             return new RuleExtension(this);
 127  
         }
 128  
 
 129  
         @Override
 130  
         public RuleTemplateAttribute.Builder getRuleTemplateAttribute() {
 131  0
             return this.ruleTemplateAttribute;
 132  
         }
 133  
 
 134  
         @Override
 135  
         public Map<String, String> getExtensionValuesMap() {
 136  0
             return this.extensionValuesMap;
 137  
         }
 138  
 
 139  
         @Override
 140  
         public Long getVersionNumber() {
 141  0
             return this.versionNumber;
 142  
         }
 143  
 
 144  
         public void setRuleTemplateAttribute(RuleTemplateAttribute.Builder ruleTemplateAttribute) {
 145  0
             if (ruleTemplateAttribute == null) {
 146  0
                 throw new RiceIllegalArgumentException("ruleTemplateAttribute was null");
 147  
             }
 148  0
             this.ruleTemplateAttribute = ruleTemplateAttribute;
 149  0
         }
 150  
 
 151  
         public void setExtensionValuesMap(Map<String, String> extensionValuesMap) {
 152  0
             this.extensionValuesMap = extensionValuesMap;
 153  0
         }
 154  
 
 155  
         public void setVersionNumber(Long versionNumber) {
 156  0
             this.versionNumber = versionNumber;
 157  0
         }
 158  
 
 159  
     }
 160  
 
 161  
     public boolean equals(Object o) {
 162  0
         if (o == null) return false;
 163  0
         if (!(o instanceof RuleExtension)) return false;
 164  0
         RuleExtension pred = (RuleExtension) o;
 165  0
         return ObjectUtils.equals(ruleTemplateAttribute, pred.getRuleTemplateAttribute()) &&
 166  
                CollectionUtils.collectionsEquivalent(extensionValuesMap.entrySet(), pred.getExtensionValuesMap().entrySet());
 167  
     }
 168  
 
 169  
     /**
 170  
      * Defines some internal constants used on this class.
 171  
      * 
 172  
      */
 173  0
     static class Constants {
 174  
 
 175  
         final static String ROOT_ELEMENT_NAME = "ruleExtension";
 176  
         final static String TYPE_NAME = "RuleExtensionType";
 177  
 
 178  
     }
 179  
 
 180  
 
 181  
     /**
 182  
      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
 183  
      * 
 184  
      */
 185  0
     static class Elements {
 186  
 
 187  
         final static String RULE_TEMPLATE_ATTRIBUTE = "ruleTemplateAttribute";
 188  
         final static String EXTENSION_VALUES_MAP = "extensionValuesMap";
 189  
 
 190  
     }
 191  
 
 192  
 }