users@jaxb.java.net

Re: Feasibility Question: XJC plugin to create AS3 code

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Wed, 18 Feb 2009 08:04:20 +0100

Hi.

> I'm just starting to evaluate XJC plugin functionality to see if I could use
> it for a very specific task. Specifically, at present there is no JAXB type
> functionalility for Adobe ActionScript (AS3) code. I have used XJC/JAXB to
> create/use Java proxies for a different project and I now need to do
> something very similar for ActionScript. If an XJC-plugin will allow me to
> dramatically alter the output (to the extent that it is for an entirely
> different target language) then it is a great start. Clearly XJC already
> has a representation of the XSD in memory so I really am just trying to
> change the code generation portion of the process.
>
> Thoughts? Is this easily done through plugins?
>
> Thanks.
> Alan
>
> P.S. Yes, I understand that the (un)marshaller need to be written entirely
> in Flex. I'm only trying to solve the first half of the equation right
> now... code generation.

Good that you acknowledge that. :)

Although I have no idea of ActionScript, I'll try to answer your question.
Generation process in XJC consists of four phases or steps:
* Load model from schema.
* Generate outline from model.
* Render outline into the code model.
* Serialize code model (for instance as files).

Model is an abstract representation of schema in terms of classes and
properties of different types. Outline is a concrete implementation of
the abstract model. It's still not the code, but there you have 1:1
mapping of "class outlines" and "field outlines" onto concrete Java
constructs. When you render the outline into the code model, you
create these concrete Java constructs. Not as Java files but first in
memory as a JCodeModel structure. This structure is finally
serialized.

From this whole process you could theoretically reuse the first part
only - loading the model from the schema. On the later phases you have
no chance at all.

As for loading the model, this could theoretically work. Schema model
is in the major part not language-dependent. Still, as I see from the
source code, you DO have JCodeModel already on this stage. I'm not
sure how much is used from this code model, hopefully not much.

I hope this helps you.

Bye.
/lexi