001 /* 002 * Copyright 1999-2001,2004 The Apache Software Foundation. 003 * 004 * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0 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 */ 016 017 018 package org.apache.commons.workflow.base; 019 020 021 import org.apache.commons.digester.Digester; 022 import org.apache.commons.digester.Rule; 023 import org.apache.commons.digester.RuleSet; 024 import org.apache.commons.digester.RuleSetBase; 025 026 027 /** 028 * <p><strong>RuleSet</strong> for the basic Activity definitions of the 029 * Workflow Management System, typically associated with the <em>base</em> 030 * prefix. This library is normally associated with the namespace URI:</p> 031 * <pre> 032 * http://commons.apache.org/workflow/base 033 * </pre> 034 * 035 * <p>This class also serves as a convenience base class for the 036 * <code>RuleSet</code> implementations for Step libraries. Subclasses 037 * MUST override the no-arguments constructor to set the correct 038 * namespace URI, and MUST override (and replace) the 039 * <code>addRuleInstances()</code> method to add the relevant rules 040 * for that particular library. 041 * 042 * @author Craig R. McClanahan 043 * @version $Revision: 561366 $ $Date: 2007-07-31 16:58:29 +0100 (Tue, 31 Jul 2007) $ 044 */ 045 046 public class BaseRuleSet extends RuleSetBase { 047 048 049 // ------------------------------------------------------------ Constructor 050 051 052 /** 053 * Construct a default instance of the <code>RuleSet</code>. 054 */ 055 public BaseRuleSet() { 056 057 super(); 058 setNamespaceURI("http://commons.apache.org/workflow/base"); 059 060 } 061 062 063 // ------------------------------------------------------------- Properties 064 065 066 /** 067 * Set the namespace URI that these rules apply to. This is only needed 068 * if you want to reset the default value created by a subclass. 069 * 070 * @param namespaceURI The new namespace URI 071 */ 072 public void setNamespaceURI(String namespaceURI) { 073 this.namespaceURI = namespaceURI; 074 } 075 076 077 // --------------------------------------------------------- Public Methods 078 079 080 /** 081 * <p>Add the set of Rule instances defined in this RuleSet to the 082 * specified <code>Digester</code> instance, associating them with 083 * our namespace URI (if any). This method should only be called 084 * by a Digester instance.</p> 085 * 086 * @param digester Digester instance to which the new Rule instances 087 * should be added. 088 */ 089 public void addRuleInstances(Digester digester) { 090 091 digester.addObjectCreate("activity", 092 "org.apache.commons.workflow.base.BaseActivity"); 093 digester.addSetProperties("activity"); 094 095 } 096 097 098 // ------------------------------------------------------ Protected Methods 099 100 101 /** 102 * Add the standard set of rules for a new Descriptor that should be 103 * recognized. 104 * 105 * @param digester Digester to which we are adding new rules 106 * @param element Element name to be matched 107 */ 108 protected void addStandardDescriptor(Digester digester, String element) { 109 110 String pattern = "*/" + element; 111 digester.addObjectCreate(pattern, 112 "org.apache.commons.workflow.base.BaseDescriptor"); 113 digester.addSetProperties(pattern); 114 digester.addSetNext(pattern, "addDescriptor", 115 "org.apache.commons.workflow.Descriptor"); 116 117 } 118 119 120 /** 121 * Add the standard set of rules for a new Step that should be recognized. 122 * 123 * @param digester Digester to which we are adding new rules 124 * @param element Element name to be matched 125 * @param name Fully qualified class name of the implementation class 126 */ 127 protected void addStandardStep(Digester digester, String element, 128 String name) { 129 130 String pattern = "*/" + element; 131 digester.addObjectCreate(pattern, name); 132 digester.addSetProperties(pattern); 133 digester.addSetNext(pattern, "addStep", 134 "org.apache.commons.workflow.Step"); 135 136 } 137 138 139 }