Re: Best way to generate XSD from Java
On 09/28/2012 10:54 PM, the don wrote:
Let me clarify a little bit, I'm not trying to do what JAXB does. I'm not
trying to marshall and unmarshall XML info to and from Java. In fact, The
XSD files produced *will* be compiled with xjc for that purpose but they
will *not* translate between XML and the annotated Java Classes which were
used to produce them.
A few lines down you say "generate an XSD which can be used by JAXB for
marshalling and unmarshalling".
I intend to automate the Methods in the annotated Java Classes, ie store
sequences of Method calls in XML files, read them into memory and then
invoke them in instantiated Object(s) of that type. I would like to start
with the Classes themselves, tag or annotate the Methods I want to make
available for automation, then generate an XSD which can be used by JAXB
for marshalling and unmarshalling, as well as for creating and editing
these "Command Strings" with validation. Eclipse, for instance, provides
something like the latter capability
There is probably some way to tag (or annotate!) a Java file so that a
Templating engine could generate the desired output, and I doubt that it is
very difficult. I was just asking to see what experience people here have
had with this sort of thing and give me some direction.
You can have javac use an annotation processor, if you want to do your
work on compilation time. In your case you would likely need to to some
processing after compiling all classes in order to be able to combine
information obtained from individual classes into a single XSD (if only
for including all other XSD snippets).
From what I understand about your goal you should probably generally
distinguish two things here:
1. creating objects
2. invoking methods
JAXB might help you with 1 but certainly not with 2. Also, you need a
way to define variables to store references to created objects in so you
can use them in method calls. So, basically your XML needs to be able
to store... what? Basically you want an interpreter to execute Java
code, don't you? Thinking a few corners further you'll notice that
there is actually already a way to specify sequences of method
invocations: Java code. You might be better off with some BeanShell
solution in the end. You get editors with semantic insight for free
(it's your IDE) etc.
Kind regards
robert
http://www.beanshell.org/