public ArrayInfoImpl(ModelBuilder<TypeT,ClassDeclT,FieldT,MethodT> builder, Locatable upstream, TypeT arrayType) { super(builder, upstream); this.arrayType = arrayType; TypeT componentType = nav().getComponentType(arrayType); this.itemType = builder.getTypeInfo(componentType, this); QName n = itemType.getTypeName(); if(n==null) { builder.reportError(new IllegalAnnotationException(Messages.ANONYMOUS_ARRAY_ITEM.format( nav().getTypeName(componentType)),this)); n = new QName("#dummy"); // for error recovery } this.typeName = ArrayInfoUtil.calcArrayTypeName(n); }
@Override public RuntimeTypeInfoSet link() { return (RuntimeTypeInfoSet)super.link(); }
/** * This method is used to add a root reference to a model. */ public NonElement<T,C> getTypeInfo(Ref<T,C> ref) { // TODO: handle XmlValueList assert !ref.valueList; C c = nav.asDecl(ref.type); if(c!=null && reader.getClassAnnotation(XmlRegistry.class,c,null/*TODO: is this right?*/)!=null) { if(!registries.containsKey(nav.getPackageName(c))) addRegistry(c,null); return null; // TODO: is this correct? } else return getTypeInfo(ref.type,null); }
/** * Have the builder recognize the type (if it hasn't done so yet), * and returns a {@link NonElement} that represents it. * * @return * always non-null. */ public NonElement<T,C> getTypeInfo(T t,Locatable upstream) { NonElement<T,C> r = typeInfoSet.getTypeInfo(t); if(r!=null) return r; if(nav.isArray(t)) { // no need for checking byte[], because above typeInfoset.getTypeInfo() would return non-null ArrayInfoImpl<T,C,F,M> ai = createArrayInfo(upstream, t); addTypeName(ai); typeInfoSet.add(ai); return ai; } C c = nav.asDecl(t); assert c!=null : t.toString()+" must be a leaf, but we failed to recognize it."; return getClassInfo(c,upstream); }
anno = reader().getMethodAnnotation( XmlElementDecl.class, m, this ); assert anno!=null; // the caller should check this assert anno instanceof Locatable; elementType = nav().getReturnType(m); T baseClass = nav().getBaseClass(elementType,nav().asDecl(JAXBElement.class)); if(baseClass==null) throw new IllegalAnnotationException( Messages.XML_ELEMENT_MAPPING_ON_NON_IXMLELEMENT_METHOD.format(nav().getMethodName(m)), anno ); if(list==null) { isCollection = false; contentType = builder.getTypeInfo(tOfJAXBElementT,this); // suck this type into the current set. } else { isCollection = true; contentType = builder.getTypeInfo(nav().getTypeArgument(list,0),this); contentType = builder.getTypeInfo(this.adapter.defaultType,this); isCollection = false; else { NonElement<T,C> scp = builder.getClassInfo(nav().asDecl(s),this); if(!(scp instanceof ClassInfo)) { throw new IllegalAnnotationException( Messages.SCOPE_IS_NOT_COMPLEXTYPE.format(nav().getTypeName(s)), anno );
if(nav.isEnum(clazz)) { EnumLeafInfoImpl<T,C,F,M> li = createEnumLeafInfo(clazz,upstream); typeInfoSet.add(li); r = li; addTypeName(r); } else { boolean isReplaced = subclassReplacements.containsKey(clazz); if(isReplaced && !searchForSuperClass) { r = getClassInfo(subclassReplacements.get(clazz),upstream); } else if(reader.hasClassAnnotation(clazz,XmlTransient.class) || isReplaced) { r = getClassInfo( nav.getSuperClass(clazz), searchForSuperClass, new ClassLocatable<C>(upstream,clazz,nav) ); } else { ClassInfoImpl<T,C,F,M> ci = createClassInfo(clazz,upstream); typeInfoSet.add(ci); addToRegistry(clazz, (Locatable) p); Class[] prmzdClasses = getParametrizedTypes(p); if (prmzdClasses != null) { for (Class prmzdClass : prmzdClasses) { if (prmzdClass != clazz) { addToRegistry((C) prmzdClass, (Locatable) p); addTypeName(r); XmlSeeAlso sa = reader.getClassAnnotation(XmlSeeAlso.class, clazz, upstream);
builder.registries.put(getPackageName(),this); if(nav.getDeclaredField(registryClass,ContextFactory.USE_JAXB_PROPERTIES)!=null) { builder.reportError(new IllegalAnnotationException( Messages.MISSING_JAXB_PROPERTIES.format(getPackageName()), this for( M m : nav.getDeclaredMethods(registryClass) ) { XmlElementDecl em = builder.reader.getMethodAnnotation( XmlElementDecl.class, m, this ); if(nav.getMethodName(m).startsWith("create")) { builder.getTypeInfo(nav.getReturnType(m), new MethodLocatable<M>(this,m,nav))); ei = builder.createElementInfo(this,m); } catch (IllegalAnnotationException e) { builder.reportError(e); continue; // recover by ignoring this element
/** * @param clazz * @param type * clazz and type should both point to the enum class * that this {@link EnumLeafInfo} represents. * Because of the type parameterization we have to take them separately. */ public EnumLeafInfoImpl(ModelBuilder<T,C,F,M> builder, Locatable upstream, C clazz, T type ) { super(builder,upstream); this.clazz = clazz; this.type = type; elementName = parseElementName(clazz); // compute the type name // TODO: I guess it must be allowed for enums to have @XmlElement typeName = parseTypeName(clazz); // locate the base type. // this can be done eagerly because there shouldn't be no cycle. XmlEnum xe = builder.reader.getClassAnnotation(XmlEnum.class, clazz, this); if(xe!=null) { T base = builder.reader.getClassValue(xe, "value"); baseType = builder.getTypeInfo(base,this); } else { baseType = builder.getTypeInfo(builder.nav.ref(String.class),this); } }
new ModelBuilder<TypeMirror, TypeElement, VariableElement, ExecutableElement>( InlineAnnotationReaderImpl.theInstance, new ApNavigator(env), defaultNamespaceRemap ); builder.setErrorHandler(new ErrorHandlerImpl(env.getMessager())); XmlList xl = ref.annotations.getAnnotation(XmlList.class); builder.getTypeInfo(new Ref<TypeMirror, TypeElement>(builder, t, xjta, xl)); TypeInfoSet<TypeMirror, TypeElement, VariableElement, ExecutableElement> r = builder.link(); if(r==null) return null;
public NonElement<T,C> getTarget(T type) { assert parent.builder!=null : "this method must be called during the build stage"; return parent.builder.getTypeInfo(type,this); } }
/** * Adding package's ObjectFactory methods to registry * @param clazz which package will be used * @param p location */ private void addToRegistry(C clazz, Locatable p) { String pkg = nav.getPackageName(clazz); if (!registries.containsKey(pkg)) { // insert the package's object factory C c = nav.loadObjectFactory(clazz, pkg); if (c != null) addRegistry(c, p); } }
anno = reader().getMethodAnnotation( XmlElementDecl.class, m, this ); assert anno!=null; // the caller should check this assert anno instanceof Locatable; elementType = nav().getReturnType(m); T baseClass = nav().getBaseClass(elementType,nav().asDecl(JAXBElement.class)); if(baseClass==null) throw new IllegalAnnotationException( Messages.XML_ELEMENT_MAPPING_ON_NON_IXMLELEMENT_METHOD.format(nav().getMethodName(m)), anno ); if(list==null) { isCollection = false; contentType = builder.getTypeInfo(tOfJAXBElementT,this); // suck this type into the current set. } else { isCollection = true; contentType = builder.getTypeInfo(nav().getTypeArgument(list,0),this); contentType = builder.getTypeInfo(this.adapter.defaultType,this); isCollection = false; else { NonElement<T,C> scp = builder.getClassInfo(nav().asDecl(s),this); if(!(scp instanceof ClassInfo)) { throw new IllegalAnnotationException( Messages.SCOPE_IS_NOT_COMPLEXTYPE.format(nav().getTypeName(s)), anno );
if(nav.isEnum(clazz)) { EnumLeafInfoImpl<T,C,F,M> li = createEnumLeafInfo(clazz,upstream); typeInfoSet.add(li); r = li; addTypeName(r); } else { boolean isReplaced = subclassReplacements.containsKey(clazz); if(isReplaced && !searchForSuperClass) { r = getClassInfo(subclassReplacements.get(clazz),upstream); } else if(reader.hasClassAnnotation(clazz,XmlTransient.class) || isReplaced) { r = getClassInfo( nav.getSuperClass(clazz), searchForSuperClass, new ClassLocatable<C>(upstream,clazz,nav) ); } else { ClassInfoImpl<T,C,F,M> ci = createClassInfo(clazz,upstream); typeInfoSet.add(ci); addToRegistry(clazz, (Locatable) p); Class[] prmzdClasses = getParametrizedTypes(p); if (prmzdClasses != null) { for (Class prmzdClass : prmzdClasses) { if (prmzdClass != clazz) { addToRegistry((C) prmzdClass, (Locatable) p); addTypeName(r); XmlSeeAlso sa = reader.getClassAnnotation(XmlSeeAlso.class, clazz, upstream);
builder.registries.put(getPackageName(),this); if(nav.getDeclaredField(registryClass,ContextFactory.USE_JAXB_PROPERTIES)!=null) { builder.reportError(new IllegalAnnotationException( Messages.MISSING_JAXB_PROPERTIES.format(getPackageName()), this for( M m : nav.getDeclaredMethods(registryClass) ) { XmlElementDecl em = builder.reader.getMethodAnnotation( XmlElementDecl.class, m, this ); if(nav.getMethodName(m).startsWith("create")) { builder.getTypeInfo(nav.getReturnType(m), new MethodLocatable<M>(this,m,nav))); ei = builder.createElementInfo(this,m); } catch (IllegalAnnotationException e) { builder.reportError(e); continue; // recover by ignoring this element
/** * Have the builder recognize the type (if it hasn't done so yet), * and returns a {@link NonElement} that represents it. * * @return * always non-null. */ public NonElement<T,C> getTypeInfo(T t,Locatable upstream) { NonElement<T,C> r = typeInfoSet.getTypeInfo(t); if(r!=null) return r; if(nav.isArray(t)) { // no need for checking byte[], because above typeInfoset.getTypeInfo() would return non-null ArrayInfoImpl<T,C,F,M> ai = createArrayInfo(upstream, t); addTypeName(ai); typeInfoSet.add(ai); return ai; } C c = nav.asDecl(t); assert c!=null : t.toString()+" must be a leaf, but we failed to recognize it."; return getClassInfo(c,upstream); }
/** * @param clazz * @param type * clazz and type should both point to the enum class * that this {@link EnumLeafInfo} represents. * Because of the type parameterization we have to take them separately. */ public EnumLeafInfoImpl(ModelBuilder<T,C,F,M> builder, Locatable upstream, C clazz, T type ) { super(builder,upstream); this.clazz = clazz; this.type = type; elementName = parseElementName(clazz); // compute the type name // TODO: I guess it must be allowed for enums to have @XmlElement typeName = parseTypeName(clazz); // locate the base type. // this can be done eagerly because there shouldn't be no cycle. XmlEnum xe = builder.reader.getClassAnnotation(XmlEnum.class, clazz, this); if(xe!=null) { T base = builder.reader.getClassValue(xe, "value"); baseType = builder.getTypeInfo(base,this); } else { baseType = builder.getTypeInfo(builder.nav.ref(String.class),this); } }
new ModelBuilder<TypeMirror, TypeElement, VariableElement, ExecutableElement>( InlineAnnotationReaderImpl.theInstance, new ApNavigator(env), defaultNamespaceRemap ); builder.setErrorHandler(new ErrorHandlerImpl(env.getMessager())); XmlList xl = ref.annotations.getAnnotation(XmlList.class); builder.getTypeInfo(new Ref<TypeMirror, TypeElement>(builder, t, xjta, xl)); TypeInfoSet<TypeMirror, TypeElement, VariableElement, ExecutableElement> r = builder.link(); if(r==null) return null;
private void calcRef() { // we can't do this eagerly because of a cyclic dependency ref = owner.parent.builder.getTypeInfo(type,owner); assert ref!=null; }
/** * Adding package's ObjectFactory methods to registry * @param clazz which package will be used * @param p location */ private void addToRegistry(C clazz, Locatable p) { String pkg = nav.getPackageName(clazz); if (!registries.containsKey(pkg)) { // insert the package's object factory C c = nav.loadObjectFactory(clazz, pkg); if (c != null) addRegistry(c, p); } }
public ArrayInfoImpl(ModelBuilder<TypeT,ClassDeclT,FieldT,MethodT> builder, Locatable upstream, TypeT arrayType) { super(builder, upstream); this.arrayType = arrayType; TypeT componentType = nav().getComponentType(arrayType); this.itemType = builder.getTypeInfo(componentType, this); QName n = itemType.getTypeName(); if(n==null) { builder.reportError(new IllegalAnnotationException(Messages.ANONYMOUS_ARRAY_ITEM.format( nav().getTypeName(componentType)),this)); n = new QName("#dummy"); // for error recovery } this.typeName = ArrayInfoUtil.calcArrayTypeName(n); }