craigmcc 01/08/13 14:16:46 Added: workflow/src/java/org/apache/commons/workflow/demo Main.java main.xml Log: Initial check-in of the workflow management system proposal. Revision Changes Path 1.1 jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/demo/Main.java Index: Main.java =================================================================== /* * $Header: /home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/demo/Main.java,v 1.1 2001/08/13 21:16:46 craigmcc Exp $ * $Revision: 1.1 $ * $Date: 2001/08/13 21:16:46 $ * * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Commons", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * */ package org.apache.commons.workflow.demo; import java.io.File; import org.apache.commons.digester.Digester; import org.apache.commons.workflow.Activity; import org.apache.commons.workflow.Context; import org.apache.commons.workflow.base.BaseContext; /** * <p>Demonstration program to illustrate how the Workflow Management System * is utilized. It accepts a command line argument to an XML file that * contains an <code><activity></code> to be parsed and then executed. * If no file is specified, a default XML document will be utilized.</p> * * <p><strong>WARNING</strong> - This program is for illustration only while * the workflow management system is being developed, and it will not be * part of the final package. Indeed, much of its functionality (such as * the parsing of XML files describing activities) will need to be encapsulated * inside the system, in ways that support the per-namespace step definitions * as outlined in the original proposal.</p> * * <p><strong>WARNING</strong> - This code depends on the version of Digester * currently in CVS - the 1.0 released version will not work correctly with * namespace prefixes.</p> * * <p><strong>WARNING</strong> - The namespace URLs in the example XML document * are not official - they are simply used to satisfy the syntax requirements * of the XML parser. Official namespace URIs <em>will</em> be required for a * formal release of this technology, because that is key to the extensibility * of Step implementations.</p> * * @version $Revision: 1.1 $ $Date: 2001/08/13 21:16:46 $ * @author Craig R. McClanahan */ public class Main { // ----------------------------------------------------------- Main Program /** * The main program for the demo. * * @param args Command line arguments */ public static void main(String args[]) { // Make sure there is a filename argument if (args.length != 1) { System.out.println("Usage: java org.apache.commons.workflow.demo.Main {XML-file}"); System.exit(1); } // Construct and utilize a new instance of this class Main main = new Main(); main.process(args[0]); } // ----------------------------------------------------- Instance Variables /** * The Activity constructed by our Digester. */ protected Activity activity = null; /** * The Digester used to process input files. */ protected Digester digester = null; // ------------------------------------------------------------ Constructor /** * Construct a new instance of this class to process input files. */ public Main() { super(); digester = createDigester(); } // -------------------------------------------------------- Support Methods /** * <p>Create a Digester instance that knows how to parse activities using * the <code>core</code> and <code>io</code> built-in Steps.</p> * * <p><strong>WARNING</strong> - This will ultimately be abstracted into * a mechanism to register the set of rule definitions associated with * a namespace.</p> */ protected Digester createDigester() { // Construct and configure a new Digester instance Digester digester = new Digester(); // digester.setDebug(999); digester.setNamespaceAware(true); digester.setValidating(false); digester.push(this); // Add rules to recognize the built-in steps that we know about digester.addObjectCreate ("activity", "org.apache.commons.workflow.base.BaseActivity"); digester.addSetProperties ("activity"); digester.addSetNext ("activity", "setActivity", "org.apache.commons.workflow.Activity"); digester.addObjectCreate ("activity/core:duplicate", "org.apache.commons.workflow.core.DuplicateStep"); digester.addSetProperties ("activity/core:duplicate"); digester.addSetNext ("activity/core:duplicate", "addStep", "org.apache.commons.workflow.Step"); digester.addObjectCreate ("activity/core:exit", "org.apache.commons.workflow.core.ExitStep"); digester.addSetProperties ("activity/core:exit"); digester.addSetNext ("activity/core:exit", "addStep", "org.apache.commons.workflow.Step"); digester.addObjectCreate ("activity/core:get", "org.apache.commons.workflow.core.GetStep"); digester.addSetProperties ("activity/core:get"); digester.addSetNext ("activity/core:get", "addStep", "org.apache.commons.workflow.Step"); digester.addObjectCreate ("activity/core:pop", "org.apache.commons.workflow.core.PopStep"); digester.addSetProperties ("activity/core:pop"); digester.addSetNext ("activity/core:pop", "addStep", "org.apache.commons.workflow.Step"); digester.addObjectCreate ("activity/core:put", "org.apache.commons.workflow.core.PutStep"); digester.addSetProperties ("activity/core:put"); digester.addSetNext ("activity/core:put", "addStep", "org.apache.commons.workflow.Step"); digester.addObjectCreate ("activity/core:remove", "org.apache.commons.workflow.core.RemoveStep"); digester.addSetProperties ("activity/core:remove"); digester.addSetNext ("activity/core:remove", "addStep", "org.apache.commons.workflow.Step"); digester.addObjectCreate ("activity/core:string", "org.apache.commons.workflow.core.StringStep"); digester.addSetProperties ("activity/core:string"); digester.addSetNext ("activity/core:string", "addStep", "org.apache.commons.workflow.Step"); digester.addObjectCreate ("activity/core:suspend", "org.apache.commons.workflow.core.SuspendStep"); digester.addSetProperties ("activity/core:suspend"); digester.addSetNext ("activity/core:suspend", "addStep", "org.apache.commons.workflow.Step"); digester.addObjectCreate ("activity/core:swap", "org.apache.commons.workflow.core.SwapStep"); digester.addSetProperties ("activity/core:swap"); digester.addSetNext ("activity/core:swap", "addStep", "org.apache.commons.workflow.Step"); digester.addObjectCreate ("activity/io:display", "org.apache.commons.workflow.io.DisplayStep"); digester.addSetProperties ("activity/io:display"); digester.addSetNext ("activity/io:display", "addStep", "org.apache.commons.workflow.Step"); digester.addObjectCreate ("activity/io:get", "org.apache.commons.workflow.io.GetStep"); digester.addSetProperties ("activity/io:get"); digester.addSetNext ("activity/io:get", "addStep", "org.apache.commons.workflow.Step"); digester.addObjectCreate ("activity/io:peek", "org.apache.commons.workflow.io.PeekStep"); digester.addSetProperties ("activity/io:peek"); digester.addSetNext ("activity/io:peek", "addStep", "org.apache.commons.workflow.Step"); digester.addObjectCreate ("activity/io:read", "org.apache.commons.workflow.io.ReadStep"); digester.addSetProperties ("activity/io:read"); digester.addSetNext ("activity/io:read", "addStep", "org.apache.commons.workflow.Step"); digester.addObjectCreate ("activity/io:write", "org.apache.commons.workflow.io.WriteStep"); digester.addSetProperties ("activity/io:write"); digester.addSetNext ("activity/io:write", "addStep", "org.apache.commons.workflow.Step"); digester.addObjectCreate ("activity/web:forward", "org.apache.commons.workflow.web.ForwardStep"); digester.addSetProperties ("activity/web:forward"); digester.addSetNext ("activity/web:forward", "addStep", "org.apache.commons.workflow.Step"); /* FIXME - pick correct implementation for Servlet 2.2 or 2.3! digester.addObjectCreate ("activity/web:include", "org.apache.commons.workflow.web.IncludeStep"); digester.addSetProperties ("activity/web:include"); digester.addSetNext ("activity/web:include", "addStep", "org.apache.commons.workflow.Step"); */ // Return the completed instance return (digester); } /** * Save the Activity that our Digester has constructed. * * @param activity The newly constructed Activity */ public void setActivity(Activity activity) { this.activity = activity; } /** * Process the specified file. * * @param pathname Pathname of the specified XML file containing * an activity definition */ public void process(String pathname) { // Parse the activity definition try { System.out.println("Main: Parsing activity file " + pathname); digester.parse(new File(pathname)); } catch (Throwable t) { t.printStackTrace(System.out); return; } // Create a context and execute this activity try { System.out.println("Main: Executing parsed activity"); Context context = new BaseContext(); context.setActivity(activity); context.execute(); } catch (Throwable t) { t.printStackTrace(System.out); return; } } } 1.1 jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/demo/main.xml Index: main.xml =================================================================== <activity id="Demostration Activity" xmlns:core="http://jakarta.apache.org/workflow/core" xmlns:io="http://jakarta.apache.org/workflow/io" xmlns:web="http://jakarta.apache.org/workflow/web"> <core:string value="This is a string value"/> <core:put name="foo"/> <core:get name="foo" scope="local"/> <io:peek/> </activity>