Re: [digester] new rule SetNestedPropertiesRule

2003-11-18 Thread robert burrell donkin
hi simon

just to let you know that i would have committed your patch but there's 
a broken lock in cvs :(

- robert

On 17 Nov 2003, at 09:34, Simon Kitching wrote:

On Tue, 2003-11-18 at 11:32, Simon Kitching wrote:
Hi,

Attached is a rule which behaves like a cross between 
SetPropertiesRule
and BeanPropertySetterRule-with-trailing-wildcard-match.
I should mention that this rule comes in very useful when using the
Plugins module. That module does not permit any wildcards in patterns
below plugin mount points. So the BeanPropertySetterRule + trailing
wildcards solution cannot be used, but this solution can.
Regards,

Simon

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: [digester] new rule SetNestedPropertiesRule

2003-11-18 Thread Simon Kitching
On Wed, 2003-11-19 at 12:30, robert burrell donkin wrote:
 hi simon
 
 just to let you know that i would have committed your patch but there's 
 a broken lock in cvs :(

Thanks Robert.

Since the new rule is considered acceptable, here's a patch that adds
the tests to build.xml. Hope that CVS issue doesn't cause you too much
headache..

Cheers,

Simon
Index: build.xml
===
RCS file: /home/cvspublic/jakarta-commons/digester/build.xml,v
retrieving revision 1.48
diff -u -r1.48 build.xml
--- build.xml	18 Oct 2003 13:40:46 -	1.48
+++ build.xml	19 Nov 2003 03:09:15 -
@@ -272,6 +272,7 @@
test.factory,
test.regex,
test.wdrules,
+   test.setnestedprops,
test.plugins
   
description=Run all unit test cases
@@ -477,6 +478,20 @@
   classpath refid=test.classpath/
 /java
   /target
+
+  target name=test.setnestedprops depends=compile.tests
+  description=Run SetNestedPropertiesRule tests ...
+echo message=Running SetNestedPropertiesRule tests .../
+condition property=logopt value=${log.factoryopt}=${log.class}
+  istrue value=${suppressLogOutputDuringTests}/
+/condition
+java classname=${test.runner} fork=yes
+failonerror=${test.failonerror}
+  jvmarg value=-D${logopt}/
+  arg value=org.apache.commons.digester.SetNestedPropertiesRuleTestCase/
+  classpath refid=test.classpath/
+/java
+  /target 
 
   target name=test.plugins depends=compile.tests
   description=Run Plugins tests ...

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

[digester] new rule SetNestedPropertiesRule

2003-11-17 Thread Simon Kitching
Hi,

Attached is a rule which behaves like a cross between SetPropertiesRule
and BeanPropertySetterRule-with-trailing-wildcard-match.

point
  x7/x
  y8/y
/point

digester.addRule(point, new SetNestedPropertiesRule());

Note that the rule doesn't need to use ExtendedBaseRules with trailing
wildcard (which is very powerful but not very efficient). It is
configured with the pattern matching the parent element.

The implementation uses a trick developed for the plugins module:
inserting a decorator Rules object that performs custom matching to
detect the direct child elements.

Yes, this functionality can already be achieved with Digester, but this
is pretty efficient and convenient, and this configuration pattern is a
common one.


Opinions??

Regards,

Simon
/*
 * $Header: $
 * $Revision: $
 * $Date: $
 *
 * 
 * 
 * The Apache Software License, Version 1.1
 *
 * Copyright (c) 2001-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 acknowledgement:  
 *   This product includes software developed by the 
 *Apache Software Foundation (http://www.apache.org/).
 *Alternately, this acknowledgement may appear in the software itself,
 *if and wherever such third-party acknowledgements normally appear.
 *
 * 4. The names Apache, 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,
 *Apache nor may Apache appear in their names without prior 
 *written permission of the Apache Software Foundation.
 *
 * 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;


import java.util.List;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.ListIterator;
import java.util.HashMap;
import java.beans.PropertyDescriptor;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.DynaBean;
import org.apache.commons.beanutils.DynaProperty;
import org.apache.commons.beanutils.PropertyUtils;

import org.xml.sax.Attributes;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


/**
 * pRule implementation that sets properties on the object at the top of the
 * stack, based on child elements with names matching properties on that 
 * object./p
 *
 * pExample input that can be processed by this rule:/p
 * pre
 * [point]
 *  [x]7[/x]
 *  [y]9[/y]
 * [/point]
 * /pre
 *
 * pThis rule supports custom mapping of attribute names to property names.
 * The default mapping for particular attributes can be overridden by using 
 * [EMAIL PROTECTED] #SetNestedPropertiesRule(String[] elementNames,
 * String[] propertyNames)}.
 * This allows child elements to be mapped to properties with different names.
 * Certain elements can also be marked to be ignored./p
 *
 * p
 * A very similar effect can be achieved using a combination of the 
 * BeanPropertySetterRule and the ExtendedBaseRules rules manager; this
 * Rule, however, works fine with the default RulesBase rules manager./p
 *
 * 

Re: [digester] new rule SetNestedPropertiesRule

2003-11-17 Thread Simon Kitching
On Tue, 2003-11-18 at 11:32, Simon Kitching wrote:
 Hi,
 
 Attached is a rule which behaves like a cross between SetPropertiesRule
 and BeanPropertySetterRule-with-trailing-wildcard-match.

I should mention that this rule comes in very useful when using the
Plugins module. That module does not permit any wildcards in patterns
below plugin mount points. So the BeanPropertySetterRule + trailing
wildcards solution cannot be used, but this solution can.

Regards,

Simon


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]