cvs commit: jakarta-commons/digester/src/java/org/apache/commons/digester/plugins PluginRules.java
skitching2004/06/10 20:48:50 Modified:digester/src/java/org/apache/commons/digester/plugins PluginRules.java Log: Add a rulesFactory member. The rulesFactory (if not null) is used to create the underlying Rules implementation rather than hardwiring RulesBase as the implementation. Revision ChangesPath 1.18 +34 -6 jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/PluginRules.java Index: PluginRules.java === RCS file: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/PluginRules.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- PluginRules.java 10 May 2004 06:44:13 - 1.17 +++ PluginRules.java 11 Jun 2004 03:48:50 - 1.18 @@ -64,6 +64,11 @@ protected Digester digester = null; /** + * The (optional) object which generates new rules instances. + */ +private RulesFactory rulesFactory; + +/** * The rules implementation that we are enhancing with plugins * functionality, as per the Decorator pattern. */ @@ -126,17 +131,24 @@ * to begin. * @param parent must be non-null. */ - PluginRules(String mountPoint, PluginRules parent) { + PluginRules(String mountPoint, PluginRules parent, Class pluginClass) + throws PluginException { // no need to set digester or decoratedRules.digester, // because when Digester.setRules is called, the setDigester // method on this object will be called. -decoratedRules = new RulesBase(); -pluginContext = parent.pluginContext; -pluginManager = new PluginManager(parent.pluginManager); - this.mountPoint = mountPoint; this.parent = parent; +this.rulesFactory = parent.rulesFactory; + +if (rulesFactory == null) { +decoratedRules = new RulesBase(); +} else { +decoratedRules = rulesFactory.newRules(digester, pluginClass); +} + +pluginContext = parent.pluginContext; +pluginManager = new PluginManager(parent.pluginManager); } // - Properties @@ -208,6 +220,21 @@ pluginContext.setRuleFinders(ruleFinders); } +/** + * Return the rules factory object (or null if one has not been specified). + */ +public RulesFactory getRulesFactory() { +return rulesFactory; +} + +/** + * Set the object which is used to generate the new Rules instances created + * to hold and process the rules associated with each plugged-in class. + */ +public void setRulesFactory(RulesFactory factory) { +rulesFactory = factory; +} + // - Public Methods /** @@ -360,6 +387,7 @@ // this same path. See PluginCreateRule's begin, body and end // methods for the reason. } else { +log.debug(delegating to decorated rules.); matches = decoratedRules.match(namespaceURI, path); } - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: jakarta-commons/digester/src/java/org/apache/commons/digester/plugins PluginRules.java
skitching2004/04/07 02:34:24 Modified:digester/src/java/org/apache/commons/digester/plugins Tag: DIGESTER_PLUGIN_REFACTORING_BRANCH PluginRules.java Log: PerDigesterResources-PluginContext Revision ChangesPath No revision No revision 1.12.2.2 +26 -21 jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/PluginRules.java Index: PluginRules.java === RCS file: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/PluginRules.java,v retrieving revision 1.12.2.1 retrieving revision 1.12.2.2 diff -u -r1.12.2.1 -r1.12.2.2 --- PluginRules.java 28 Mar 2004 06:16:17 - 1.12.2.1 +++ PluginRules.java 7 Apr 2004 09:34:24 - 1.12.2.2 @@ -86,7 +86,7 @@ * A reference to the object that holds all data which should only * exist once per digester instance. */ -private PerDigesterResources perDigesterResources = null; +private PluginContext pluginContext = null; // - Constructor @@ -106,8 +106,8 @@ public PluginRules(Rules decoratedRules) { this.decoratedRules = decoratedRules; -perDigesterResources = new PerDigesterResources(); -pluginManager = new PluginManager(perDigesterResources); +pluginContext = new PluginContext(); +pluginManager = new PluginManager(pluginContext); } /** @@ -117,6 +117,11 @@ * One of these is created each time a PluginCreateRule's begin method * fires, in order to manage the custom rules associated with whatever * concrete plugin class the user has specified. + * + * @param mountPoint is the digester match path for the element + * matching a PluginCreateRule which caused this nested parsing scope + * to begin. + * @param parent must be non-null. */ PluginRules(String mountPoint, PluginRules parent) { // no need to set digester or decoratedRules.digester, @@ -124,8 +129,8 @@ // method on this object will be called. decoratedRules = new RulesBase(); -perDigesterResources = parent.perDigesterResources; -pluginManager = new PluginManager(perDigesterResources, parent.pluginManager); +pluginContext = parent.pluginContext; +pluginManager = new PluginManager(parent.pluginManager); this.mountPoint = mountPoint; this.parent = parent; @@ -187,17 +192,17 @@ } /** - * See [EMAIL PROTECTED] PerDigesterResources#getRuleFinders}. + * See [EMAIL PROTECTED] PluginContext#getRuleFinders}. */ public List getRuleFinders() { -return perDigesterResources.getRuleFinders(); +return pluginContext.getRuleFinders(); } /** - * See [EMAIL PROTECTED] PerDigesterResources#setRuleFinders}. + * See [EMAIL PROTECTED] PluginContext#setRuleFinders}. */ public void setRuleFinders(List ruleFinders) { -perDigesterResources.setRuleFinders(ruleFinders); +pluginContext.setRuleFinders(ruleFinders); } // - Public Methods @@ -358,35 +363,35 @@ return matches; } -/** See [EMAIL PROTECTED] PerDigesterResources#setPluginClassAttribute}. */ +/** See [EMAIL PROTECTED] PluginContext#setPluginClassAttribute}. */ public void setPluginClassAttribute(String namespaceUri, String attrName) { -perDigesterResources.setPluginClassAttribute(namespaceUri, attrName); +pluginContext.setPluginClassAttribute(namespaceUri, attrName); } -/** See [EMAIL PROTECTED] PerDigesterResources#setPluginIdAttribute}. */ +/** See [EMAIL PROTECTED] PluginContext#setPluginIdAttribute}. */ public void setPluginIdAttribute(String namespaceUri, String attrName) { -perDigesterResources.setPluginIdAttribute(namespaceUri, attrName); +pluginContext.setPluginIdAttribute(namespaceUri, attrName); } -/** See [EMAIL PROTECTED] PerDigesterResources#getPluginClassAttrNs}. */ +/** See [EMAIL PROTECTED] PluginContext#getPluginClassAttrNs}. */ public String getPluginClassAttrNs() { -return perDigesterResources.getPluginClassAttrNs(); +return pluginContext.getPluginClassAttrNs(); } -/** See [EMAIL PROTECTED] PerDigesterResources#getPluginClassAttr}. */ +/** See [EMAIL PROTECTED] PluginContext#getPluginClassAttr}. */ public String getPluginClassAttr() { -return
cvs commit: jakarta-commons/digester/src/java/org/apache/commons/digester/plugins PluginRules.java
skitching2004/03/27 22:16:17 Modified:digester/src/java/org/apache/commons/digester/plugins Tag: DIGESTER_PLUGIN_REFACTORING_BRANCH PluginRules.java Log: * the root PluginRules object for a Digester now creates an instance of PerDigesterResources, others get a ref to a pre-existing one * added getter/setter methods to acecss data on the underlying PerDigesterResources object. Some of these methods were previously on the PluginCreateRules class. Revision ChangesPath No revision No revision 1.12.2.1 +60 -7 jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/PluginRules.java Index: PluginRules.java === RCS file: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/PluginRules.java,v retrieving revision 1.12 retrieving revision 1.12.2.1 diff -u -r1.12 -r1.12.2.1 --- PluginRules.java 23 Mar 2004 07:11:00 - 1.12 +++ PluginRules.java 28 Mar 2004 06:16:17 - 1.12.2.1 @@ -82,6 +82,12 @@ */ private PluginRules parent = null; +/** + * A reference to the object that holds all data which should only + * exist once per digester instance. + */ +private PerDigesterResources perDigesterResources = null; + // - Constructor /** @@ -90,8 +96,7 @@ * object before parsing starts. */ public PluginRules() { -decoratedRules = new RulesBase(); -pluginManager = new PluginManager(); +this(new RulesBase()); } /** @@ -100,7 +105,9 @@ */ public PluginRules(Rules decoratedRules) { this.decoratedRules = decoratedRules; -pluginManager = new PluginManager(); + +perDigesterResources = new PerDigesterResources(); +pluginManager = new PluginManager(perDigesterResources); } /** @@ -117,7 +124,8 @@ // method on this object will be called. decoratedRules = new RulesBase(); -pluginManager = new PluginManager(parent.pluginManager); +perDigesterResources = parent.perDigesterResources; +pluginManager = new PluginManager(perDigesterResources, parent.pluginManager); this.mountPoint = mountPoint; this.parent = parent; @@ -177,7 +185,21 @@ public PluginManager getPluginManager() { return pluginManager; } - + +/** + * See [EMAIL PROTECTED] PerDigesterResources#getRuleFinders}. + */ +public List getRuleFinders() { +return perDigesterResources.getRuleFinders(); +} + +/** + * See [EMAIL PROTECTED] PerDigesterResources#setRuleFinders}. + */ +public void setRuleFinders(List ruleFinders) { +perDigesterResources.setRuleFinders(ruleFinders); +} + // - Public Methods /** @@ -329,11 +351,42 @@ // even though this object may hold some rules matching // this same path. See PluginCreateRule's begin, body and end // methods for the reason. -} -else { +} else { matches = decoratedRules.match(namespaceURI, path); } return matches; +} + +/** See [EMAIL PROTECTED] PerDigesterResources#setPluginClassAttribute}. */ +public void setPluginClassAttribute(String namespaceUri, +String attrName) { +perDigesterResources.setPluginClassAttribute(namespaceUri, attrName); +} + +/** See [EMAIL PROTECTED] PerDigesterResources#setPluginIdAttribute}. */ +public void setPluginIdAttribute(String namespaceUri, + String attrName) { +perDigesterResources.setPluginIdAttribute(namespaceUri, attrName); +} + +/** See [EMAIL PROTECTED] PerDigesterResources#getPluginClassAttrNs}. */ +public String getPluginClassAttrNs() { +return perDigesterResources.getPluginClassAttrNs(); +} + +/** See [EMAIL PROTECTED] PerDigesterResources#getPluginClassAttr}. */ +public String getPluginClassAttr() { +return perDigesterResources.getPluginClassAttr(); +} + +/** See [EMAIL PROTECTED] PerDigesterResources#getPluginIdAttrNs}. */ +public String getPluginIdAttrNs() { +return perDigesterResources.getPluginIdAttrNs(); +} + +/** See [EMAIL PROTECTED] PerDigesterResources#getPluginIdAttr}. */ +public String getPluginIdAttr() { +return perDigesterResources.getPluginIdAttr(); } }
cvs commit: jakarta-commons/digester/src/java/org/apache/commons/digester/plugins PluginRules.java
rdonkin 2003/11/18 14:32:16 Modified:digester/src/java/org/apache/commons/digester/plugins PluginRules.java Log: Corrects patterns that begin with a leading slash. Submitted by Simon Kitching. Revision ChangesPath 1.7 +12 -4 jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/PluginRules.java Index: PluginRules.java === RCS file: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/PluginRules.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- PluginRules.java 16 Nov 2003 22:37:35 - 1.6 +++ PluginRules.java 18 Nov 2003 22:32:16 - 1.7 @@ -224,7 +224,9 @@ /** * Register a new Rule instance matching the specified pattern. * - * @param pattern Nesting pattern to be matched for this Rule + * @param pattern Nesting pattern to be matched for this Rule. + * This parameter treats equally patterns that begin with and without + * a leading slash ('/'). * @param rule Rule instance to be registered */ public void add(String pattern, Rule rule) { @@ -234,6 +236,12 @@ if (debug) { log.debug(add entry + : mapping pattern [ + pattern + ] + to rule of type [ + rule.getClass().getName() + ]); +} + +// allow patterns with a leading slash character +if (pattern.startsWith(/)) +{ +pattern = pattern.substring(1); } decoratedRules.add(pattern, rule); - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: jakarta-commons/digester/src/java/org/apache/commons/digester/plugins PluginRules.java
rdonkin 2003/10/04 05:29:53 Added: digester/src/java/org/apache/commons/digester/plugins PluginRules.java Log: Added plugins module. Submitted by Simon Kitching. Revision ChangesPath 1.1 jakarta-commons/digester/src/java/org/apache/commons/digester/plugins/PluginRules.java Index: PluginRules.java === /* * * * The Apache Software License, Version 1.1 * * Copyright (c) 1999-2003 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.digester.plugins; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.ListIterator; import java.util.Map; import java.util.HashMap; import java.util.TreeMap; import java.util.Comparator; import org.apache.commons.digester.Digester; import org.apache.commons.digester.Rule; import org.apache.commons.digester.Rules; import org.apache.commons.digester.RulesBase; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * A custom digester Rules manager which must be used as the Rules object * when using the plugins module functionality. * /p * @author Simon Kitching */ public class PluginRules implements Rules { private static Log log = LogFactory.getLog(PluginRules.class); /** * The rules implementation that we are enhancing with plugins * functionality, as per the Decorator pattern. */ private Rules decoratedRules_; /** * The Digester instance with which this Rules instance is associated. */ protected Digester digester_ = null; /** * The currently active PluginCreateRule. When the begin method of a * PluginCreateRule is encountered, this is set. When the end method is * encountered, this is cleared. Any attempt to call match() while this * attribute is set just causes this single rule to be returned. */ private PluginCreateRule currPluginCreateRule_ = null; /** Object which contains information about all known plugins. */ private PluginManager pluginManager_; /** The parent rules object for this object. */ private