java - How can I reference the ObjectFactory class generated by xjc from within my xjc plugin code? -
ideally add generated code objectfactory class. if not possible use generated objectfactory parameter in generated method.
this scenario this:
import com.sun.tools.xjc.plugin; import com.sun.tools.xjc.outline.outline; import com.sun.tools.xjc.outline.classoutline; import com.sun.codemodel.jmethod; import com.sun.codemodel.jmod; public class app extends plugin { ... private static void generatemymethod(outline model, classoutline classoutline) { //somehow 'objectfactoryinstance' jmethod method = classoutline.implclass.method(jmod.public | jmod.final | jmod.static, void.class, "useobjectfactory") .param(objectfactoryinstance, "input")); } }
and generated code should this:
public final static void useobjectfactory(objectfactory input) { //stuff happens here }
the question how can reach generated objectfactory within xjc plugin?
the other generated classes accessible this, except objectfactory:
@override public boolean run(outline model, options opt, errorhandler errorhandler) throws saxexception { (classoutline classoutline : model.getclasses()) { //do generated class } }
i wasn't able access generated objectfactory class accessed other generated classes. i'm generating code assumes objectfactory generated. based on assumption create class method wanted.
import com.sun.codemodel.jblock; import com.sun.codemodel.jexpr; import com.sun.codemodel.jexpression; import com.sun.codemodel.jmethod; import com.sun.codemodel.jmod; import com.sun.codemodel.jvar; import com.sun.tools.xjc.outline.classoutline; //... public void generatemethodthatusesobjectfactory(classoutline classoutline) { jmethod method = classoutline.implclass.method(jmod.public | jmod.final, model.getmodel().codemodel.void, "useobjectfactory"); jvar objectfactory = method.param(model.getmodel().codemodel.ref(object.class), "input"); jexpression objectfactorycast = jexpr.cast(model.getmodel().codemodel.ref("objectfactory"), objectfactory); jblock body = method.body(); //add objectfactory , objectfactorycast method body //... } //...
the generated result looks similar code:
public final static void useobjectfactory(object input) { jaxbelement<sometype> je = ((objectfactory) input).callmethodofobjectfactory(); //... }
i don't think ideal approach, works. in hope better answer @ point in time won't accept own answer @ point.
Comments
Post a Comment