Refine search
private void addComplexType(Outline outline, Map<String, JFieldVar> namespaceFields) { Set<Map.Entry<NClass, CClassInfo>> set = outline.getModel().beans().entrySet(); for (Map.Entry<NClass, CClassInfo> entry : set) { ClassOutline classOutline = outline.getClazz(entry.getValue()); QName qname = entry.getValue().getTypeName(); if (qname == null) { continue; } JFieldVar namespaceField = namespaceFields.get(qname.getNamespaceURI()); createQName(outline, classOutline.implClass, COMPLEX_TYPE_FIELD_NAME, qname, namespaceField, false, false); } }
public static CCustomizations getCustomizations(final Model model) { final CCustomizations main = new CCustomizations(model .getCustomizations()); return main; }
private CClassInfo createDefaultClass() { String className = owner.model.getNameConverter().toClassName(name); QName tagName = new QName("",name); return new CClassInfo(owner.model,owner.getTargetPackage(),className,locator,null,tagName,null,null/*TODO*/); }
JAXBModelImpl(Outline outline) { this.model = outline.getModel(); this.outline = outline; for (CClassInfo ci : model.beans().values()) { if(!ci.isElement()) continue; byXmlName.put(ci.getElementName(),new BeanMappingImpl(this,ci)); } for (CElementInfo ei : model.getElementMappings(null).values()) { byXmlName.put(ei.getElementName(),new ElementMappingImpl(this,ei)); } }
/** * Returns all <i>used</i> JPackages. * * A JPackage is considered as "used" if a ClassItem or * a InterfaceItem resides in that package. * * This value is dynamically calculated every time because * one can freely remove ClassItem/InterfaceItem. * * @return * Given the same input, the order of packages in the array * is always the same regardless of the environment. */ public final JPackage[] getUsedPackages( Aspect aspect ) { Set<JPackage> s = new TreeSet<JPackage>(); for( CClassInfo bean : model.beans().values() ) { JClassContainer cont = getContainer(bean.parent(),aspect); if(cont.isPackage()) s.add( (JPackage)cont ); } for( CElementInfo e : model.getElementMappings(null).values() ) { // at the first glance you might think we should be iterating all elements, // not just global ones, but if you think about it, local ones live inside // another class, so those packages are already enumerated when we were // walking over CClassInfos. s.add( e._package() ); } return s.toArray(new JPackage[s.size()]); }
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); }
public <T> T getCustomization(final Class<T> customizationClass, final Deque<CCustomizable> schemaComponents) { final QName qName = getQName(customizationClass); if (!schemaComponents.isEmpty()) { final CCustomizable schemaComponent = schemaComponents.pop(); final CPluginCustomization pluginCustomization = schemaComponent.getCustomizations().find(qName.getNamespaceURI(), qName.getLocalPart()); if (pluginCustomization == null) { return getCustomization(customizationClass, schemaComponents); } else { pluginCustomization.markAsAcknowledged(); return JAXB.unmarshal(new DOMSource(pluginCustomization.element), customizationClass); } } else { final CPluginCustomization pluginCustomization = this.outline.getModel().getCustomizations().find(qName.getNamespaceURI(), qName.getLocalPart()); if (pluginCustomization != null) { pluginCustomization.markAsAcknowledged(); return JAXB.unmarshal(new DOMSource(pluginCustomization.element), customizationClass); } else { return null; } } }
private void addContainerName(Outline outline, Map<String, JFieldVar> namespaceFields) { Map<QName, List<QName>> complexTypeToElementName = null; Set<Map.Entry<NClass, CClassInfo>> set = outline.getModel().beans().entrySet(); for (Map.Entry<NClass, CClassInfo> entry : set) { CClassInfo classInfo = entry.getValue(); JFieldVar var = namespaceFields.get(qname.getNamespaceURI()); JInvocation invocation = JExpr._new(CLASS_MAP.get(QName.class)); if (var != null) { JClass schemaClass = outline.getModel().codeModel._getClass(StepSchemaConstants.SCHEMA_CONSTANTS_GENERATED_CLASS_NAME); invocation.arg(schemaClass.staticRef(var)); invocation.arg(qname.getLocalPart()); } else { invocation.arg(qname.getNamespaceURI()); invocation.arg(qname.getLocalPart());
for (CElementInfo elementInfo : outline.getModel().getAllElements()) { QName name = elementInfo.getElementName(); XSComponent elementDecl; elementDecl = elementInfo.getSchemaComponent(); } else { elementDecl = schemaSet.getElementDecl(name.getNamespaceURI(), name.getLocalPart()); nameValue.generate(nameFormatter); if (("\""+name.getNamespaceURI()+"\"").equals(namespaceWriter.toString()) && ("\""+name.getLocalPart()+"\"").equals(nameWriter.toString())) { print("*** Annotating method as @Raw: " + method.name());
/** * Returns the "squeezed name" of this element. * * @see CClassInfo#getSqueezedName() */ @XmlElement public String getSqueezedName() { if(squeezedName!=null) return squeezedName; StringBuilder b = new StringBuilder(); CClassInfo s = getScope(); if(s!=null) b.append(s.getSqueezedName()); if(className!=null) b.append(className); else b.append( model.getNameConverter().toClassName(tagName.getLocalPart())); return b.toString(); }
@Override public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) throws Exception { Model model = outline.getModel(); JDefinedClass schemaConstants = model.codeModel._class(SCHEMA_CONSTANTS_GENERATED_CLASS_NAME); Map<QName, CElementInfo> map = model.getElementMappings(null); Set<Map.Entry<QName, CElementInfo>> set = map.entrySet(); for (Map.Entry<QName, CElementInfo> entry : set) { JFieldVar var = namespaceFields.get(field.getValue().getNamespaceURI()); createQName(outline, schemaConstants, field.getFieldName(), field.getValue(), var, true, true);
public static ClassOutline findClassOutline(Outline outline, QName type) { Set<Map.Entry<NClass, CClassInfo>> set = outline.getModel().beans().entrySet(); for (Map.Entry<NClass, CClassInfo> entry : set) { ClassOutline classOutline = outline.getClazz(entry.getValue()); QName qname = entry.getValue().getTypeName(); if (!type.equals(qname)) { continue; } return classOutline; } throw new IllegalStateException("Object type class defined by qname '" + type + "' outline was not found."); }
for (CEnumLeafInfo p : model.enums().values()) { enums.put(p, generateEnumDef(p)); for (CClassInfo bean : model.beans().values()) { getClazz(bean); JClass OBJECT = codeModel.ref(Object.class); CClassInfo superClass = cc.target.getBaseClass(); if (superClass != null) { CClassRef refSuperClass = cc.target.getRefBaseClass(); if (refSuperClass != null) { cc.implClass._extends(refSuperClass.toType(this, EXPOSED)); CClassInfoParent base = cc.target.parent(); if ((base != null) && (base instanceof CClassInfo)) { String pkg = base.getOwnerPackage().name(); for (CElementInfo ei : model.getAllElements()) { getPackageContext(ei._package()).objectFactoryGenerator().populate(ei); codeModel._prepareModuleInfo(model.options.getModuleName(), JAXB_PACKAGE);
packageName, tempXsdFile.getAbsolutePath() }); Model model = ModelLoader.load(options, new JCodeModel(), errorReceiver); if (model.generateCode(options, errorReceiver) == null) { throw new Cob2JaxbGeneratorException( "JAXB-XJC failed to compile a schema"); model.codeModel.build(targetFolder); tempXsdFile.deleteOnExit(); } catch (IOException e) {
/** * Generates an attribute wildcard property on a class. */ private void generateAttributeWildcard(ClassOutlineImpl cc) { String FIELD_NAME = "otherAttributes"; String METHOD_SEED = model.getNameConverter().toClassName(FIELD_NAME); JClass mapType = codeModel.ref(Map.class).narrow(QName.class, String.class); JClass mapImpl = codeModel.ref(HashMap.class).narrow(QName.class, String.class); // [RESULT] // Map<QName,String> m = new HashMap<QName,String>(); JFieldVar $ref = cc.implClass.field(JMod.PRIVATE, mapType, FIELD_NAME, JExpr._new(mapImpl)); $ref.annotate2(XmlAnyAttributeWriter.class); MethodWriter writer = cc.createMethodWriter(); JMethod $get = writer.declareMethod(mapType, "get" + METHOD_SEED); $get.javadoc().append( "Gets a map that contains attributes that aren't bound to any typed property on this class.\n\n" + "<p>\n" + "the map is keyed by the name of the attribute and \n" + "the value is the string value of the attribute.\n" + "\n" + "the map returned by this method is live, and you can add new attribute\n" + "by updating the map directly. Because of this design, there's no setter.\n"); $get.javadoc().addReturn().append("always non-null"); $get.body()._return($ref); }
for( CEnumLeafInfo p : model.enums().values() ) enums.put( p, generateEnumDef(p) ); for( CClassInfo bean : model.beans().values() ) getClazz(bean); p.calcDefaultValues(); JClass OBJECT = codeModel.ref(Object.class); CClassInfo superClass = cc.target.getBaseClass(); if(superClass!=null) { CClassRef refSuperClass = cc.target.getRefBaseClass(); if(refSuperClass!=null) { cc.implClass._extends(refSuperClass.toType(this,EXPOSED)); for( CElementInfo ei : model.getAllElements()) getPackageContext(ei._package()).objectFactoryGenerator().populate(ei);
private void execute(String configuration) throws Exception { Options options = createOptions(configuration); Model model = ModelLoader.load(options, new JCodeModel(), ERROR_RECEIVER); Outline outline = model.generateCode(model.options, ERROR_RECEIVER); writeCode(outline); }
&& field.getPropertyInfo().getAdapter().customType != null ) typeInfo = field.parent().parent().getModel().getTypeInfo( field.getPropertyInfo().getAdapter().customType ); tryCopy._catch( field.parent().parent().getCodeModel().ref( Exception.class ) ); ref( AssertionError.class ) ).arg( e ) );
/** * The whole type set can be later bound to a reference property, * in which case we need to generate additional code to wrap this * type reference into an element class. * * This method generates such an element class and returns it. */ protected void toElementRef(CReferencePropertyInfo prop) { CClassInfo scope = Ring.get(ClassSelector.class).getCurrentBean(); Model model = Ring.get(Model.class); CCustomizations custs = Ring.get(BGMBuilder.class).getBindInfo(decl).toCustomizationList(); if(target instanceof CClassInfo && Ring.get(BIGlobalBinding.class).isSimpleMode()) { CClassInfo bean = new CClassInfo(model,scope, model.getNameConverter().toClassName(decl.getName()), decl.getLocator(), null, BGMBuilder.getName(decl), decl, custs); bean.setBaseClass((CClassInfo)target); prop.getElements().add(bean); } else { CElementInfo e = new CElementInfo(model,BGMBuilder.getName(decl),scope,target, decl.getDefaultValue(), decl, custs, decl.getLocator()); prop.getElements().add(e); } }
protected CPropertyInfo(String name, boolean collection, XSComponent source, CCustomizations customizations, Locator locator) { this.publicName = name; String n = null; Model m = Ring.get(Model.class); if (m != null) { n = m.getNameConverter().toVariableName(name); } else { n = NameConverter.standard.toVariableName(name); } if(!JJavaName.isJavaIdentifier(n)) n = '_'+n; // avoid colliding with the reserved names like 'abstract'. this.privateName = n; this.isCollection = collection; this.locator = locator; if(customizations==null) this.customizations = CCustomizations.EMPTY; else this.customizations = customizations; this.source = source; }