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.node;
017
018import org.kuali.rice.core.api.mo.common.Coded;
019import org.kuali.rice.kew.api.KewApiConstants;
020
021/**
022 * Activation Type enum type which defines the two types of activation within the engine.
023 * Sequential activation means that only a single request on a node will get activated at a time.
024 * Parallel activation means that all requests on a node will be activated.
025 * 
026 * @author Kuali Rice Team (rice.collab@kuali.org)
027 */
028public final class ActivationTypeEnum implements Coded {
029    /** Routing should process the associated ActionRequests in sequence */
030    public static final ActivationTypeEnum SEQUENTIAL = new ActivationTypeEnum(KewApiConstants.ROUTE_LEVEL_SEQUENCE, KewApiConstants.ROUTE_LEVEL_SEQUENTIAL_NAME, KewApiConstants.ROUTE_LEVEL_SEQUENCE_LABEL);
031    /** Routing should process the associated ActionRequests in parallel */
032    public static final ActivationTypeEnum PARALLEL = new ActivationTypeEnum(KewApiConstants.ROUTE_LEVEL_PARALLEL, KewApiConstants.ROUTE_LEVEL_PARALLEL_NAME, KewApiConstants.ROUTE_LEVEL_PARALLEL_LABEL);
033    /** Routing should process the associated ActionRequests in parallel according to priority */
034    public static final ActivationTypeEnum PRIORITY_PARALLEL = new ActivationTypeEnum(KewApiConstants.ROUTE_LEVEL_PRIORITY_PARALLEL, KewApiConstants.ROUTE_LEVEL_PRIORITY_PARALLEL_NAME, KewApiConstants.ROUTE_LEVEL_PRIORITY_PARALLEL_LABEL);
035
036    private final String code;
037    private final String name;
038    private final String label;
039
040    private ActivationTypeEnum(String code, String name, String label) {
041        this.code = code;
042        this.name = name;
043        this.label = label;
044    }
045
046    public String getCode() {
047        return code;
048    }
049
050    public String getName() {
051        return name;
052    }
053
054    public String getLabel() {
055        return label;
056    }
057
058    public String toString() {
059        return "[ActivationTypeEnum: code=" + code + ", name=" + name + ", label=" + label + "]";
060    }
061
062    /**
063     * Parses the code verbatim and returns the enum type that matches that code exactly
064     * @param code the activation type code
065     * @return the enum type
066     * @throws IllegalArgumentException if code is null, or invalid
067     */
068    public static ActivationTypeEnum lookupCode(String code) {
069        if (code == null) {
070            throw new IllegalArgumentException("Activation type code must be non-null");
071        }
072        if (SEQUENTIAL.code.equals(code)) {
073            return SEQUENTIAL;
074        } else if (PARALLEL.code.equals(code)) {
075            return PARALLEL;
076        } else if (PRIORITY_PARALLEL.code.equals(code)) {
077            return PRIORITY_PARALLEL;
078        } else {
079            throw new IllegalArgumentException("Invalid activation code: '" + code + "'");
080        }
081    }
082
083    /**
084     * Parses the string and returns the enum type whose code, name, or label
085     * matches the string regardless of case
086     * @param string the activation type string
087     * @return the enum type
088     * @throws IllegalArgumentException if string is null, or invalid
089     */
090    public static ActivationTypeEnum parse(String string) {
091        if (string == null) {
092            throw new IllegalArgumentException("Activation type string must be non-null");
093        }
094        if (SEQUENTIAL.code.equalsIgnoreCase(string) ||
095            SEQUENTIAL.name.equalsIgnoreCase(string) ||
096            SEQUENTIAL.label.equalsIgnoreCase(string)) {
097            return SEQUENTIAL;
098        } else if (PARALLEL.code.equalsIgnoreCase(string) ||
099            PARALLEL.name.equalsIgnoreCase(string) ||
100            PARALLEL.label.equalsIgnoreCase(string)) {
101            return PARALLEL;
102        } else if (PRIORITY_PARALLEL.code.equalsIgnoreCase(string) ||
103            PRIORITY_PARALLEL.name.equalsIgnoreCase(string) ||
104            PRIORITY_PARALLEL.label.equalsIgnoreCase(string)) {
105            return PRIORITY_PARALLEL;
106        } else {
107            throw new IllegalArgumentException("Invalid activation type: '" + string + "'");
108        }
109    }
110}