Coverage Report - org.kuali.rice.kew.api.extension.ExtensionDefinition
 
Classes in this File Line Coverage Branch Coverage Complexity
ExtensionDefinition
0%
0/35
0%
0/2
1.273
ExtensionDefinition$1
N/A
N/A
1.273
ExtensionDefinition$Builder
0%
0/52
0%
0/8
1.273
ExtensionDefinition$Constants
0%
0/1
N/A
1.273
ExtensionDefinition$Elements
0%
0/1
N/A
1.273
 
 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.extension;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.core.api.CoreConstants;
 20  
 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
 21  
 import org.kuali.rice.core.api.mo.ModelBuilder;
 22  
 import org.kuali.rice.core.api.util.jaxb.MapStringStringAdapter;
 23  
 import org.w3c.dom.Element;
 24  
 
 25  
 import javax.xml.bind.annotation.XmlAccessType;
 26  
 import javax.xml.bind.annotation.XmlAccessorType;
 27  
 import javax.xml.bind.annotation.XmlAnyElement;
 28  
 import javax.xml.bind.annotation.XmlElement;
 29  
 import javax.xml.bind.annotation.XmlRootElement;
 30  
 import javax.xml.bind.annotation.XmlType;
 31  
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
 32  
 import java.io.Serializable;
 33  
 import java.util.Collection;
 34  
 import java.util.Collections;
 35  
 import java.util.HashMap;
 36  
 import java.util.Map;
 37  
 
 38  
 /**
 39  
  * Immutable implementation of the {@link ExtensionDefinitionContract}.  Defines an extension to some component of
 40  
  * Kuali Enterprise Workflow.
 41  
  *
 42  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 43  
  */
 44  
 @XmlRootElement(name = ExtensionDefinition.Constants.ROOT_ELEMENT_NAME)
 45  
 @XmlAccessorType(XmlAccessType.NONE)
 46  
 @XmlType(name = ExtensionDefinition.Constants.TYPE_NAME, propOrder = {
 47  
         ExtensionDefinition.Elements.ID,
 48  
         ExtensionDefinition.Elements.NAME,
 49  
         ExtensionDefinition.Elements.APPLICATION_ID,
 50  
         ExtensionDefinition.Elements.LABEL,
 51  
         ExtensionDefinition.Elements.DESCRIPTION,
 52  
         ExtensionDefinition.Elements.TYPE,
 53  
         ExtensionDefinition.Elements.RESOURCE_DESCRIPTOR,
 54  
         ExtensionDefinition.Elements.CONFIGURATION,
 55  
         CoreConstants.CommonElements.VERSION_NUMBER,
 56  
         CoreConstants.CommonElements.FUTURE_ELEMENTS
 57  
 })
 58  0
 public final class ExtensionDefinition extends AbstractDataTransferObject implements ExtensionDefinitionContract {
 59  
 
 60  
     private static final long serialVersionUID = 6234968409006917945L;
 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.APPLICATION_ID, required = false)
 69  
     private final String applicationId;
 70  
 
 71  
     @XmlElement(name = Elements.LABEL, required = false)
 72  
     private final String label;
 73  
 
 74  
     @XmlElement(name = Elements.DESCRIPTION, required = false)
 75  
     private final String description;
 76  
 
 77  
     @XmlElement(name = Elements.TYPE, required = true)
 78  
     private final String type;
 79  
 
 80  
     @XmlElement(name = Elements.RESOURCE_DESCRIPTOR, required = true)
 81  
     private final String resourceDescriptor;
 82  
 
 83  
     @XmlElement(name = Elements.CONFIGURATION, required = false)
 84  
     @XmlJavaTypeAdapter(MapStringStringAdapter.class)
 85  
     private final Map<String, String> configuration;
 86  
 
 87  
     @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
 88  
     private final Long versionNumber;
 89  
 
 90  0
     @SuppressWarnings("unused")
 91  
     @XmlAnyElement
 92  
     private final Collection<Element> _futureElements = null;
 93  
 
 94  
     /**
 95  
      * Private constructor used only by JAXB.
 96  
      */
 97  
     @SuppressWarnings("unused")
 98  0
     private ExtensionDefinition() {
 99  0
         this.id = null;
 100  0
         this.name = null;
 101  0
         this.applicationId = null;
 102  0
         this.label = null;
 103  0
         this.description = null;
 104  0
         this.type = null;
 105  0
         this.resourceDescriptor = null;
 106  0
         this.configuration = null;
 107  0
         this.versionNumber = null;
 108  0
     }
 109  
 
 110  0
     private ExtensionDefinition(Builder builder) {
 111  0
         this.id = builder.getId();
 112  0
         this.name = builder.getName();
 113  0
         this.applicationId = builder.getApplicationId();
 114  0
         this.label = builder.getLabel();
 115  0
         this.description = builder.getDescription();
 116  0
         this.type = builder.getType();
 117  0
         this.resourceDescriptor = builder.getResourceDescriptor();
 118  0
         if (builder.getConfiguration() == null) {
 119  0
             this.configuration = Collections.emptyMap();
 120  
         } else {
 121  0
             this.configuration = Collections.unmodifiableMap(new HashMap<String, String>(builder.getConfiguration()));
 122  
         }
 123  0
         this.versionNumber = builder.getVersionNumber();
 124  0
     }
 125  
 
 126  
     @Override
 127  
     public String getId() {
 128  0
         return this.id;
 129  
     }
 130  
 
 131  
     @Override
 132  
     public String getName() {
 133  0
         return this.name;
 134  
     }
 135  
 
 136  
     @Override
 137  
     public String getApplicationId() {
 138  0
         return this.applicationId;
 139  
     }
 140  
 
 141  
     @Override
 142  
     public String getLabel() {
 143  0
         return this.label;
 144  
     }
 145  
 
 146  
     @Override
 147  
     public String getDescription() {
 148  0
         return this.description;
 149  
     }
 150  
 
 151  
     @Override
 152  
     public String getType() {
 153  0
         return this.type;
 154  
     }
 155  
 
 156  
     @Override
 157  
     public String getResourceDescriptor() {
 158  0
         return this.resourceDescriptor;
 159  
     }
 160  
 
 161  
     @Override
 162  
     public Map<String, String> getConfiguration() {
 163  0
         return this.configuration;
 164  
     }
 165  
 
 166  
     @Override
 167  
     public Long getVersionNumber() {
 168  0
         return this.versionNumber;
 169  
     }
 170  
 
 171  
     /**
 172  
      * A builder which can be used to construct {@link ExtensionDefinition} instances.  Enforces the constraints of the
 173  
      * {@link ExtensionDefinitionContract}.
 174  
      */
 175  0
     public final static class Builder implements Serializable, ModelBuilder, ExtensionDefinitionContract {
 176  
 
 177  
         private String id;
 178  
         private String name;
 179  
         private String applicationId;
 180  
         private String label;
 181  
         private String description;
 182  
         private String type;
 183  
         private String resourceDescriptor;
 184  
         private Map<String, String> configuration;
 185  
         private Long versionNumber;
 186  
 
 187  0
         private Builder(String name, String type, String resourceDescriptor) {
 188  0
             setName(name);
 189  0
             setType(type);
 190  0
             setResourceDescriptor(resourceDescriptor);
 191  0
             setConfiguration(new HashMap<String, String>());
 192  0
         }
 193  
 
 194  
         public static Builder create(String name, String type, String resourceDescriptor) {
 195  0
             return new Builder(name, type, resourceDescriptor);
 196  
         }
 197  
 
 198  
         public static Builder create(ExtensionDefinitionContract contract) {
 199  0
             if (contract == null) {
 200  0
                 throw new IllegalArgumentException("contract was null");
 201  
             }
 202  0
             Builder builder = create(contract.getName(), contract.getType(), contract.getResourceDescriptor());
 203  0
             builder.setId(contract.getId());
 204  0
             builder.setApplicationId(contract.getApplicationId());
 205  0
             builder.setLabel(contract.getLabel());
 206  0
             builder.setDescription(contract.getDescription());
 207  0
             builder.setConfiguration(contract.getConfiguration());
 208  0
             builder.setVersionNumber(contract.getVersionNumber());
 209  0
             return builder;
 210  
         }
 211  
 
 212  
         public ExtensionDefinition build() {
 213  0
             return new ExtensionDefinition(this);
 214  
         }
 215  
 
 216  
         @Override
 217  
         public String getId() {
 218  0
             return this.id;
 219  
         }
 220  
 
 221  
         @Override
 222  
         public String getName() {
 223  0
             return this.name;
 224  
         }
 225  
 
 226  
         @Override
 227  
         public String getApplicationId() {
 228  0
             return this.applicationId;
 229  
         }
 230  
 
 231  
         @Override
 232  
         public String getLabel() {
 233  0
             return this.label;
 234  
         }
 235  
 
 236  
         @Override
 237  
         public String getDescription() {
 238  0
             return this.description;
 239  
         }
 240  
 
 241  
         @Override
 242  
         public String getType() {
 243  0
             return this.type;
 244  
         }
 245  
 
 246  
         @Override
 247  
         public String getResourceDescriptor() {
 248  0
             return this.resourceDescriptor;
 249  
         }
 250  
 
 251  
         @Override
 252  
         public Map<String, String> getConfiguration() {
 253  0
             return this.configuration;
 254  
         }
 255  
 
 256  
         @Override
 257  
         public Long getVersionNumber() {
 258  0
             return this.versionNumber;
 259  
         }
 260  
 
 261  
         public void setId(String id) {
 262  0
             this.id = id;
 263  0
         }
 264  
 
 265  
         public void setName(String name) {
 266  0
             if (StringUtils.isBlank(name)) {
 267  0
                 throw new IllegalArgumentException("name was null or blank");
 268  
             }
 269  0
             this.name = name;
 270  0
         }
 271  
 
 272  
         public void setApplicationId(String applicationId) {
 273  0
             this.applicationId = applicationId;
 274  0
         }
 275  
 
 276  
         public void setLabel(String label) {
 277  0
             this.label = label;
 278  0
         }
 279  
 
 280  
         public void setDescription(String description) {
 281  0
             this.description = description;
 282  0
         }
 283  
 
 284  
         public void setType(String type) {
 285  0
             if (StringUtils.isBlank(type)) {
 286  0
                 throw new IllegalArgumentException("type was null or blank");
 287  
             }
 288  
 
 289  0
             this.type = type;
 290  0
         }
 291  
 
 292  
         public void setResourceDescriptor(String resourceDescriptor) {
 293  0
             if (StringUtils.isBlank(resourceDescriptor)) {
 294  0
                 throw new IllegalArgumentException("descriptor was null or blank");
 295  
             }
 296  0
             this.resourceDescriptor = resourceDescriptor;
 297  0
         }
 298  
 
 299  
         public void setConfiguration(Map<String, String> configuration) {
 300  0
             this.configuration = configuration;
 301  0
         }
 302  
 
 303  
         public void setVersionNumber(Long versionNumber) {
 304  0
             this.versionNumber = versionNumber;
 305  0
         }
 306  
 
 307  
     }
 308  
 
 309  
     /**
 310  
      * Defines some internal constants used on this class.
 311  
      */
 312  0
     static class Constants {
 313  
         final static String ROOT_ELEMENT_NAME = "extensionDefinition";
 314  
         final static String TYPE_NAME = "ExtensionDefinitionType";
 315  
     }
 316  
 
 317  
     /**
 318  
      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
 319  
      */
 320  0
     static class Elements {
 321  
         final static String ID = "id";
 322  
         final static String NAME = "name";
 323  
         final static String APPLICATION_ID = "applicationId";
 324  
         final static String LABEL = "label";
 325  
         final static String DESCRIPTION = "description";
 326  
         final static String TYPE = "type";
 327  
         final static String RESOURCE_DESCRIPTOR = "resourceDescriptor";
 328  
         final static String CONFIGURATION = "configuration";
 329  
     }
 330  
 
 331  
 }