On Thu, Jul 5, 2012 at 2:25 PM, Lucas Reginato <lucas.regin...@yoppa.com> wrote: > I tried your suggestion without success. :( > > Using the xPath myschema.MyEntity.new() returns a new object. Cool. > > But using the xPath myschema.MyEntity.getName() I got the following > exception: > > org.apache.commons.jxpath.JXPathInvalidAccessException: Cannot invoke public > java.lang.String myschema.MyEntity.getName(); java.lang.NullPointerException > at > org.apache.commons.jxpath.functions.MethodFunction.invoke(MethodFunction.java:99) > at > org.apache.commons.jxpath.ri.compiler.ExtensionFunction.computeValue(ExtensionFunction.java:102) > at > org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.getValue(JXPathContextReferenceImpl.java:353) > at > org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.getValue(JXPathContextReferenceImpl.java:313) > at Main.main(Main.java:20) > Caused by: java.lang.NullPointerException > at > org.apache.commons.jxpath.functions.MethodFunction.invoke(MethodFunction.java:79) > ... 4 more > > The same happen for myschema.MyEntity.isIsUsaResident() > > Am I missing something?
What *I* am missing is an example of what you've tried here ;P Matt > > -Lucas > > > On Thu, Jul 5, 2012 at 12:14 PM, Matt Benson <gudnabr...@gmail.com> wrote: >> >> On Tue, Jul 3, 2012 at 8:58 PM, Lucas Reginato <lucas.regin...@gmail.com> >> wrote: >> > I will try to make this change (from is method to get method) tomorrow >> > and >> > will send the results. >> > >> > But imagine the scenario: you have a product (which was already shipped >> > to >> > customers) that has an API. >> > And your product also presents the possibility to query values from XML >> > using Xpath. >> > What do you suggest for this specific product that was already shipped >> > and >> > now customer are using xpath to retrieve boolean values without success? >> > >> > Yes, we can use XSLT to get the boolean value, but I think apache should >> > fix >> > this. >> > I mean, apache commons xpath should be able to work with get/set/is >> > methods >> > and not only get/set. >> >> The thing is, [jxpath] works with Java bean style accessors, but >> "Boolean isFoo()" is by definition not one such and is therefore by >> default "just another method." I think you're saying that what you >> want is a way to interact with the Java API you already have; in this >> case I think your best best would be an extension function [1]. The >> example of calling "regular methods" just might do the truck here. >> >> Matt >> >> [1] >> http://commons.apache.org/jxpath/users-guide.html#Standard_Extension_Functions >> >> > >> > Do you think it's possible to file a new issue for this? >> > >> > -Lucas >> > >> > >> > On Tue, Jul 3, 2012 at 10:33 PM, Matt Benson <gudnabr...@gmail.com> >> > wrote: >> >> >> >> Good call; yes, being an Object Boolean, the "is" idiom does not work. >> >> >> >> Matt >> >> >> >> On Tue, Jul 3, 2012 at 8:11 PM, Lucas Reginato >> >> <lucas.regin...@gmail.com> >> >> wrote: >> >> > Yes, >> >> > >> >> > The example is incorrect, it should be lower case, my mistake. >> >> > If you try to execute my example you will see this issue. >> >> > >> >> > Did you see the java code that was generated? >> >> > Maybe if the is methods where change to get method, will it work? >> >> > >> >> > -Lucas >> >> > >> >> > On Tue, Jul 3, 2012 at 6:55 PM, Matt Benson <gudnabr...@gmail.com> >> >> > wrote: >> >> >> >> >> >> Have you tried "/isUsaResident"? Javabean property names typically >> >> >> begin with lower case. >> >> >> >> >> >> HTH, >> >> >> Matt >> >> >> >> >> >> On Tue, Jul 3, 2012 at 4:41 PM, Lucas Reginato >> >> >> <lucas.regin...@gmail.com> >> >> >> wrote: >> >> >> > Hi, >> >> >> > >> >> >> > >> >> >> > >> >> >> > I’m facing a strange behavior using xPath to query boolean values. >> >> >> > >> >> >> > Every time I tried to query boolean values with xPath, I get an >> >> >> > exception >> >> >> > saying that no value was found. >> >> >> > >> >> >> > >> >> >> > The exception is: >> >> >> > >> >> >> > org.apache.commons.jxpath.JXPathNotFoundException: No value for >> >> >> > xpath: >> >> >> > <myXpath> >> >> >> > >> >> >> > >> >> >> > Let me present the complete example that I'm using: >> >> >> > >> >> >> > >> >> >> > This is my schema: >> >> >> > >> >> >> > <?xml version="1.0"?> >> >> >> > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi=" >> >> >> > http://www.w3.org/2001/XMLSchema-instance" xmlns="http://mySchema" >> >> >> > xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc=" >> >> >> > http://java.sun.com/xml/ns/jaxb/xjc" >> >> >> > targetNamespace="http://mySchema" >> >> >> > elementFormDefault="qualified" jaxb:extensionBindingPrefixes="xjc" >> >> >> > jaxb:version="2.0"> >> >> >> > <xs:annotation> >> >> >> > <xs:appinfo> >> >> >> > <jaxb:globalBindings> >> >> >> > <xjc:serializable/> >> >> >> > </jaxb:globalBindings> >> >> >> > </xs:appinfo> >> >> >> > </xs:annotation> >> >> >> > <!-- Base type definitions --> >> >> >> > <xs:complexType name="MyEntity"> >> >> >> > <xs:sequence> >> >> >> > <xs:element name="Id" type="xs:string" minOccurs="0" >> >> >> > maxOccurs="1"/> >> >> >> > <xs:element name="Name" type="xs:string" minOccurs="0" >> >> >> > maxOccurs="1"/> >> >> >> > <xs:element name="IsUsaResident" type="xs:boolean" >> >> >> > minOccurs="0" maxOccurs="1"/> >> >> >> > <xs:element name="AnotherBooleanValue" >> >> >> > type="xs:boolean" >> >> >> > minOccurs="0" maxOccurs="1"/> >> >> >> > </xs:sequence> >> >> >> > </xs:complexType> >> >> >> > <!-- Root Element --> >> >> >> > <xs:element name="MyEntity" type="MyEntity"/> >> >> >> > </xs:schema> >> >> >> > >> >> >> > >> >> >> > In order to generate my java classes based on the schema, I'm >> >> >> > using >> >> >> > the >> >> >> > xjc >> >> >> > ant tag. >> >> >> > >> >> >> > My generated class looks like this: >> >> >> > >> >> >> > >> >> >> > package myschema; >> >> >> > import java.io.Serializable; >> >> >> > import javax.xml.bind.annotation.XmlAccessType; >> >> >> > import javax.xml.bind.annotation.XmlAccessorType; >> >> >> > import javax.xml.bind.annotation.XmlElement; >> >> >> > import javax.xml.bind.annotation.XmlType; >> >> >> > @XmlAccessorType(XmlAccessType.FIELD) >> >> >> > @XmlType(name = "MyEntity", propOrder = { >> >> >> > "id", >> >> >> > "name", >> >> >> > "isUsaResident", >> >> >> > "anotherBooleanValue" >> >> >> > }) >> >> >> > public class MyEntity implements Serializable{ >> >> >> > @XmlElement(name = "Id") >> >> >> > protected String id; >> >> >> > @XmlElement(name = "Name") >> >> >> > protected String name; >> >> >> > @XmlElement(name = "IsUsaResident") >> >> >> > protected Boolean isUsaResident; >> >> >> > @XmlElement(name = "AnotherBooleanValue") >> >> >> > protected Boolean anotherBooleanValue; >> >> >> > public String getId() { return id; } >> >> >> > public void setId(String value) { this.id = value; } >> >> >> > public String getName() { return name; } >> >> >> > public void setName(String value) { this.name = value; } >> >> >> > public Boolean isIsUsaResident() { return isUsaResident; } >> >> >> > public void setIsUsaResident(Boolean value) { >> >> >> > this.isUsaResident >> >> >> > = >> >> >> > value; } >> >> >> > public Boolean isAnotherBooleanValue() { return >> >> >> > anotherBooleanValue; >> >> >> > } >> >> >> > public void setAnotherBooleanValue(Boolean value) { >> >> >> > this.anotherBooleanValue = value; } >> >> >> > } >> >> >> > >> >> >> > >> >> >> > And I'm using the following code to query boolean values: >> >> >> > MyEntity myEntity = new MyEntity(); >> >> >> > myEntity.setId("1"); >> >> >> > myEntity.setName("MyName"); >> >> >> > myEntity.setIsUsaResident(true); >> >> >> > myEntity.setAnotherBooleanValue(false); >> >> >> > Object result = ""; >> >> >> > JXPathContext context = JXPathContext.newContext(myEntity); >> >> >> > try { >> >> >> > result = context.getValue("/IsUsaResident"); >> >> >> > if (result == null) { >> >> >> > result = ""; >> >> >> > } >> >> >> > } catch (JXPathException exc) { >> >> >> > exc.printStackTrace(); >> >> >> > } >> >> >> > System.out.println(result.toString()); >> >> >> > >> >> >> > Can someone help me with this? >> >> >> > >> >> >> > Thanks, >> >> >> > -Lucas Reginato >> >> >> >> >> >> >> >> >> --------------------------------------------------------------------- >> >> >> To unsubscribe, e-mail: user-unsubscr...@commons.apache.org >> >> >> For additional commands, e-mail: user-h...@commons.apache.org >> >> >> >> >> >> -- >> >> >> Lucas Rosa Cruz Reginato >> >> >> >> >> > >> >> >> >> --------------------------------------------------------------------- >> >> To unsubscribe, e-mail: user-unsubscr...@commons.apache.org >> >> For additional commands, e-mail: user-h...@commons.apache.org >> >> >> >> -- >> >> Lucas Rosa Cruz Reginato >> >> >> > >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: user-unsubscr...@commons.apache.org >> For additional commands, e-mail: user-h...@commons.apache.org >> > > > > -- > Lucas Rosa Cruz Reginato --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org