On Tue, Jul 3, 2012 at 8:58 PM, Lucas Reginato <[email protected]> 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 <[email protected]> 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 <[email protected]> >> 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 <[email protected]> >> > 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 >> >> <[email protected]> >> >> 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: [email protected] >> >> For additional commands, e-mail: [email protected] >> >> >> >> -- >> >> Lucas Rosa Cruz Reginato >> >> >> > >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [email protected] >> For additional commands, e-mail: [email protected] >> >> -- >> Lucas Rosa Cruz Reginato >> > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
