use of com.sun.tools.xjc.reader.xmlschema.bindinfo.BISchemaBinding in project jaxb-ri by eclipse-ee4j.
the class DefaultClassBinder method complexType.
@Override
public CElement complexType(XSComplexType type) {
CElement ci = allow(type, type.getName());
if (ci != null)
return ci;
// no customization is given -- do as the default binding.
BindInfo bi = builder.getBindInfo(type);
if (type.isGlobal()) {
QName tagName = null;
String className = deriveName(type);
Locator loc = type.getLocator();
if (getGlobalBinding().isSimpleMode()) {
// in the simple mode, we may optimize it away
XSElementDecl referer = getSoleElementReferer(type);
if (referer != null && isCollapsable(referer)) {
// if a global element contains
// a collpsable complex type, we bind this element to a named one
// and collapses element and complex type.
tagName = getName(referer);
className = deriveName(referer);
loc = referer.getLocator();
}
}
// by default, global ones get their own classes.
JPackage pkg = selector.getPackage(type.getTargetNamespace());
return new CClassInfo(model, pkg, className, loc, getTypeName(type), tagName, type, bi.toCustomizationList());
} else {
XSElementDecl element = type.getScope();
if (element.isGlobal() && isCollapsable(element)) {
if (builder.getBindInfo(element).get(BIClass.class) != null)
// cause unnecessary wrapping
return null;
// which creates unnecessary classes
return new CClassInfo(model, selector.getClassScope(), deriveName(element), element.getLocator(), null, getName(element), element, bi.toCustomizationList());
}
CElement parentType = selector.isBound(element, type);
String className;
CClassInfoParent scope;
if (parentType != null && parentType instanceof CElementInfo && ((CElementInfo) parentType).hasClass()) {
// special case where we put a nested 'Type' element
scope = (CElementInfo) parentType;
className = "Type";
} else {
// since the parent element isn't bound to a type, merge the customizations associated to it, too.
// custs = CCustomizations.merge( custs, builder.getBindInfo(type.getScope()).toCustomizationList());
className = builder.getNameConverter().toClassName(element.getName());
BISchemaBinding sb = builder.getBindInfo(type.getOwnerSchema()).get(BISchemaBinding.class);
if (sb != null)
className = sb.mangleAnonymousTypeClassName(className);
scope = selector.getClassScope();
}
return new CClassInfo(model, scope, className, type.getLocator(), null, null, type, bi.toCustomizationList());
}
}
use of com.sun.tools.xjc.reader.xmlschema.bindinfo.BISchemaBinding in project jaxb-ri by eclipse-ee4j.
the class BGMBuilder method processPackageJavadoc.
/**
* Generates <code>package.html</code> if the customization
* says so.
*/
private void processPackageJavadoc(XSSchema s) {
// look for the schema-wide customization
BISchemaBinding cust = getBindInfo(s).get(BISchemaBinding.class);
// not present
if (cust == null)
return;
cust.markAsAcknowledged();
// no javadoc customization
if (cust.getJavadoc() == null)
return;
// produce a HTML file
JTextFile html = new JTextFile("package.html");
html.setContents(cust.getJavadoc());
getClassSelector().getPackage(s.getTargetNamespace()).addResourceFile(html);
}
use of com.sun.tools.xjc.reader.xmlschema.bindinfo.BISchemaBinding in project jaxb-ri by eclipse-ee4j.
the class ClassSelector method _bindToClass.
/**
* The real meat of the "bindToType" code.
*
* @param cannotBeDelayed
* if the binding of the body of the class cannot be defered
* and needs to be done immediately. If the flag is false,
* the binding of the body will be done later, to avoid
* cyclic binding problem.
* @param referer
* The component that refers to {@code sc}. This can be null,
* if figuring out the referer is too hard, in which case
* the error message might be less user friendly.
*/
// TODO: consider getting rid of "cannotBeDelayed"
CTypeInfo _bindToClass(@NotNull XSComponent sc, XSComponent referer, boolean cannotBeDelayed) {
// check if this class is already built.
if (!bindMap.containsKey(sc)) {
// craete a bind task
// if this is a global declaration, make sure they will be generated
// under a package.
boolean isGlobal = false;
if (sc instanceof XSDeclaration) {
isGlobal = ((XSDeclaration) sc).isGlobal();
if (isGlobal)
pushClassScope(new CClassInfoParent.Package(getPackage(((XSDeclaration) sc).getTargetNamespace())));
}
// otherwise check if this component should become a class.
CElement bean = sc.apply(classBinder);
if (isGlobal)
popClassScope();
if (bean == null)
return null;
// can this namespace generate a class?
if (bean instanceof CClassInfo) {
XSSchema os = sc.getOwnerSchema();
BISchemaBinding sb = builder.getBindInfo(os).get(BISchemaBinding.class);
if (sb != null && !sb.map) {
// nope
getErrorReporter().error(sc.getLocator(), Messages.ERR_REFERENCE_TO_NONEXPORTED_CLASS, sc.apply(new ComponentNameFunction()));
getErrorReporter().error(sb.getLocation(), Messages.ERR_REFERENCE_TO_NONEXPORTED_CLASS_MAP_FALSE, os.getTargetNamespace());
if (referer != null)
getErrorReporter().error(referer.getLocator(), Messages.ERR_REFERENCE_TO_NONEXPORTED_CLASS_REFERER, referer.apply(new ComponentNameFunction()));
}
}
queueBuild(sc, bean);
}
Binding bind = bindMap.get(sc);
if (cannotBeDelayed)
bind.build();
return bind.bean;
}
use of com.sun.tools.xjc.reader.xmlschema.bindinfo.BISchemaBinding in project jaxb-ri by eclipse-ee4j.
the class BGMBuilder method deriveName.
/**
* Derives a name from a schema component.
*
* This method handles prefix/suffix modification and
* XML-to-Java name conversion.
*
* @param name
* The base name. This should be things like element names
* or type names.
* @param comp
* The component from which the base name was taken.
* Used to determine how names are modified.
*/
public String deriveName(String name, XSComponent comp) {
XSSchema owner = comp.getOwnerSchema();
name = getNameConverter().toClassName(name);
if (owner != null) {
BISchemaBinding sb = getBindInfo(owner).get(BISchemaBinding.class);
if (sb != null)
name = sb.mangleClassName(name, comp);
}
return name;
}
use of com.sun.tools.xjc.reader.xmlschema.bindinfo.BISchemaBinding in project jaxb-ri by eclipse-ee4j.
the class BGMBuilder method buildContents.
/**
* Fill-in the contents of each classes.
*/
private void buildContents() {
ClassSelector cs = getClassSelector();
SimpleTypeBuilder stb = Ring.get(SimpleTypeBuilder.class);
for (XSSchema s : Ring.get(XSSchemaSet.class).getSchemas()) {
BISchemaBinding sb = getBindInfo(s).get(BISchemaBinding.class);
if (sb != null && !sb.map) {
sb.markAsAcknowledged();
// no mapping for this package
continue;
}
getClassSelector().pushClassScope(new CClassInfoParent.Package(getClassSelector().getPackage(s.getTargetNamespace())));
checkMultipleSchemaBindings(s);
processPackageJavadoc(s);
populate(s.getAttGroupDecls(), s);
populate(s.getAttributeDecls(), s);
populate(s.getElementDecls(), s);
populate(s.getModelGroupDecls(), s);
// fill in typeUses
for (XSType t : s.getTypes().values()) {
stb.refererStack.push(t);
model.typeUses().put(getName(t), cs.bindToType(t, s));
stb.refererStack.pop();
}
getClassSelector().popClassScope();
}
}
Aggregations