users@jaxb.java.net

Re: Accessing JAXB mappings

From: <dev_at_samizdatdigital.org>
Date: Fri, 27 Aug 2004 07:34:29 -0700

no problem. actually, i should have said a bit more -- jxpath should be
good for *getting* (if, as you note, your classes have some reasonably
predictable naming pattern), but it won't do deep setting -- since you
have to use the object factory to create the objects on the way to your
leaf, which i don't believe jxpath can do off the shelf. that being
said, i have a friend who has played around with combining the two. i
should also have mentioned that we've used reflection to get the
getter/setter methods, as you suggest. one caveat, if you do this, is
to remeber that you'll need to obtain Class objects for things of type
yourpackage.impl.Address_BookImpl with Class.forName, since (if i
remember correctly) Class.forName( "AddressBook" ) will give you an
interface, from which you won't be able to retrieve any Method objects.

jon

On Aug 27, 2004, at 7:30 AM, Moravec Jan wrote:

> Did not know about JXPATH. It looks pretty good, however, I think I
> still need to extract the mapping info from JAXB context somehow. Why?
> Because JXPATH has no clue about what method mapping JAXB is using.
> Eg.
>
> For XPath:
>
> /address_book/entry[1]/general/first_name
>
> JXPATH will attempt to perform:
>
> getAddress_book().getEntry().get(0).getGeneral().setFirst_name(...)
>
> But I would need:
>
> getAddressBook().getEntry().get( 0 ).getGeneral().setFirstName( 'Jan' )
>
> because that's the mapping JAXB generates. To make things more
> difficult, JAXB allows one to customize the mapping using a property
> file. So in the end to access the contents of the address_book element
> you may end up using a method named getFoo() etc.
>
> Thanks for the JXPATH pointer it will definitely save me from writing
> the reflection stuff.
>
> Cheers,
> Jan Moravec
>
>
>>
>> I need to be able to perform something like:
>>
>> getAddressBook().getEntry().get( 0 ).getGeneral().setFirstName( 'Jan'
>> )
>
>
>
> Thanks for the pointer anyway, it will definitelly save me from
> writing the reflection stuff.
>
>
>
> -----Original Message-----
> From: dev_at_samizdatdigital.org [mailto:dev_at_samizdatdigital.org]
> Sent: Friday, August 27, 2004 4:07 PM
> To: users_at_jaxb.dev.java.net
> Subject: Re: Accessing JAXB mappings
>
>
> have you considered jxpath?
>
> jon
>
> On Aug 26, 2004, at 11:42 PM, Moravec Jan wrote:
>
>> Hello,
>>
>> Is it possible to access JAXB element name to method name mapping at
>> runtime? What I would like to achieve is to set/get a particular value
>> in the content tree using Java reflection and XPath.
>>
>> For example,
>>
>> To set a value of a content tree element identified with an XPath that
>> looks like
>>
>> /address_book/entry[1]/general/first_name
>>
>> I need to be able to perform something like:
>>
>> getAddressBook().getEntry().get( 0 ).getGeneral().setFirstName( 'Jan'
>> )
>>
>> For this to happen I need to find out what method/type each of the
>> XPath elements maps onto. I would expect it would be accessible
>> through the JAXBContext, but it does not seem to be the case.
>>
>> In the worst case I could derive the method names by stripping '_'
>> from XPath element names and converting first letters to capitals, but
>> that would be a hack as the setter/getter method names can be
>> customized using a property file anyway (never tried, but glimsed an
>> example somewhere).
>>
>> Thanks a lot,
>> Jan Moravec
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
>> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net