| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
package org.kuali.rice.kew.engine.node; |
| 18 | |
|
| 19 | |
import java.util.ArrayList; |
| 20 | |
import java.util.Collections; |
| 21 | |
import java.util.Comparator; |
| 22 | |
import java.util.Iterator; |
| 23 | |
import java.util.List; |
| 24 | |
|
| 25 | |
import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; |
| 26 | |
import org.kuali.rice.core.api.reflect.ObjectDefinition; |
| 27 | |
import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; |
| 28 | |
import org.kuali.rice.core.util.ClassLoaderUtils; |
| 29 | |
import org.kuali.rice.kew.exception.ResourceUnavailableException; |
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
public class NodeType { |
| 41 | |
|
| 42 | |
private static final String SIMPLE_NAME = "simple"; |
| 43 | |
private static final String JOIN_NAME = "join"; |
| 44 | |
private static final String SPLIT_NAME = "split"; |
| 45 | |
private static final String SUB_PROCESS_NAME = "process"; |
| 46 | |
private static final String DYNAMIC_NAME = "dynamic"; |
| 47 | |
private static final String START_NAME = "start"; |
| 48 | |
private static final String REQUEST_ACTIVATION_NAME = "requestActivation"; |
| 49 | |
private static final String REQUESTS_NAME = "requests"; |
| 50 | |
private static final String ROLE_NAME = "role"; |
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | 0 | private static final List typeList = new ArrayList(); |
| 56 | 0 | private static final Comparator depthComparator = new ExtensionDepthComparator(); |
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | 0 | public static final NodeType SIMPLE = new NodeType(SIMPLE_NAME, SimpleNode.class, null); |
| 61 | 0 | public static final NodeType SPLIT = new NodeType(SPLIT_NAME, SplitNode.class, SimpleSplitNode.class); |
| 62 | 0 | public static final NodeType JOIN = new NodeType(JOIN_NAME, JoinNode.class, SimpleJoinNode.class); |
| 63 | 0 | public static final NodeType SUB_PROCESS = new NodeType(SUB_PROCESS_NAME, SubProcessNode.class, SimpleSubProcessNode.class); |
| 64 | 0 | public static final NodeType DYNAMIC = new NodeType(DYNAMIC_NAME, DynamicNode.class, null); |
| 65 | |
|
| 66 | |
|
| 67 | 0 | public static final NodeType REQUEST_ACTIVATION = new NodeType(SIMPLE, REQUEST_ACTIVATION_NAME, RequestActivationNode.class, RequestActivationNode.class); |
| 68 | 0 | public static final NodeType START = new NodeType(REQUEST_ACTIVATION, START_NAME, InitialNode.class, InitialNode.class); |
| 69 | 0 | public static final NodeType REQUESTS = new NodeType(REQUEST_ACTIVATION, REQUESTS_NAME, RequestsNode.class, RequestsNode.class); |
| 70 | 0 | public static final NodeType ROLE = new NodeType(REQUESTS, ROLE_NAME, RoleNode.class, RoleNode.class); |
| 71 | |
|
| 72 | |
private NodeType extensionBase; |
| 73 | |
private String name; |
| 74 | |
private Class baseClass; |
| 75 | |
private Class defaultClass; |
| 76 | 0 | private int extensionDepth = 0; |
| 77 | |
|
| 78 | |
private NodeType(String name, Class baseClass, Class defaultClass) { |
| 79 | 0 | this(null, name, baseClass, defaultClass); |
| 80 | 0 | } |
| 81 | |
|
| 82 | 0 | private NodeType(NodeType extensionBase, String name, Class baseClass, Class defaultClass) { |
| 83 | 0 | this.extensionBase = extensionBase; |
| 84 | 0 | this.name = name; |
| 85 | 0 | this.baseClass = baseClass; |
| 86 | 0 | this.defaultClass = defaultClass; |
| 87 | 0 | while (extensionBase != null) { |
| 88 | 0 | extensionDepth++; |
| 89 | 0 | extensionBase = extensionBase.getExtensionBase(); |
| 90 | |
} |
| 91 | 0 | typeList.add(this); |
| 92 | |
|
| 93 | 0 | Collections.sort(typeList, depthComparator); |
| 94 | 0 | } |
| 95 | |
|
| 96 | |
public NodeType getExtensionBase() { |
| 97 | 0 | return extensionBase; |
| 98 | |
} |
| 99 | |
|
| 100 | |
public Class getBaseClass() { |
| 101 | 0 | return baseClass; |
| 102 | |
} |
| 103 | |
|
| 104 | |
public Class getDefaultClass() { |
| 105 | 0 | return defaultClass; |
| 106 | |
} |
| 107 | |
|
| 108 | |
public String getName() { |
| 109 | 0 | return name; |
| 110 | |
} |
| 111 | |
|
| 112 | |
public int getExtensionDepth() { |
| 113 | 0 | return extensionDepth; |
| 114 | |
} |
| 115 | |
|
| 116 | |
public boolean isAssignableFrom(Class typeClass) { |
| 117 | 0 | return getBaseClass().isAssignableFrom(typeClass); |
| 118 | |
} |
| 119 | |
|
| 120 | |
public boolean isAssignableFrom(NodeType type) { |
| 121 | 0 | return getBaseClass().isAssignableFrom(type.getBaseClass()); |
| 122 | |
} |
| 123 | |
|
| 124 | |
public boolean isInstanceOf(Object object) { |
| 125 | 0 | return ClassLoaderUtils.isInstanceOf(object, getBaseClass()); |
| 126 | |
} |
| 127 | |
|
| 128 | |
public boolean isTypeOf(Class typeClass) { |
| 129 | 0 | return typeClass.isAssignableFrom(getBaseClass()); |
| 130 | |
} |
| 131 | |
|
| 132 | |
public boolean isTypeOf(NodeType type) { |
| 133 | 0 | return type.getBaseClass().isAssignableFrom(getBaseClass()); |
| 134 | |
} |
| 135 | |
|
| 136 | |
public boolean isCustomNode(String className) { |
| 137 | 0 | return getDefaultClass() == null || !getDefaultClass().getName().equals(className); |
| 138 | |
} |
| 139 | |
|
| 140 | |
public boolean equals(Object object) { |
| 141 | 0 | if (object instanceof NodeType) { |
| 142 | 0 | return ((NodeType)object).name.equals(name); |
| 143 | |
} |
| 144 | 0 | return false; |
| 145 | |
} |
| 146 | |
|
| 147 | |
public int hashCode() { |
| 148 | 0 | return name.hashCode(); |
| 149 | |
} |
| 150 | |
|
| 151 | |
public static NodeType fromClassName(String className) throws ResourceUnavailableException { |
| 152 | |
|
| 153 | 0 | Object typeObject = GlobalResourceLoader.getResourceLoader().getObject(new ObjectDefinition(className)); |
| 154 | 0 | if (typeObject == null) { |
| 155 | 0 | throw new ResourceUnavailableException("Could not locate the node with the given class name '" + className + "'."); |
| 156 | |
} |
| 157 | |
|
| 158 | |
|
| 159 | 0 | for (Iterator iterator = typeList.iterator(); iterator.hasNext();) { |
| 160 | 0 | NodeType type = (NodeType) iterator.next(); |
| 161 | |
|
| 162 | |
|
| 163 | 0 | if (type.isInstanceOf(typeObject)) { |
| 164 | 0 | return type; |
| 165 | |
} |
| 166 | 0 | } |
| 167 | 0 | return null; |
| 168 | |
} |
| 169 | |
|
| 170 | |
public static NodeType fromNode(RouteNode node) throws ResourceUnavailableException { |
| 171 | 0 | return fromClassName(node.getNodeType()); |
| 172 | |
} |
| 173 | |
|
| 174 | |
public static NodeType fromNodeInstance(RouteNodeInstance nodeInstance) throws ResourceUnavailableException { |
| 175 | 0 | return fromNode(nodeInstance.getRouteNode()); |
| 176 | |
} |
| 177 | |
|
| 178 | |
|
| 179 | |
|
| 180 | |
|
| 181 | 0 | private static class ExtensionDepthComparator implements Comparator { |
| 182 | |
|
| 183 | |
public int compare(Object object1, Object object2) { |
| 184 | 0 | NodeType type1 = (NodeType)object1; |
| 185 | 0 | NodeType type2 = (NodeType)object2; |
| 186 | 0 | if (type1.getExtensionDepth() > type2.getExtensionDepth()) { |
| 187 | 0 | return -1; |
| 188 | 0 | } else if (type1.getExtensionDepth() < type2.getExtensionDepth()) { |
| 189 | 0 | return 1; |
| 190 | |
} |
| 191 | 0 | return 0; |
| 192 | |
} |
| 193 | |
|
| 194 | |
} |
| 195 | |
|
| 196 | |
public static List<NodeType> getTypeList(){ |
| 197 | 0 | return typeList; |
| 198 | |
} |
| 199 | |
|
| 200 | |
} |