Re: Digester problem
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:
...
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
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:
...
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
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]
Re: [Digester] Problem using recursion in xml rule file
Hi!! Thanks for the solution. But actually, problem is more complex. The complete format of the XML file is as follows: abc I don't know how to write the xml rule file for parsing the above xml. Even I am not able to implement the solution provided. Thanks, Arshika On 2/28/07, Arshika Mishra <[EMAIL PROTECTED]> wrote: > 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: > > > systemOption="FULLOLDI"> > systemOption="HALFOLDI"/> > systemOption="HALFOLDI"> > systemOption="FULLOLDI"/> > > systemOption="FULLOLDI,HALFOLDI"> > systemOption="FULLOLDI"/> > systemOption="HALFOLDI"> > name="maximumspeed21" systemOption="FULLOLDI"/> > name="descendRate" systemOption="HALFOLDI"> > name="maximumspeed211" systemOption="FULLOLDI"/> > > > > > > > The rule file I have written for this is: > > > > > classname="check.DataCategory"/> > > > classname="check.Attribute"/> > > /> > > paramtype="check.DataCategory"/> > > > > > 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. > Arshika, I never use the XML format for defining rules, so I'm a little fuzzy on how it really works. However, it seems to me that you would *not* want to nest your category pattern inside the domain pattern when you use the "*" prefix for recursion. The problem is that the composite pattern will be trying to match "dpr-domain/*/dpr-data-category" and I do not think Digester knows how to deal with wildcards in the middle like that. Try something along these lines instead: ... rules for a new domain ... ... rules for a new category ... ... rules for a new attribute ... Craig > > > Regards, > Arshika Mishra > > > > __ __
Re: [Digester] Problem using recursion in xml rule file
On 2/28/07, Arshika Mishra <[EMAIL PROTECTED]> wrote: 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: The rule file I have written for this is: 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. Arshika, I never use the XML format for defining rules, so I'm a little fuzzy on how it really works. However, it seems to me that you would *not* want to nest your category pattern inside the domain pattern when you use the "*" prefix for recursion. The problem is that the composite pattern will be trying to match "dpr-domain/*/dpr-data-category" and I do not think Digester knows how to deal with wildcards in the middle like that. Try something along these lines instead: ... rules for a new domain ... ... rules for a new category ... ... rules for a new attribute ... Craig Regards, Arshika Mishra __ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
[Digester] Problem using recursion in xml rule file
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: The rule file I have written for this is: 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
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 :
Test.xml :
Find Doc
2006-04-11 09:48:22.406
1
0
index.jsp
Error on Index.jsp
5
Revolution Team
1
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
Hi everyone, I'm using an xml file for rules. 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
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:
---
---
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
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:
---
---
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.
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]
Re: [Digester] Problem with XML rule definiton.
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]
[Digester] Problem with XML rule definiton.
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: non-String Bean Digester problem
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:
>
>
>
> 3220D03D-59F7-49ca-86AE-E97B7427BA7B
> 2
>
> cnn001.jpg
> ...
>
> 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:
>
>
>
>
>
> />
> paramcount="0" />
> 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:
>
>
>
>
>
> />
>
>
>
>
> 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:
>
>
>
>
>
> />
> paramcount="0" />
>
>
>
>
> ...
>
> 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]
non-String Bean Digester problem
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:
3220D03D-59F7-49ca-86AE-E97B7427BA7B
2
cnn001.jpg
...
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:
...
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:
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:
...
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: Digester: Problem of loading parents attribute to the child
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 > > > > >my nameDC >my address > > > > > > > > > > > > > > > > > > > > > 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]
Digester: Problem of loading parents attribute to the child
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 my nameDC my address 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 related to Bean Classname
Thanks Craig, I think I'll go with the renaming the class idea. Martin - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Digester Problem related to Bean Classname
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 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 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]
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 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.
Best Regards
Martin Maher
-- 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 RULES
--
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
