Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

How to create a MAP[Key: XML Element name, Value: Java Object Property Name] for JAXB processed XML?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Am currently working on the following requirement.

1. I have a user interface wherein every XML element (in SOAP request/response) would be mapped to a less technical term or a label. (E.g. specType would be referred as "Technology").

2. For the various webservice or for that matter the XML request/response fields, i need to set certain rules (E.g. if specType is the element, then something like Technology is not equal to 'XYZ').

3. There is a UI for creation of rules on the different XML elements(For eg. Country is 'ABC' && Technology is not equal to 'XYZ').

4, JAXB has been used for XML to JAVA transformations.

Is there a way i can generate a map having the XML element name as key, and corresponding Java object property as the value, at runtime in my program?

This may be very very simple, so please bear my ignorance.

Thanks,
Ketan
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That sounds like a java.util.Properties object - there is a nice Properties load( Reader ) method that could be used to read a file. Assuming you can create a text file with the mapping you want, thats all you need.

Bill
 
Ketan Damle
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bill for your reply, but perhaps I have not been able to put across my question properly.

Assume I have a JAXB transformed JAVA class, and has properties as below. (This has been an automatic transformation, no customized bindings provided here.)



Now what I want is a Map with key as the XML element name and value as Java Property name, something like{["local_creationDate","localCreationDate"],["local_accessType", "localAcessType"]}

There is a UI for mapping the XML element name to a less technical label, e.g. [local_creationDate ---> Local Creation Date]. The rule would appear to be set on "Local Creation Date" (E.g. Local Creation Date not before '20-08-2013') but would actually be applied on the java property name "localCreationDate"

Additionally i do not want this to be a static mapping, instead it should be dynamic or at runtime, i was wondering if i could loop through either the XSD or the java classes using reflection and generate this sort of a Map. One way was to read the annotations using reflection, but is there a a more standard, straightforward way to achieve this?


Thanks,
Ketan
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic