001/**
002 * Copyright 2005-2017 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.kew.engine;
017
018import org.kuali.rice.core.api.reflect.ObjectDefinition;
019import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
020import org.kuali.rice.core.api.util.ClassLoaderUtils;
021import org.kuali.rice.kew.engine.node.BasicJoinEngine;
022import org.kuali.rice.kew.engine.node.DynamicNode;
023import org.kuali.rice.kew.engine.node.JoinEngine;
024import org.kuali.rice.kew.engine.node.JoinNode;
025import org.kuali.rice.kew.engine.node.Node;
026import org.kuali.rice.kew.engine.node.RequestActivationNode;
027import org.kuali.rice.kew.engine.node.RequestsNode;
028import org.kuali.rice.kew.engine.node.RouteNode;
029import org.kuali.rice.kew.engine.node.SimpleNode;
030import org.kuali.rice.kew.engine.node.SplitNode;
031import org.kuali.rice.kew.engine.node.SubProcessNode;
032import org.kuali.rice.kew.engine.node.XPathSplitNode;
033
034/**
035 * A helper class which provides some useful utilities for examining and generating nodes.
036 * Provides access to the {@link JoinEngine} and the {@link RoutingNodeFactory}.
037 *
038 * @author Kuali Rice Team (rice.collab@kuali.org)
039 */
040public class RouteHelper {
041
042    private JoinEngine joinEngine = new BasicJoinEngine();
043    private RoutingNodeFactory nodeFactory = new RoutingNodeFactory();
044
045    public JoinEngine getJoinEngine() {
046        return joinEngine;
047    }
048
049    public RoutingNodeFactory getNodeFactory() {
050        return nodeFactory;
051    }
052
053    public boolean isSimpleNode(RouteNode routeNode) {
054        return ClassLoaderUtils.isInstanceOf(getNode(routeNode), SimpleNode.class);
055    }
056
057    public boolean isJoinNode(RouteNode routeNode) {
058        return ClassLoaderUtils.isInstanceOf(getNode(routeNode), JoinNode.class);
059    }
060
061    public boolean isSplitNode(RouteNode routeNode) {
062        return (ClassLoaderUtils.isInstanceOf(getNode(routeNode), SplitNode.class) ||
063                ClassLoaderUtils.isInstanceOf(getNode(routeNode), XPathSplitNode.class));
064    }
065
066    public boolean isDynamicNode(RouteNode routeNode) {
067        return ClassLoaderUtils.isInstanceOf(getNode(routeNode), DynamicNode.class);
068    }
069
070    public boolean isSubProcessNode(RouteNode routeNode) {
071        return ClassLoaderUtils.isInstanceOf(getNode(routeNode), SubProcessNode.class);
072    }
073
074    public boolean isRequestActivationNode(RouteNode routeNode) {
075        return ClassLoaderUtils.isInstanceOf(getNode(routeNode), RequestActivationNode.class);
076    }
077
078    public boolean isRequestsNode(RouteNode routeNode) {
079        return getNode(routeNode) instanceof RequestsNode;
080    }
081
082    public Node getNode(RouteNode routeNode) {
083        return (Node) GlobalResourceLoader.getObject(new ObjectDefinition(routeNode.getNodeType(), routeNode.getDocumentType().getApplicationId()));
084    }
085}