Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@apache.org Received: (qmail 60076 invoked from network); 18 Dec 2001 22:42:39 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 18 Dec 2001 22:42:39 -0000 Received: (qmail 10610 invoked by uid 97); 18 Dec 2001 22:42:44 -0000 Delivered-To: qmlist-jakarta-archive-commons-dev@jakarta.apache.org Received: (qmail 10577 invoked by uid 97); 18 Dec 2001 22:42:43 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 10566 invoked from network); 18 Dec 2001 22:42:43 -0000 Message-ID: <00b901c18815$744ae280$1f00a8c0@stepston4undxv> From: "Mika Goeckel" To: "Jakarta Commons Developers List" Subject: third patch for digester -> selfConfiguring objects :-) minimal change following Rob Donkin's and Craig's advice Date: Tue, 18 Dec 2001 23:43:45 +0100 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_00B6_01C1881D.D4EEBF50" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4807.1700 X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N ------=_NextPart_000_00B6_01C1881D.D4EEBF50 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hey! This one is rather minimalistic, but gives all to me that I need. Some documentation is in the class javadoc of the SelfConfigureObject Interface. Mika ------=_NextPart_000_00B6_01C1881D.D4EEBF50 Content-Type: application/octet-stream; name="commons.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="commons.diff" ? = jakarta-commons/digester/src/java/org/apache/commons/digester/SelfConfigu= reObject.java Index: = jakarta-commons/digester/src/java/org/apache/commons/digester/Digester.ja= va =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: = /home/cvspublic/jakarta-commons/digester/src/java/org/apache/commons/dige= ster/Digester.java,v retrieving revision 1.29 diff -w -r1.29 Digester.java 315d314 <=20 1740a1740,1746 > /** > * After a startElement() call during parse(), this method > * returns the matched pattern. > */ > public String getMatch(){ > return match; > } 1877d1882 <=20 Index: = jakarta-commons/digester/src/java/org/apache/commons/digester/ObjectCreat= eRule.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: = /home/cvspublic/jakarta-commons/digester/src/java/org/apache/commons/dige= ster/ObjectCreateRule.java,v retrieving revision 1.6 diff -w -r1.6 ObjectCreateRule.java 155a156,162 >=20 > // If this object implements the SelfConfigureObject interface, > // we give it a chance to add rules. > if(instance instanceof SelfConfigureObject){ > = ((SelfConfigureObject)instance).configureAdditionalRules(digester); > } >=20 ------=_NextPart_000_00B6_01C1881D.D4EEBF50 Content-Type: application/octet-stream; name="SelfConfigureObject.java" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="SelfConfigureObject.java" package org.apache.commons.digester; /** * Interface to enable objects created by the ObjectCreationRule * to add it's own rules for sub elements. * After the object has been created, the configureAdditionalRules() = method of it is called. In this method, the object may register = additional rules, that are processed when the parsing of the XML = document is continued. Rules are not applied backwards. *=20 * This enables developers to create configurable child objects = depending on what parent object is really instantiated. * For example, Valve usually has no child objects * . If you want to create childs, you have to pass all necessary = configuration as attributes to the Valve. With SelfConfigureObjects, a = specific implementation can add further rules. If for example FancyValve = needs a FancyValveRessource and a FancyValveManager as child objects, = you don't need to change the location where this Valve is configured to = be created by the Digester, but instead you can simply implement the = SelfConfigureObject interface and put the digester configuration code in = your configreAdditionalRules method: *
 * public class FancyValve extends ValveBase implements Lifecycle, =
SelfConfigureObject {
 *=20
 * 	// ...
 *=20
 * 	public void configureAdditionalRules(Digester digester){
 *
 *              String pattern =3D digester.getMatch();
 *=20
 *         		digester.addObjectCreate(pattern + "/FancyValveRessource",
 *                                  		null, // MUST be specified in the =
element
 *                                  		"className");
 *         		digester.addSetProperties(pattern + =
"/FancyValveRessource");
 *         		digester.addSetNext(pattern + "/FancyValveRessource",
 *                             	"setValveRessource",
 *                             	=
"my.domain.valves.ValveRessourceInterface");
 *=20
 *         		digester.addObjectCreate(pattern + "/FancyValveManager",
 *                                  		null, // MUST be specified in the =
element
 *                                  		"className");
 *         		digester.addSetProperties(pattern + "/FancyValveManager");
 *         		digester.addSetNext(pattern + "/FancyValveManager",
 *                             	"setManager",
 *                             	"my.domain.valves.FancyValveManager");
 * 	}
 *=20
 * }
 * 
* The digester callback getMatch() enables you to create matching rules = relative to the matched parent. For example if you place the example = valve under <Host/> and under <Engine/>, the absolute = matchstring would need to be different. However, you are not restricted = to provide rules below the matched rule. The only restriction is, that = all rules you add are only matched down the document, i.e. to all tags = that are processed after the tag that lead to the creation of that = rules. * @author Mika G=F6ckel mika@goeckel.net */ public interface SelfConfigureObject { /** This method is called directly after the object is * created. * @param Digester The digester that created the object */ public void configureAdditionalRules(Digester digester); } ------=_NextPart_000_00B6_01C1881D.D4EEBF50 Content-Type: text/plain; charset=us-ascii -- To unsubscribe, e-mail: For additional commands, e-mail: ------=_NextPart_000_00B6_01C1881D.D4EEBF50--