Coverage Report - org.kuali.rice.kew.api.doctype.RoutePath
 
Classes in this File Line Coverage Branch Coverage Complexity
RoutePath
0%
0/16
0%
0/8
1.8
RoutePath$1
N/A
N/A
1.8
RoutePath$Builder
0%
0/17
0%
0/4
1.8
RoutePath$Cache
0%
0/1
N/A
1.8
RoutePath$Constants
0%
0/1
N/A
1.8
RoutePath$Elements
0%
0/1
N/A
1.8
 
 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.doctype;
 17  
 
 18  
 import org.kuali.rice.core.api.CoreConstants;
 19  
 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
 20  
 import org.kuali.rice.core.api.mo.ModelBuilder;
 21  
 import org.kuali.rice.core.api.util.collect.CollectionUtils;
 22  
 import org.kuali.rice.kew.api.KewApiConstants;
 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.XmlElementWrapper;
 30  
 import javax.xml.bind.annotation.XmlRootElement;
 31  
 import javax.xml.bind.annotation.XmlType;
 32  
 import java.io.Serializable;
 33  
 import java.util.ArrayList;
 34  
 import java.util.Collection;
 35  
 import java.util.List;
 36  
 
 37  
 @XmlRootElement(name = RoutePath.Constants.ROOT_ELEMENT_NAME)
 38  
 @XmlAccessorType(XmlAccessType.NONE)
 39  
 @XmlType(name = RoutePath.Constants.TYPE_NAME, propOrder = {
 40  
         RoutePath.Elements.PROCESSES,
 41  
         CoreConstants.CommonElements.FUTURE_ELEMENTS
 42  
 })
 43  0
 public final class RoutePath extends AbstractDataTransferObject implements RoutePathContract {
 44  
 
 45  
     private static final long serialVersionUID = -7177305375323986864L;
 46  
 
 47  
     @XmlElementWrapper(name = Elements.PROCESSES, required = false)
 48  
     @XmlElement(name = Elements.PROCESS, required = false)
 49  
     private final List<ProcessDefinition> processDefinitions;
 50  
 
 51  0
     @SuppressWarnings("unused")
 52  
     @XmlAnyElement
 53  
     private final Collection<Element> _futureElements = null;
 54  
 
 55  
     /**
 56  
      * Private constructor used only by JAXB.
 57  
      */
 58  0
     private RoutePath() {
 59  0
         this.processDefinitions = null;
 60  0
     }
 61  
 
 62  0
     private RoutePath(Builder builder) {
 63  0
         this.processDefinitions = new ArrayList<ProcessDefinition>();
 64  0
         if (builder.getProcessDefinitions() != null) {
 65  0
             for (ProcessDefinition.Builder processBuilder : builder.getProcessDefinitions()) {
 66  0
                 this.processDefinitions.add(processBuilder.build());
 67  
             }
 68  
         }
 69  0
     }
 70  
     
 71  
     public ProcessDefinition getPrimaryProcess() {
 72  0
         for (ProcessDefinition processDefinition : processDefinitions) {
 73  0
             if (processDefinition.isInitial()) {
 74  0
                 return processDefinition;
 75  
             }
 76  
         }        
 77  0
         return null;
 78  
     }
 79  
 
 80  
     @Override
 81  
     public List<ProcessDefinition> getProcessDefinitions() {
 82  0
         return CollectionUtils.unmodifiableListNullSafe(this.processDefinitions);
 83  
     }
 84  
 
 85  
     /**
 86  
      * A builder which can be used to construct {@link RoutePath} instances. Enforces the
 87  
      * constraints of the {@link RoutePathContract}.
 88  
      */
 89  0
     public final static class Builder implements Serializable, ModelBuilder, RoutePathContract {
 90  
 
 91  
         private static final long serialVersionUID = -6916424305298043710L;
 92  
 
 93  
         private List<ProcessDefinition.Builder> processes;
 94  
 
 95  0
         private Builder() {}
 96  
 
 97  
         public static Builder create() {
 98  0
             Builder builder = new Builder();
 99  0
             builder.setProcesses(new ArrayList<ProcessDefinition.Builder>());
 100  0
             return builder;
 101  
         }
 102  
 
 103  
         public static Builder create(RoutePathContract contract) {
 104  0
             if (contract == null) {
 105  0
                 throw new IllegalArgumentException("contract was null");
 106  
             }
 107  0
             Builder builder = create();
 108  0
             List<ProcessDefinition.Builder> processBuilders = new ArrayList<ProcessDefinition.Builder>();
 109  0
             for (ProcessDefinitionContract process : contract.getProcessDefinitions()) {
 110  0
                 processBuilders.add(ProcessDefinition.Builder.create(process));
 111  
             }
 112  0
             builder.setProcesses(processBuilders);
 113  0
             return builder;
 114  
         }
 115  
 
 116  
         public RoutePath build() {
 117  0
             return new RoutePath(this);
 118  
         }
 119  
 
 120  
         @Override
 121  
         public List<ProcessDefinition.Builder> getProcessDefinitions() {
 122  0
             return this.processes;
 123  
         }
 124  
 
 125  
         public void setProcesses(List<ProcessDefinition.Builder> processes) {
 126  0
             this.processes = processes;
 127  0
         }
 128  
 
 129  
     }
 130  
 
 131  
     /**
 132  
      * Defines some internal constants used on this class.
 133  
      */
 134  0
     static class Constants {
 135  
         final static String ROOT_ELEMENT_NAME = "routePath";
 136  
         final static String TYPE_NAME = "RoutePathType";
 137  
     }
 138  
 
 139  
     /**
 140  
      * A private class which exposes constants which define the XML element names to use when this
 141  
      * object is marshalled to XML.
 142  
      */
 143  0
     static class Elements {
 144  
         final static String PROCESSES = "processDefinitions";
 145  
         final static String PROCESS = "processDefinition";
 146  
     }
 147  
 
 148  0
     public static class Cache {
 149  
         public static final String NAME = KewApiConstants.Namespaces.KEW_NAMESPACE_2_0 + "/" + RoutePath.Constants.TYPE_NAME;
 150  
     }
 151  
 
 152  
 }