Coverage Report - org.kuali.rice.kew.api.action.ValidActions
 
Classes in this File Line Coverage Branch Coverage Complexity
ValidActions
0%
0/24
0%
0/8
1.75
ValidActions$1
N/A
N/A
1.75
ValidActions$Builder
0%
0/15
0%
0/4
1.75
ValidActions$Constants
0%
0/2
N/A
1.75
ValidActions$Elements
0%
0/1
N/A
1.75
 
 1  
 /*
 2  
  * Copyright 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/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.kew.api.action;
 17  
 
 18  
 import java.io.Serializable;
 19  
 import java.util.Collection;
 20  
 import java.util.Collections;
 21  
 import java.util.HashSet;
 22  
 import java.util.Set;
 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.XmlRootElement;
 29  
 import javax.xml.bind.annotation.XmlType;
 30  
 
 31  
 import org.apache.commons.lang.builder.EqualsBuilder;
 32  
 import org.apache.commons.lang.builder.HashCodeBuilder;
 33  
 import org.apache.commons.lang.builder.ToStringBuilder;
 34  
 import org.kuali.rice.core.api.CoreConstants;
 35  
 import org.kuali.rice.core.api.mo.ModelBuilder;
 36  
 import org.kuali.rice.core.api.mo.ModelObjectComplete;
 37  
 import org.w3c.dom.Element;
 38  
 
 39  
 @XmlRootElement(name = ValidActions.Constants.ROOT_ELEMENT_NAME)
 40  
 @XmlAccessorType(XmlAccessType.NONE)
 41  
 @XmlType(name = ValidActions.Constants.TYPE_NAME, propOrder = {
 42  
     ValidActions.Elements.VALID_ACTION_CODES,
 43  
     CoreConstants.CommonElements.FUTURE_ELEMENTS
 44  
 })
 45  0
 public final class ValidActions implements ModelObjectComplete {
 46  
 
 47  
         private static final long serialVersionUID = 8074175291030982905L;
 48  
 
 49  
         @XmlElement(name = Elements.VALID_ACTION_CODE, required = false)
 50  
     private final Set<String> validActionCodes;
 51  
     
 52  0
     @SuppressWarnings("unused")
 53  
     @XmlAnyElement
 54  
     private final Collection<Element> _futureElements = null;
 55  
 
 56  
     /**
 57  
      * Private constructor used only by JAXB.
 58  
      */
 59  0
     private ValidActions() {
 60  0
         this.validActionCodes = null;
 61  0
     }
 62  
 
 63  0
     private ValidActions(Builder builder) {
 64  0
         Set<ActionType> validActions = builder.getValidActions();
 65  0
         Set<String> validActionCodes = new HashSet<String>();
 66  0
         for (ActionType actionType : validActions) {
 67  0
                 validActionCodes.add(actionType.getCode());
 68  
         }
 69  0
         this.validActionCodes = validActionCodes;
 70  0
     }
 71  
 
 72  
     public Set<ActionType> getValidActions() {
 73  0
             if (validActionCodes == null) {
 74  0
                     return Collections.emptySet();
 75  
             }
 76  0
             Set<ActionType> validActions = new HashSet<ActionType>();
 77  0
             for (String validActionCode : validActionCodes) {
 78  
                     // ignore action codes that we don't understand because they could be coming from a later version of KEW
 79  0
                     ActionType actionType = ActionType.fromCode(validActionCode, true);
 80  0
                     if (actionType != null) {
 81  0
                             validActions.add(actionType);
 82  
                     }
 83  0
             }
 84  0
         return Collections.unmodifiableSet(validActions);
 85  
     }
 86  
 
 87  
     @Override
 88  
     public int hashCode() {
 89  0
         return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 90  
     }
 91  
 
 92  
     @Override
 93  
     public boolean equals(Object object) {
 94  0
         return EqualsBuilder.reflectionEquals(object, this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 95  
     }
 96  
 
 97  
     @Override
 98  
     public String toString() {
 99  0
         return ToStringBuilder.reflectionToString(this);
 100  
     }
 101  
 
 102  
 
 103  
     /**
 104  
      * A builder which can be used to construct {@link ValidActions} instances.
 105  
      */
 106  0
     public final static class Builder implements Serializable, ModelBuilder {
 107  
 
 108  
                 private static final long serialVersionUID = -3227993220281961077L;
 109  
 
 110  
                 private Set<ActionType> validActions;
 111  
 
 112  0
         private Builder() {
 113  0
                 setValidActions(new HashSet<ActionType>());
 114  0
         }
 115  
 
 116  
         public static Builder create() {
 117  0
             return new Builder();
 118  
         }
 119  
 
 120  
         public ValidActions build() {
 121  0
             return new ValidActions(this);
 122  
         }
 123  
 
 124  
         public Set<ActionType> getValidActions() {
 125  0
             return this.validActions;
 126  
         }
 127  
 
 128  
         public void setValidActions(Set<ActionType> validActions) {
 129  0
                 if (validActions == null) {
 130  0
                         throw new IllegalArgumentException("validActions was null");
 131  
                 }
 132  0
             this.validActions = new HashSet<ActionType>(validActions);
 133  0
         }
 134  
         
 135  
         public void addValidAction(ActionType validAction) {
 136  0
                 if (validAction == null) {
 137  0
                         throw new IllegalArgumentException("validAction was null");
 138  
                 }
 139  0
                 validActions.add(validAction);
 140  0
         }
 141  
 
 142  
     }
 143  
 
 144  
     /**
 145  
      * Defines some internal constants used on this class.
 146  
      */
 147  0
     static class Constants {
 148  
         final static String ROOT_ELEMENT_NAME = "validActions";
 149  
         final static String TYPE_NAME = "ValidActionsType";
 150  0
         final static String[] HASH_CODE_EQUALS_EXCLUDE = new String[] { CoreConstants.CommonElements.FUTURE_ELEMENTS };
 151  
     }
 152  
 
 153  
 
 154  
     /**
 155  
      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
 156  
      */
 157  0
     static class Elements {
 158  
         final static String VALID_ACTION_CODES = "validActionCodes";
 159  
         final static String VALID_ACTION_CODE = "validActionCode";
 160  
     }
 161  
 
 162  
 }
 163