Hi /lexi and all the others (:
I still have no glue how to add a CClassInfo class to the model.
like you suggested, I tried to generate the class in the post process
model phase:
@Override
public void postProcessModel(Model model, ErrorHandler errorHandler) {
JPackage mainPackage = null;
//find the main package
for (CClassInfo classInfo : model.beans().values()) {
System.out.println(classInfo.fullName());
if (classInfo.shortName.equals("Kml")) {
mainPackage = classInfo.getOwnerPackage();
System.out.println(classInfo.getOwnerPackage().name());
break;
}
}
// assert mainPackage != null;
//try to create class in the mainpackage
CClassInfo myNewClass = new CClassInfo(model, mainPackage,
"MyNewClass", null, null, null, null, null);
...
but how still have no glue how to add a CClassInfo class to the model!
I have taken a look at
https://jaxb2-commons.dev.java.net/source/browse/jaxb2-commons/basic/src/main/java/org/jvnet/jaxb2_commons/plugin/
but I didn't find anything related to CClassInfo creation.
I although took a look at your
https://hj3.dev.java.net/svn/hj3/trunk/ejb/plugin/src/main/java/org/jvnet/hyperjaxb3/ejb/strategy/model/base/
but I don't understand the code at all.
In your EjbPlugin.java in line 184 you do something with the
mysterious Ring, which holds all the binding related components:-
final Ring ring = Ring.begin();
try {
ring.add(this.bgmBuilder);
final ModelAndOutlineProcessor<EjbPlugin> modelAndOutlineProcessor
=getModelAndOutlineProcessor();
modelAndOutlineProcessor.process(this, outline.getModel(), options);
} catch (Exception ex) {
ex.printStackTrace();
throw ex;
} finally {
Ring.end(ring);
}
for (final CClassInfo classInfo : getCreatedClasses()) {
final ClassOutline classOutline = outline.getClazz(classInfo);
if (Customizations.isGenerated(classInfo)) {
generateClassBody(outline, (ClassOutlineImpl) classOutline);
}
for (final CPropertyInfo propertyInfo : classInfo.getProperties()) {
if (outline.getField(propertyInfo) == null) {
generateFieldDecl(outline, (ClassOutlineImpl) classOutline,
propertyInfo);
}
}
}
as far as I understand this, you add all classes in the model to your
Collection<CClassInfo> returned by the getCreatedClasses() method,
which is filled in DefaultProcessModel.java in the process method and
then you only work on your collection as new outline or something like
this.
But isn't there a easy way to create a new class in the model, like:
model.add(myNewClass);
So that the classOutline can be easily generated by the bean generator?
regards
from a slightly desperate and a bit helpless
flori
On 06.05.2009, at 23:28, Aleksei Valikov wrote:
> Hi,
>
>> If I create a new class like:
>> CodeModelClassFactory classFactory = outline.getClassFactory();
>> coordinateClass = classFactory.createClass(kmlpackage, JMod.PUBLIC,
>> "Coordinate", null, ClassType.CLASS);
>>
>> // other class related stuff
>>
>>
>> the class doesn’t show up, if I iterate over the getClasses-
>> collection:
>> for (final ClassOutline classOutline : outline.getClasses()) {
>> createHashCodeAndEqualsMethod((ClassOutlineImpl)
>> classOutline);
>> LOG.info("---------> " + classOutline.implClass.fullName());
>> }
>>
>> Could you tell me, what’s the proper way, to add a new class in a
>> JAXB
>> plugin and to process the created class later (in the same plugin)?
>
> CodeModelClassFactory has nothing to do with class outlines.
>
> If you want to create an additional schema-derived class, you actually
> have to create a new CClassInfo during the "postprocess model" phase
> in your plugin. ClassOutline will be automatically generated by the
> bean generator.
>
> The generation sequence in XJC is model (CClassInfo, CPropertyInfo) ->
> outline (ClassOutline, FieldOutline) -> rendered code (JClass, ...).
>
> ps. I'm not sure if you are aware of jaxb2-commons "basic" plugins:
>
> https://jaxb2-commons.dev.java.net/source/browse/jaxb2-commons/basic/src/main/java/org/jvnet/jaxb2_commons/plugin/
>
> They might be helpful if you develop your own plugins. You can also
> check Hyperjaxb3 for code examples on working with XJC model:
>
> https://hj3.dev.java.net/svn/hj3/trunk/ejb/plugin/src/main/java/org/jvnet/hyperjaxb3/ejb/strategy/model/base/
>
> Bye.
> /lexi
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>