1

usually, JAXB is used to generate code from an xsd, which generates java classes for xsd complexType with annotations to convert it to xml and vice-versa.

I am trying to achieve something different. I want, to generate a data mapper class for each such xsd element. The mapper will map each field of the generated class with values from another datatype (say from database, or other stream)

so i need to: for every user-defined datatype in xsd, add a method in a DataMapper class map-<XSD-ComplexDataType-Class>() and generate method body.

to achieve this, i think it is not possible to generate this class in a Plugin extending com.sun.tools.internal.xjc.Plugin as in the run method, i wont be able to create a new JDefinedClass

is there any way to add a hook method before Model invokes Plugins ?

thanks,

weima
  • 4,653
  • 6
  • 34
  • 55

1 Answers1

0

There are a few things you can do. In my other answer I specificaly meant these:

  • In a plugin you can write and set your own com.sun.tools.xjc.generator.bean.field.FieldRendererFactory. Field renderers generate a FieldOutlines from CPropertyInfos. This is a step between the model and the outline. So if you want different code generated out of the model, consider implementing your own FieldRendererFactory. You can register a FieldRendererFactory via XJC plugin (see Options.setFieldRendererFactory(...)).
  • On the class level, you can write your own com.sun.tools.xjc.generator.bean.BeanGenerator and use it for code generation.
  • You can just use model and generate the code completely on your own. I do this in Jsonix when I produce JavaScript mappings for XML<->JSON.

As for your specific task, I would actually just postprocess the code model in the run method of your plugin. You have everything there - the model, the outline and also the code model (see outline.getCodeModel()). And you can definitely create your JDefinedClasses there, the code model exists already.

Community
  • 1
  • 1
lexicore
  • 42,748
  • 17
  • 132
  • 221
  • yes, i followed like you told at the end, i defined my own `JDefinedClass` and adding methods to it. it is in very initial stages. thanks! – weima Sep 22 '15 at 12:00