All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jharks.workflow.Action Maven / Gradle / Ivy

package org.jharks.workflow;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jharks.workflow.exception.WorkFlowActionException;


/**
 * The Action class is an abstract class with a factory method that
 * allows for the instantiation of various action implementations.  This 
 * ultimately allows for new Action implementations to be written
 * and then plugged into the architecture by simply modifying the workflow 
 * XML configuration file.
 * @author Michael J. Rizzo
 * @version 1.0
 */
public abstract class Action {

    /** The logger for the module. */
    protected Log logger = LogFactory.getLog(getClass().getName());
    
    protected List childActions;
    
    /**
     * Apply action.
     * @param input the submitted input.
     * @throws a WorkFlowActionException if error occurs applying
     *         the action.  Exceptions that want to be exposed to a UI should be
     *         thrown by the apply method within the action.
     */
    public abstract void apply(Object input) throws WorkFlowActionException;
    
    /**
     * Adds the Action to list of child actions.
     * @param action the child Action. 
     */
    public void appendChild(Action action) {
        if (childActions == null)
            childActions = new ArrayList();
        
        childActions.add(action);
        
    }
    
    public List getChildActions() {
        return childActions;
    }

    /**
     * Factory method for creation of Action implementations.
     * @param actionImplName the class name of action implementation to be 
     *        instantiated.
     * @return an instance of a Action object.
     * @throws ClassNotFoundException if can not find classname specified.
     * @throws IllegalAccessException if the protection on object constructor
     *         is violated.
     * @throws InstantiationException if error occurs while instantiating
     *         the object.
     */
    public static Action getActionInstance(String actionImplName)
                                            throws ClassNotFoundException, 
                                            IllegalAccessException, 
                                            InstantiationException {
        
        return (Action) Class.forName(actionImplName).newInstance();
        
    }
    
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy