/** 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(); continue; // no mapping for this package } 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(); } }
/** List up all the global bindings. */ private void promoteGlobalBindings() { // promote any global bindings in the schema XSSchemaSet schemas = Ring.get(XSSchemaSet.class); for (XSSchema s : schemas.getSchemas()) { BindInfo bi = getBindInfo(s); // collect all global customizations model.getCustomizations().addAll(bi.toCustomizationList()); BIGlobalBinding gb = bi.get(BIGlobalBinding.class); if (gb == null) continue; if (globalBinding == null) { globalBinding = gb; globalBinding.markAsAcknowledged(); } else { // acknowledge this customization and report an error // otherwise the user will see "customization is attached to a wrong place" error, // which is incorrect gb.markAsAcknowledged(); getErrorReporter().error(gb.getLocation(), Messages.ERR_MULTIPLE_GLOBAL_BINDINGS); getErrorReporter() .error(globalBinding.getLocation(), Messages.ERR_MULTIPLE_GLOBAL_BINDINGS_OTHER); } } if (globalBinding == null) { // no global customization is present. // use the default one globalBinding = new BIGlobalBinding(); BindInfo big = new BindInfo(); big.addDecl(globalBinding); big.setOwner(this, null); } // code generation mode model.strategy = globalBinding.getCodeGenerationStrategy(); model.rootClass = globalBinding.getSuperClass(); model.rootInterface = globalBinding.getSuperInterface(); particleBinder = globalBinding.isSimpleMode() ? new ExpressionParticleBinder() : new DefaultParticleBinder(); // check XJC extensions and realize them BISerializable serial = globalBinding.getSerializable(); if (serial != null) { model.serializable = true; model.serialVersionUID = serial.uid; } // obtain the name conversion mode if (globalBinding.nameConverter != null) model.setNameConverter(globalBinding.nameConverter); // attach global conversions to the appropriate simple types globalBinding.dispatchGlobalConversions(schemas); globalBinding.errorCheck(); }
private void mapToClass(DElementPattern p) { NameClass nc = p.getName(); if (nc.isOpen()) return; // infinite name. can't map to a class. Set<QName> names = nc.listNames(); CClassInfo[] types = new CClassInfo[names.size()]; int i = 0; for (QName n : names) { // TODO: read class names from customization String name = model.getNameConverter().toClassName(n.getLocalPart()); bindQueue.put( types[i++] = new CClassInfo(model, pkg, name, p.getLocation(), null, n, null, null /*TODO*/), p.getChild()); } classes.put(p, types); }
private void promoteTypeSafeEnums() { // we'll be trying a lot of choices, // and most of them will not be type-safe enum. // using the same list improves the memory efficiency. List<CEnumConstant> members = new ArrayList<CEnumConstant>(); OUTER: for (DDefine def : defs) { DPattern p = def.getPattern(); if (p instanceof DChoicePattern) { DChoicePattern cp = (DChoicePattern) p; members.clear(); // check if the choice consists of all value patterns // and that they are of the same datatype DValuePattern vp = null; for (DPattern child : cp) { if (child instanceof DValuePattern) { DValuePattern c = (DValuePattern) child; if (vp == null) vp = c; else { if (!vp.getDatatypeLibrary().equals(c.getDatatypeLibrary()) || !vp.getType().equals(c.getType())) continue OUTER; // different type name } members.add( new CEnumConstant( model.getNameConverter().toConstantName(c.getValue()), null, c.getValue(), c.getLocation())); } else continue OUTER; // not a value } if (members.isEmpty()) continue; // empty choice CNonElement base = CBuiltinLeafInfo.STRING; DatatypeLib lib = datatypes.get(vp.getNs()); if (lib != null) { TypeUse use = lib.get(vp.getType()); if (use instanceof CNonElement) base = (CNonElement) use; } CEnumLeafInfo xducer = new CEnumLeafInfo( model, null, new CClassInfoParent.Package(pkg), def.getName(), base, new ArrayList<CEnumConstant>(members), null, null /*TODO*/, cp.getLocation()); classes.put(cp, new CTypeInfo[] {xducer}); } } }
/** * Name converter that implements "XML->Java name conversion" as specified in the spec. * * <p>This object abstracts the detail that we use different name conversion depending on the * customization. * * <p>This object should be used to perform any name conversion needs, instead of the JJavaName * class in CodeModel. */ public NameConverter getNameConverter() { return model.getNameConverter(); }