dev@jaxb.java.net

Re: Prostprocessing model - creating properties and classes from JAXB plugin

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Mon, 23 Feb 2009 11:29:33 +0100

Hi.

> we'll look at it. It would help us if you could locate which exact version
> of JAXB introduced this problem.

Thanks a lot.
I've checked the releases, the problem first appears with 2.1.8.

The problem is caused by the following line in the CClassInfo constructor:

BIFactoryMethod factoryMethod =
Ring.get(BGMBuilder.class).getBindInfo(source).get(BIFactoryMethod.class);

In 2.1.7 this constructor is as follows:

    public CClassInfo(Model model,JCodeModel cm, String fullName,
Locator location, QName typeName, QName elementName, XSComponent
source, CCustomizations customizations) {
        super(model,source,location,customizations);
        this.model = model;
        int idx = fullName.indexOf('.');
        if(idx<0) {
            this.parent = model.getPackage(cm.rootPackage());
            this.shortName = model.allocator.assignClassName(parent,fullName);
        } else {
            this.parent =
model.getPackage(cm._package(fullName.substring(0,idx)));
            this.shortName =
model.allocator.assignClassName(parent,fullName.substring(idx+1));
        }
        this.typeName = typeName;
        this.elementName = elementName;

        model.add(this);
    }

In 2.1.8 it looks as follows:

    public CClassInfo(Model model,CClassInfoParent p, String
shortName, Locator location, QName typeName, QName elementName,
XSComponent source, CCustomizations customizations) {
        super(model,source,location,customizations);
        this.model = model;
        this.parent = p;
        this.shortName = model.allocator.assignClassName(parent,shortName);
        this.typeName = typeName;
        this.elementName = elementName;

        Language schemaLanguage = model.options.getSchemaLanguage();
        if ((schemaLanguage != null) &&
            (schemaLanguage.equals(Language.XMLSCHEMA) ||
schemaLanguage.equals(Language.WSDL))) {
            BIFactoryMethod factoryMethod =
Ring.get(BGMBuilder.class).getBindInfo(source).get(BIFactoryMethod.class);
            if(factoryMethod!=null) {
                factoryMethod.markAsAcknowledged();
                this.squeezedName = factoryMethod.name;
            }
        }

        model.add(this);
    }

When invoked outside of the Ring.begin() .... Ring.end(...) cycle of
the BGMBuilder.build(...), this constructor fails since the Ring is
empty.
I think there are two possibilities to resolve this:
* Execute model postprocessing inside this BGMBuilder.build(...) ring cycle.
* Allow BGMBuilder to live longer.

The first one seems more elegant to me...

Thank you for the prompt reaction.

Bye.
/lexi