Re: Digester problem

2007-06-29 Thread James Carman

Have you tried an ObjectCreate followed by a SetProperties?

On 6/28/07, Poulton, Jonathan [EMAIL PROTECTED] wrote:


Hi there,
I've tried finding a solution to what I think should be quite a simple
problem using the Commons Digester, but the tutorials I can find on the
subject only really cover the basics and aren't of any help.

Given an XML fragment like the following:

article id=_1234
text.../text
/article

I need the Digester to call a method on an Article class, with the
following signiture:

public void setId(long id);

In other words I just need a Rule that will fire for an XML id
attribute, and remove an underscore from the front of a String before
converting it to a long, and calling the appropriate method.

I realise that this will require some kind of custom class to chop up
the String, but the pattern you apply to matching the rule
(article/id) appears to refer to a nested id element, rather than an
id attribute.

I can't seem to find an example of this anywhere. All the custom rules
examples appear to refer to nested elements. Any suggestions? Have I
missed something in the API?

Cheers

Jon





Digester problem

2007-06-28 Thread Poulton, Jonathan
Hi there,
I've tried finding a solution to what I think should be quite a simple
problem using the Commons Digester, but the tutorials I can find on the
subject only really cover the basics and aren't of any help. 
 
Given an XML fragment like the following:
 
article id=_1234
text.../text
/article
 
I need the Digester to call a method on an Article class, with the
following signiture:
 
public void setId(long id);
 
In other words I just need a Rule that will fire for an XML id
attribute, and remove an underscore from the front of a String before
converting it to a long, and calling the appropriate method.
 
I realise that this will require some kind of custom class to chop up
the String, but the pattern you apply to matching the rule
(article/id) appears to refer to a nested id element, rather than an
id attribute. 
 
I can't seem to find an example of this anywhere. All the custom rules
examples appear to refer to nested elements. Any suggestions? Have I
missed something in the API?
 
Cheers
 
Jon
 
 


Re: [Digester] Problem using recursion in xml rule file

2007-03-14 Thread Vikram
Hi Arshika,
even i am having the same problem with a project i am working on...
it is working on removing the tag and doesn't work with the tag...
if u have got the solution...please mail me the same...
thanks
:)
Vikram...



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



[Digester] Problem using recursion in xml rule file

2007-02-28 Thread Arshika Mishra
Hi!

I am trying to parse an XML file using digester but getting a problem. The 
file has a recursive tag. The format of the file given below:

dpr-domain name=AircraftPerformances
dpr-data-category name=AircraftClass 
systemOption=FULLOLDI
dpr-attribute name=landingSpeed 
systemOption=HALFOLDI/
dpr-data-category name=holdingParameters 
systemOption=HALFOLDI
dpr-attribute name=maximumspeed1 
systemOption=FULLOLDI/
/dpr-data-category
dpr-data-category name=turnRate 
systemOption=FULLOLDI,HALFOLDI
dpr-attribute name=maximumspeed2 
systemOption=FULLOLDI/
dpr-data-category name=accelerateRate 
systemOption=HALFOLDI
dpr-attribute 
name=maximumspeed21 systemOption=FULLOLDI/
dpr-data-category 
name=descendRate systemOption=HALFOLDI
dpr-attribute 
name=maximumspeed211 systemOption=FULLOLDI/
/dpr-data-category
/dpr-data-category
/dpr-data-category
/dpr-data-category
/dpr-domain

The rule file I have written for this is:
digester-rules
pattern value=dpr-domain
object-create-rule classname=check.Domain/
pattern value=*/dpr-data-category
object-create-rule 
classname=check.DataCategory/
set-properties-rule/
pattern value=dpr-attribute
object-create-rule 
classname=check.Attribute/
set-properties-rule/
set-next-rule methodname=addAttributes 
/
/pattern
set-next-rule methodname=addDataCategory 
paramtype=check.DataCategory/ 
/pattern
/pattern 
/digester-rules

But this is not working. If the dpr-domain tag is removed, then it 
works. Please help me by giving a solution for this problem. 



Regards,
Arshika Mishra



__

[digester] problem

2006-04-11 Thread Qaiser Mehmood
Hi,

 

I am using Commons Digester to parse one XML file to a Java Object and
the code is not populating my Java Bean. The XML Files are 

 

Rules.xml :

 

?xml version=1.0?

 

digester-rules

  

 pattern value=messages/message

object-create-rule
classname=com.rhg.infrastructure.dao.bean.Message /

set-next-rule methodname=add
paramtype=java.lang.Object/

set-properties-rule /

bean-property-setter-rule pattern=application_name/

bean-property-setter-rule pattern=createDate/

bean-property-setter-rule pattern=createdBy/

bean-property-setter-rule pattern=id/

bean-property-setter-rule pattern=index_page/

bean-property-setter-rule pattern=message_text/

bean-property-setter-rule pattern=priority/

bean-property-setter-rule pattern=signature/

bean-property-setter-rule pattern=user_id/



  /pattern

/digester-rules

 

Test.xml :

 

?xml version=1.0 ?  

 messages

  message

application_nameFind Doc/application_name

createDate2006-04-11 09:48:22.406/createDate

createdBy1/createdBy

id0/id

index_pageindex.jsp/index_page

message_textError on Index.jsp/message_text

priority5/priority

signatureRevolution Team/signature

user_id1/user_id

  /message

 /messages

 

And the code :

 

List messagesList = new ArrayList( );

URL rules = getClass( ).getResource(/rules.xml);

Digester digester = DigesterLoader.createDigester(rules);

digester.push(messagesList);

InputStream input = getClass( ).getResourceAsStream(/test.xml);

Object root = digester.parse(input);

message = (Message) messagesList.get(0);

 

 System.out.println(message application name +message);

 

There are elements in messageList , bu the fileds in message are null.
So Field from the 2nd XML file are not populated. Any help. I will
appreciate prompt response.

 

Qaiser Mehmood

 

 



[digester] problem with factory creation rule

2006-03-29 Thread amine achergui
Hi everyone,
I'm using an xml file for rules.

   pattern value=configuration/action/destination
 factory-create-rule
 classname=pakcagename.DestinationCreationFactory
  bean-property-setter-rule pattern=value/
  set-next-rule methodname=setDestination/
/pattern


I have defined an implementation for AbstractObjectCreationFactory that's
DestinationCreationFactory. On Runtime i'm having this exception:


0 [main] ERROR digester.Digester - End event threw exception

java.lang.NoSuchMethodException: No such accessible method: add() on object:
org.apache.commons.digester.FactoryCreateRule

at org.apache.commons.beanutils.MethodUtils.invokeMethod(MethodUtils.java
:250)

at org.apache.commons.digester.SetNextRule.end(SetNextRule.java:256)

at org.apache.commons.digester.Rule.end(Rule.java:276)

at org.apache.commons.digester.Digester.endElement(Digester.java:1058)

at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)

at org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unknown
Source)

at 
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown
Source)

at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown
Source)

at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
Source)

at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)

at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)

at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)

at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)

at org.apache.commons.digester.Digester.parse(Digester.java:1567)

at org.apache.commons.digester.xmlrules.FromXmlRuleSet.addRuleInstances(
FromXmlRuleSet.java:149)

at org.apache.commons.digester.Digester.addRuleSet(Digester.java:1663)

at org.apache.commons.digester.xmlrules.DigesterLoader.createDigester(
DigesterLoader.java:91)

.

org.apache.commons.digester.xmlrules.XmlLoadException: Error at (20, 51: No
such accessible method: add() on object:
org.apache.commons.digester.FactoryCreateRule

at org.apache.commons.digester.xmlrules.FromXmlRuleSet.addRuleInstances(
FromXmlRuleSet.java:151)

at org.apache.commons.digester.Digester.addRuleSet(Digester.java:1663)

at org.apache.commons.digester.xmlrules.DigesterLoader.createDigester(
DigesterLoader.java:91)
Has anyone had this problem before?
Cheers,
Amine.


Re: Digester: Problem with CallMethodRule

2005-09-05 Thread Mikko Nylén

Simon Kitching wrote:


On Mon, 2005-09-05 at 07:18 +0300, Mikko Nylén wrote:
 


Hi!,

I'm having a little problem with Digester's CallMethodRule: it doesn't 
call the method.


The XML file I try to parse is:

---
configuration
 pages
   page path=/index.htm class=test.TestPage /
   page path=/hello.htm class=test.HelloPage /
 /pages
/configuration
---

The Java code I'm trying to use for parsing the configuration:

---
...
Digester digester = new Digester();
digester.addObjectCreate(configuration, test.Configuration);
digester.addObjectCreate(configuration/pages/page, 
test.PageConfiguration);
digester.addSetProperties(configuration/pages/page, new 
String[]{path, class}, new String[]{path, className});

digester.addCallMethod(configuration/pages/page, freeze);
digester.addSetNext(configuration/pages/page, addPageConfiguration, 
test.PageConfiguration);


Configuration configuration = (Configuration)digester.parse(reader);
---

The problem is that the freeze() method of instantiated 
PageConfiguration objects isn't ever called (which results to that the 
Configuration's addPageConfiguration(PageConfiguration) throws an 
IllegalStateException). How I should fix this? I'm using the version 1.7 
of Digester.
   



Are you sure the problem isn't the *order* that methods get called for
element configuration/pages/page rather than that the freeze method
doesn't get called at all? 


I suggest reading the FAQ entry titled How do I get CallMethodRule to
fire before SetNextRule? here:
 http://wiki.apache.org/jakarta-commons/Digester/FAQ

Regards,

Simon



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


 


Thanks! That FAQ entry solved the problem.

- Mikko Nylén

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



Digester: Problem with CallMethodRule

2005-09-04 Thread Mikko Nylén

Hi!,

I'm having a little problem with Digester's CallMethodRule: it doesn't 
call the method.


The XML file I try to parse is:

---
configuration
 pages
   page path=/index.htm class=test.TestPage /
   page path=/hello.htm class=test.HelloPage /
 /pages
/configuration
---

The Java code I'm trying to use for parsing the configuration:

---
...
Digester digester = new Digester();
digester.addObjectCreate(configuration, test.Configuration);
digester.addObjectCreate(configuration/pages/page, 
test.PageConfiguration);
digester.addSetProperties(configuration/pages/page, new 
String[]{path, class}, new String[]{path, className});

digester.addCallMethod(configuration/pages/page, freeze);
digester.addSetNext(configuration/pages/page, addPageConfiguration, 
test.PageConfiguration);


Configuration configuration = (Configuration)digester.parse(reader);
---

The problem is that the freeze() method of instantiated 
PageConfiguration objects isn't ever called (which results to that the 
Configuration's addPageConfiguration(PageConfiguration) throws an 
IllegalStateException). How I should fix this? I'm using the version 1.7 
of Digester.


- Mikko Nylén

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



Re: [Digester] Problem with XML rule definiton.

2005-03-31 Thread Silas Snider
I was using Eclipse as the development enviroment, so that could be 
doing it, but I have done reflection with it before, and it worked both 
in the jar file and the environment.

Sincerely,
Silas Snider
Reid Pinchback wrote:
It sounds like one of two things:
1) in the jar'd configuration something is missing from the classpath
2) in the jar'd configuration you aren't using the same type of
  classloaders as you are in the non-jar'd configuration
  (e.g. not just jar vs non-jar, but jar-in-webapp vs
  unjarred-standalone-app).
--- Silas Snider [EMAIL PROTECTED] wrote:
 

Dear List:
   I am having problems with Digester. I am using it to parse the XML
returned by Amazon's Web Services.
   


		
__ 
Do you Yahoo!? 
Yahoo! Small Business - Try our new resources site!
http://smallbusiness.yahoo.com/resources/ 

-
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]


[Digester] Problem with XML rule definiton.

2005-03-30 Thread Silas Snider
Dear List:
I am having problems with Digester. I am using it to parse the XML
returned by Amazon's Web Services. My problem occurs when I create a .jar
out of my java program. I am passing the XML rules to DigesterLoader as a
stream from the getClass().getResourceAsStream(resource file name) method,
and digester likes the rules file. When it actually tries to parse the XML,
it chokes on a object creation rule saying that it can't find the class
named in the rule. However, when I am running it outside of .jar, it works
fine, and the class is included in the .jar (I checked with 7-zip). I have
solved the problem by defining rule programmatically, but, for obvious
reasons, would like to have them defined in a seperate file. Does anyone
have suggestions as to what I might be doing wrong?
 
Sincerely,
Silas Snider


Re: [Digester] Problem with XML rule definiton.

2005-03-30 Thread Reid Pinchback

It sounds like one of two things:
1) in the jar'd configuration something is missing from the classpath
2) in the jar'd configuration you aren't using the same type of
   classloaders as you are in the non-jar'd configuration
   (e.g. not just jar vs non-jar, but jar-in-webapp vs
   unjarred-standalone-app).

--- Silas Snider [EMAIL PROTECTED] wrote:
 Dear List:
 I am having problems with Digester. I am using it to parse the XML
 returned by Amazon's Web Services.




__ 
Do you Yahoo!? 
Yahoo! Small Business - Try our new resources site!
http://smallbusiness.yahoo.com/resources/ 

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


non-String Bean Digester problem

2005-01-19 Thread William Fuller
Hello, I'm new to Digester, Tomcat, Servlet, Velocity, and even Java...
Yup, one of those.

I am running into a spot of bother while using Digester to parse my XML file
that I will ultimately pluck from Derby.  The file starts out like this:


Screen
 ScreenID3220D03D-59F7-49ca-86AE-E97B7427BA7B/ScreenID
Lifetime_ms2/Lifetime_ms
 BugItem
ImageURLcnn001.jpg/ImageURL
...

It is a rather large file with many Vectors and I parse it just fine so long
as all the setMethods are of type String.  I am using XML Rules and my file
looks like this:

?xml version=1.0?

digester-rules
pattern value=Screen
object-create-rule classname=com.synergy.screendoc.ScreenDocument
/
call-method-rule pattern=ScreenID methodname=setScreenID
paramcount=0 /
call-method-rule pattern=Lifetime_ms methodname=setLifetime_ms
paramcount=0 /
...

My Java bean for the first level looks like this:

public class ScreenDocument
{
public  String  ScreenID;
public  String  Lifetime_ms;
public  Vector  BugItem;
public  Vector  StaticTextItem;
public  Vector  DynamicTextItem;

public ScreenDocument()
{
BugItem = new Vector();
StaticTextItem  = new Vector();
DynamicTextItem = new Vector();
}

public String getScreenID() { return ScreenID; }
public void setScreenID( String rhs ) { this.ScreenID = rhs; }
public String getLifetime_ms() { return Lifetime_ms; }
public void setLifetime_ms( String rhs ) { this.Lifetime_ms = rhs; }
...

The problem that I am encountering is that if I try to use
bean-property-setter-rule like this:

?xml version=1.0?

digester-rules
pattern value=Screen
object-create-rule classname=com.synergy.screendoc.ScreenDocument
/
set-properties-rule/
bean-property-setter-rule pattern=ScreenID/
bean-property-setter-rule pattern=Lifetime_ms/

I get the Digester exception that the bean has no property ScreenID.

Having a method that works I would normally just blow this off, but I don't
really want Lifetime_ms to be a String, I want it to be an int.  I would
be happy with it being a java.lang.Integer, but when I do something like
this:

?xml version=1.0?

digester-rules
pattern value=Screen
object-create-rule classname=com.synergy.screendoc.ScreenDocument
/
call-method-rule pattern=ScreenID methodname=setScreenID
paramcount=0 /
pattern value=Lifetime_ms
call-method-rule methodname=setLifetime_ms paramcount=1/
object-param-rule paramnumber='0' type=java.lang.Integer /
/pattern
...

And change the bean to have Lifetime_ms defined, set, and returned as type
Integer, Digester throws and exception and complains that setLifetime_ms is
not defined in my class.

I am at a loss for understanding why I am having this problem and suspect I
am doing something really dumb.

Can anyone please set me staight?

Thank you in advance.

Will


Re: non-String Bean Digester problem

2005-01-19 Thread Simon Kitching
Hi William,

On Wed, 2005-01-19 at 02:49 -0600, William Fuller wrote:
 Hello, I'm new to Digester, Tomcat, Servlet, Velocity, and even Java...
 Yup, one of those.

No worries, we've all been there..

 
 I am running into a spot of bother while using Digester to parse my XML file
 that I will ultimately pluck from Derby.  The file starts out like this:
 
 
 Screen
  ScreenID3220D03D-59F7-49ca-86AE-E97B7427BA7B/ScreenID
 Lifetime_ms2/Lifetime_ms
  BugItem
 ImageURLcnn001.jpg/ImageURL
 ...
 
 It is a rather large file with many Vectors and I parse it just fine so long
 as all the setMethods are of type String.  I am using XML Rules and my file
 looks like this:
 
 ?xml version=1.0?
 
 digester-rules
 pattern value=Screen
 object-create-rule classname=com.synergy.screendoc.ScreenDocument
 /
 call-method-rule pattern=ScreenID methodname=setScreenID
 paramcount=0 /
 call-method-rule pattern=Lifetime_ms methodname=setLifetime_ms
 paramcount=0 /
 ...
 
 My Java bean for the first level looks like this:
 
 public class ScreenDocument
 {
 public  String  ScreenID;
 public  String  Lifetime_ms;
 public  Vector  BugItem;
 public  Vector  StaticTextItem;
 public  Vector  DynamicTextItem;
 
 public ScreenDocument()
 {
 BugItem = new Vector();
 StaticTextItem  = new Vector();
 DynamicTextItem = new Vector();
 }
 
 public String getScreenID() { return ScreenID; }
 public void setScreenID( String rhs ) { this.ScreenID = rhs; }
 public String getLifetime_ms() { return Lifetime_ms; }
 public void setLifetime_ms( String rhs ) { this.Lifetime_ms = rhs; }
 ...

If I understand your problem, your issue is that this works when
property Lifetime_ms is a String, but you want it to be an int or
Integer?

Well, this should just work. Digester uses BeanUtils to access
properties of a Java object, and this automatically does type
conversions. From inspection of the target ScreenDocument class,
BeanUtils should see that there is a setScreenID(int rhs) method, and so
automatically convert String-int before invoking that method. If the
getter/setter deal in Integer rather than int, then that should work
too.

A few suggestions:
(a) Did you change the prototype of the getScreenID method to return the
same datatype as the setScreenID takes as a parameter? This is required
by the JavaBean standard...
(b) If you're still having problems then you can try enabling debugging
in Digester. See http://wiki.apache.org/jakarta-commons/Digester/FAQ
section 1.4.

 
 The problem that I am encountering is that if I try to use
 bean-property-setter-rule like this:
 
 ?xml version=1.0?
 
 digester-rules
 pattern value=Screen
 object-create-rule classname=com.synergy.screendoc.ScreenDocument
 /
 set-properties-rule/
 bean-property-setter-rule pattern=ScreenID/
 bean-property-setter-rule pattern=Lifetime_ms/
 
 I get the Digester exception that the bean has no property ScreenID.
 
 Having a method that works I would normally just blow this off, but I don't
 really want Lifetime_ms to be a String, I want it to be an int.  I would
 be happy with it being a java.lang.Integer, but when I do something like
 this:
 
 ?xml version=1.0?
 
 digester-rules
 pattern value=Screen
 object-create-rule classname=com.synergy.screendoc.ScreenDocument
 /
 call-method-rule pattern=ScreenID methodname=setScreenID
 paramcount=0 /
 pattern value=Lifetime_ms
 call-method-rule methodname=setLifetime_ms paramcount=1/
 object-param-rule paramnumber='0' type=java.lang.Integer /
 /pattern
 ...
 
 And change the bean to have Lifetime_ms defined, set, and returned as type
 Integer, Digester throws and exception and complains that setLifetime_ms is
 not defined in my class.
 
 I am at a loss for understanding why I am having this problem and suspect I
 am doing something really dumb.
 
 Can anyone please set me staight?

I'm puzzled as well. It should all work. The only thing that I can think
of is that you failed to change the getter method [as described in (a)
above].

If this isn't the case, then please enable debugging and have a look at
the output. If this still doesn't help, then post the debug output to
this list and maybe I (or someone else) can help further.

Regards,

Simon



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



Digester: Problem of loading parents attribute to the child

2004-10-07 Thread Nalika Dissanayaka
Hi,

I am having a difficulty to load the following XML file by using the
commons Digester. Is there anyone that can help me on this...

XML FILE

?xml version=1.0 encoding=UTF-8?
metadata lang=en-US environment=Production revision=001
   Sender
   Namemy nameDC/Name
   Addressmy address /Address
   /Sender
   DataArea
   Data Set
   Data
   attr1/attr1
   attr2/attr2

   attrn/attrn

   /Data
   Data
   attr1/attr1
   attr2/attr2

   attrn/attrn
   /Data
   /Data Set
   /DataArea
/metadata

I am only interested getting the list of Data objects. The issue is,
Data class has a attribute  called lang which should be loaded from
the value of the lang in the metadata node. (I am planning to load
series of files where metadata lang can be changed based on the
locale)

What are the possible approaches that I can use ?. Is this something
that can be done by using the commons Digester. (I have no problrm of
loading the list of Data)

Thanks in advance
Nalika

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



Re: Digester: Problem of loading parents attribute to the child

2004-10-07 Thread Simon Kitching
On Fri, 2004-10-08 at 07:11, Nalika Dissanayaka wrote:
 Hi,
 
 I am having a difficulty to load the following XML file by using the
 commons Digester. Is there anyone that can help me on this...
 
 XML FILE
 
 ?xml version=1.0 encoding=UTF-8?
 metadata lang=en-US environment=Production revision=001
Sender
Namemy nameDC/Name
Addressmy address /Address
/Sender
DataArea
Data Set
Data
attr1/attr1
attr2/attr2
 
attrn/attrn
 
/Data
Data
attr1/attr1
attr2/attr2
 
attrn/attrn
/Data
/Data Set
/DataArea
 /metadata
 
 I am only interested getting the list of Data objects. The issue is,
 Data class has a attribute  called lang which should be loaded from
 the value of the lang in the metadata node. (I am planning to load
 series of files where metadata lang can be changed based on the
 locale)
 
 What are the possible approaches that I can use ?. Is this something
 that can be done by using the commons Digester. (I have no problrm of
 loading the list of Data)

It certainly can be done using the Digester, though you might have to
create a custom Rule class or two.

I would suggest having a look at the ObjectParamRule class which can be
used to pass an arbitrary object to a method on the top object on the
digester object stack.

Regards,

Simon


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



Re: Digester Problem related to Bean Classname

2003-02-06 Thread Craig R. McClanahan


On Thu, 6 Feb 2003, Maher Martin wrote:

 Date: Thu, 6 Feb 2003 16:20:58 +0100
 From: Maher Martin [EMAIL PROTECTED]
 Reply-To: Jakarta Commons Users List [EMAIL PROTECTED]
 To: '[EMAIL PROTECTED]' [EMAIL PROTECTED]
 Subject: Digester Problem related to Bean Classname

 Hi,

 I've encountered a strange problem with Digester which is related to the
 name of the java bean class. If I name the Java class x.y.Component then
 the set-properties-rule / fails to call the setter methods for the bean
 class. However if I rename the class to x.y.Component2 all setters are
 invoked by Digester when parsing the XML.

 Can anybody explain what's going on here? I've included examples below.


This is going to take a few paragraphs, but here goes ...

Digester (and beanutils, for that matter) use Java's introspection
capabilities (java.beans.Introspector) to find the available methods and
properties of bean classes.  Normally, properties are identified by the
naming pattern used on the methods (getFoo() and setFoo()), but you can
also override this if you provide a BeanInfo class associated with your
bean class (see the Introspector Javadocs and the JavaBeans Specification
for more info).

Now, there are two ways to associate a BeanInfo class with your bean:

* Put it in the same package as your bean class, with the same
  classname + BeanInfo on the end (for a bean MyBean, the corresponding
  class would be MyBeanBeanInfo).

* Tell the introspector to use a particular search path (set of
  package names) to search in for BeanInfo classes.

Unfortunately, the default search path in the JDK includes a directory
that contains a class named ComponentBeanInfo -- which tells the
introspector that any class named Component will use this BeanInfo class
to identify its properties, rather than looking at the methods of your
class.  Thus, *your* properties are not recognized.

There's two workarounds:

* Name your class anything other than Component.  (This seems
  to be the only BeanInfo class available in the default JDK list)

* Call Introspector.setBeanInfoSearchPath() to set a different
  set of search directories, before using Digester.

 Best Regards

 Martin Maher


Craig McClanahan


 -- Component Class 

 package x.y

 public class Component {

   private int _number;
   private String _type;

   public Component() {
   }

   public void setNumber(int number) {
 _number = number;
   }

   public void setType(String type) {
 _type = type;
   }

   public int getNumber() {
 return _number;
   }

   public String getType() {
 return _type;
   }

   public String toString() {
 String newline = System.getProperty(line.separator);
 StringBuffer sBuf = new StringBuffer();

 sBuf.append(Number:).append(_number).append(newline);
 sBuf.append(Type:).append(_type).append(newline);

 return sBuf.toString();
   }

 }

 --INPUT XML FILE

 ?xml version=1.0?

 component number=1 type=a
 /component

 -- XML RULES 

 ?xml version=1.0?

 digester-rules

   pattern value=component
   object-create-rule classname=x.y.Component /
   set-properties-rule /
   /pattern

 /digester-rules
 --

 -
 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]