0
理想情況下,我想將一些生成的代碼添加到ObjectFactory類。如果這是不可能的,我想使用生成的ObjectFactory作爲另一個生成的方法中的參數。如何從xjc插件代碼中引用由xjc生成的ObjectFactory類?
這種情況會是這個樣子:
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 get 'objectFactoryInstance'
JMethod method = classOutline.implClass.method(JMod.PUBLIC | JMod.FINAL | JMod.STATIC, Void.class, "useObjectFactory")
.param(objectFactoryInstance, "input"));
}
}
和生成的代碼應該是這樣的:
public final static void useObjectFactory(ObjectFactory input) {
//stuff happens here
}
的問題是我如何從我的XJC內到達生成的ObjectFactory插入?
其他的生成類都是這樣的訪問,除了的ObjectFactory:
@Override
public boolean run(Outline model, Options opt, ErrorHandler errorHandler) throws SAXException {
for (ClassOutline classOutline : model.getClasses()) {
//do something with the generated class
}
}