Re: enhancement to digester

2003-01-30 Thread robert burrell donkin
hello Yunfeng Hou

(i could be wrong, but) commons-betwixt (http://jakarta.apache.org/commons/
betwixt) seems similar to your ideas. why not take a look at it and see if 
it is?

if it is, then i'd prefer to enhance betwixt than add this functionality 
to digester.

if it isn't, then you'll probably be able to explain to me the differences 
and we'll take it from there.

- robert

On Thursday, January 30, 2003, at 10:22 AM, Yunfeng Hou wrote:

Commons digester is very powerful, and it is rule
centered. It makes digester very useful, but at the
same time, not a easy job to write the rules. To deal
with a complex XML file, we will have to write many
rules for each class and it's properties, methods. I
feel it not very flexible and hard to mantain. What I
need is the following:
1. Using a xml config file to define the relationship
between Java Class and XML element. (XML rule is a
step forward, but not enough)
2. As simple as castor xml mapping, but still have the
power of digester.

With the tool I write myself, marshal an XML document
to a java object could be much easier. Here's the
sample.
I have an mapping file digester.xml.
=
mapping
	includedigester_inc.xml/include

	class name=net.yunfeng.digester.config.MappingInfo
xmlName=mapping
		object xmlName=class
type=net.yunfeng.digester.config.ClassInfo
method=addClass/
		method name=addInclude xmlName=include/
	/class

	class name=net.yunfeng.digester.config.ClassInfo
xmlName=class
		object
type=net.yunfeng.digester.config.PropertyInfo
method=addProperty/
		object type =
net.yunfeng.digester.config.MethodInfo
method=addMethod/
		object
type=net.yunfeng.digester.config.ObjectInfo
method=addObject/
	/class
	
	
	class name=net.yunfeng.digester.config.Methodnfo
xmlName=method
		object type=net.yunfeng.digester.config.ParamInfo
method=addParam/
	/class
	
	
/mapping
===

and digester_inc.xml
===
mapping
	class
name=net.yunfeng.digester.config.PropertyInfo
xmlName=property/
	class name=net.yunfeng.digester.config.ObjectInfo
xmlName=object/
	class name=net.yunfeng.digester.config.ParamInfo
xmlName=param/
/mapping
=
I can easily read these two files into my config
classes( I only list two of them)

MappingInfo.java
=
public class MappingInfo {
	
  private ArrayList classes = new ArrayList();
  private ArrayList includes = new ArrayList();
  // and the accessors of these two

  public void addClass(ClassInfo classInfo) {
classes.add(classInfo);
  }

  public void addInclude(String include) {
includes.add(include);
  }
}	

MethodInfo.java

public class MethodInfo {
	
  private String name;
  private String xmlName;
  private ArrayList params = new ArrayList();
  // and their accessors

  public void addParam(ParamInfo param) {
params.add(param);
  }
}


The code to digest it is:

URL file =
DigesterHelper.class.getClassLoader().getResource(net/yunfeng/digester/digester.
xml);
DigesterHelper helper = new DigesterHelper(file);
MappingInfo mappingInfo = (MappingInfo)
helper.load(file, MappingInfo.class);


The first statement is get a mapping file;
second statement is create a helper object and have it
load the mapping file to later use;
the last statement is to digester an xml file into an
specified java class. In this case, it happens to be
the same of the mapping file. :-)

Please note that you do not need to specify all the
properties of a class within the mapping file. The
tool will automatically add rules for all properties
of a class. So if the property has the same name as
the element name of XML, you can just leave the tool
handle it.

If you think it worth putting it into the code base,
will be more than happy to help.

Yunfeng Hou	


_
Do You Yahoo!?
雅虎节日大转盘惊喜不断 快乐节日好礼连连
http://cn.promo.yahoo.com/holiday/

From: Yunfeng Hou [EMAIL PROTECTED]
Date: Thu Jan 30, 2003  10:13:31 AM Europe/London
To: [EMAIL PROTECTED]
Subject: enhancement to digester


Commons digester is very powerful, and it is rule
centered. It makes digester very useful, but at the
same time, not a easy job to write the rules. To deal
with a complex XML file, we will have to write many
rules for each class and it's properties, methods. I
feel it not very flexible and hard to mantain. What I
need is the following:
1. Using a xml config file to define the relationship
between Java Class and XML element. (XML rule is a
step forward, but not enough)
2. As simple as castor xml mapping, but still have the
power of digester.

With the tool I write myself, marshal an XML

Re: Fwd: enhancement to digester

2003-01-30 Thread dion
Have you tried betwixt?
--
dIon Gillard, Multitask Consulting
Blog:  http://www.freeroller.net/page/dion/Weblog
Work:  http://www.multitask.com.au


Yunfeng Hou [EMAIL PROTECTED] wrote on 30/01/2003 09:22:25 PM:

 Commons digester is very powerful, and it is rule
 centered. It makes digester very useful, but at the
 same time, not a easy job to write the rules. To deal
 with a complex XML file, we will have to write many
 rules for each class and it's properties, methods. I
 feel it not very flexible and hard to mantain. What I
 need is the following:
 1. Using a xml config file to define the relationship
 between Java Class and XML element. (XML rule is a
 step forward, but not enough)
 2. As simple as castor xml mapping, but still have the
 power of digester.
 
 With the tool I write myself, marshal an XML document
 to a java object could be much easier. Here's the
 sample.
 I have an mapping file digester.xml.
 =
 mapping
includedigester_inc.xml/include
 
class name=net.yunfeng.digester.config.MappingInfo
 xmlName=mapping
   object xmlName=class
 type=net.yunfeng.digester.config.ClassInfo
 method=addClass/
   method name=addInclude xmlName=include/
/class
 
class name=net.yunfeng.digester.config.ClassInfo
 xmlName=class
   object
 type=net.yunfeng.digester.config.PropertyInfo
 method=addProperty/
   object type =
 net.yunfeng.digester.config.MethodInfo
 method=addMethod/
   object
 type=net.yunfeng.digester.config.ObjectInfo
 method=addObject/
/class
 
 
class name=net.yunfeng.digester.config.Methodnfo
 xmlName=method
   object type=net.yunfeng.digester.config.ParamInfo
 method=addParam/
/class
 
 
 /mapping
 ===
 
 and digester_inc.xml
 ===
 mapping
class
 name=net.yunfeng.digester.config.PropertyInfo
 xmlName=property/
class name=net.yunfeng.digester.config.ObjectInfo
 xmlName=object/
class name=net.yunfeng.digester.config.ParamInfo
 xmlName=param/
 /mapping
 =
 I can easily read these two files into my config
 classes( I only list two of them)
 
 MappingInfo.java
 =
 public class MappingInfo {
 
   private ArrayList classes = new ArrayList();
   private ArrayList includes = new ArrayList(); 
   // and the accessors of these two
 
   public void addClass(ClassInfo classInfo) {
 classes.add(classInfo);
   }
 
   public void addInclude(String include) {
 includes.add(include);
   }
 } 
 
 MethodInfo.java
 
 public class MethodInfo {
 
   private String name;
   private String xmlName;
   private ArrayList params = new ArrayList();
   // and their accessors
 
   public void addParam(ParamInfo param) {
 params.add(param);
   }
 }
 
 
 The code to digest it is:
 
 URL file =
 DigesterHelper.class.getClassLoader().
 getResource(net/yunfeng/digester/digester.xml);
 DigesterHelper helper = new DigesterHelper(file);
 MappingInfo mappingInfo = (MappingInfo)
 helper.load(file, MappingInfo.class);
 
 
 The first statement is get a mapping file;
 second statement is create a helper object and have it
 load the mapping file to later use;
 the last statement is to digester an xml file into an
 specified java class. In this case, it happens to be
 the same of the mapping file. :-)
 
 Please note that you do not need to specify all the
 properties of a class within the mapping file. The
 tool will automatically add rules for all properties
 of a class. So if the property has the same name as
 the element name of XML, you can just leave the tool
 handle it.
 
 If you think it worth putting it into the code base,
 will be more than happy to help.
 
 Yunfeng Hou 
 
 
 _
 Do You Yahoo!? 
 ÑÅ»¢½ÚÈÕ´óתÅ̾ªÏ²²»¶Ï ¿ìÀÖ½ÚÈÕºÃÀñÁ¬Á¬
 http://cn.promo.yahoo.com/holiday/
 - Message from Yunfeng Hou [EMAIL PROTECTED] on Thu, 30 Jan 
 2003 18:13:31 +0800 (CST) -
 
 To:
 
 [EMAIL PROTECTED]
 
 Subject:
 
 enhancement to digester
 
 Commons digester is very powerful, and it is rule
 centered. It makes digester very useful, but at the
 same time, not a easy job to write the rules. To deal
 with a complex XML file, we will have to write many
 rules for each class and it's properties, methods. I
 feel it not very flexible and hard to mantain. What I
 need is the following:
 1. Using a xml config file to define the relationship
 between Java Class and XML element. (XML rule