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