public final void reportError(IllegalAnnotationException e) { hadError = true; if(errorHandler!=null) errorHandler.error(e); }
public Ref(AnnotationReader<T,C,?,?> reader, Navigator<T,C,?,?> nav, T type, XmlJavaTypeAdapter xjta, XmlList xl ) { Adapter<T,C> adapter=null; if(xjta!=null) { adapter = new Adapter<T,C>(xjta,reader,nav); type = adapter.defaultType; } this.type = type; this.adapter = adapter; this.valueList = xl!=null; } }
public void add( ArrayInfo<T,C> a ) { assert a!=null; final String namespaceURI = a.getTypeName().getNamespaceURI(); Namespace n = getNamespace(namespaceURI); n.arrays.add(a); // search for foreign namespace references n.addDependencyTo(a.getItemType().getTypeName()); }
if(clazz.getClazz()==navigator.asDecl(CompositeStructure.class)) return; // this is a special class we introduced for JAX-WS that we *don't* want in the schema if(clazz.isElement()) { nsUri = clazz.getElementName().getNamespaceURI(); Namespace ns = getNamespace(nsUri); ns.classes.add(clazz); ns.addDependencyTo(clazz.getTypeName()); add(clazz.getElementName(),false,clazz); QName tn = clazz.getTypeName(); if(tn!=null) { nsUri = tn.getNamespaceURI(); for( PropertyInfo<T,C> p : clazz.getProperties()) { n.processForeignNamespaces(p, 1); if (p instanceof AttributePropertyInfo) { AttributePropertyInfo<T,C> ap = (AttributePropertyInfo<T,C>) p; String aUri = ap.getXmlName().getNamespaceURI(); if(aUri.length()>0) { n.addDependencyTo(ap.getXmlName()); for (TypeRef<T,C> tref : ep.getTypes()) { String eUri = tref.getTagName().getNamespaceURI(); if(eUri.length()>0 && !eUri.equals(n.uri)) { getNamespace(eUri).addGlobalElement(tref);
/** * Adds a new element to the list of elements to be written. */ public void add( ElementInfo<T,C> elem ) { assert elem!=null; @SuppressWarnings("UnusedAssignment") boolean nillable = false; // default value QName name = elem.getElementName(); Namespace n = getNamespace(name.getNamespaceURI()); ElementInfo ei; if (elem.getScope() != null) { // (probably) never happens ei = this.types.getElementInfo(elem.getScope().getClazz(), name); } else { ei = this.types.getElementInfo(null, name); } XmlElement xmlElem = ei.getProperty().readAnnotation(XmlElement.class); if (xmlElem == null) { nillable = false; } else { nillable = xmlElem.nillable(); } n.elementDecls.put(name.getLocalPart(),n.new ElementWithType(nillable, elem.getContentType())); // search for foreign namespace references n.processForeignNamespaces(elem.getProperty(), 1); }
public XmlSchemaGenerator( Navigator<T,C,F,M> navigator, TypeInfoSet<T,C,F,M> types ) { this.navigator = navigator; this.types = types; this.stringType = types.getTypeInfo(navigator.ref(String.class)); this.anyType = types.getAnyTypeInfo(); // populate the object for( ClassInfo<T,C> ci : types.beans().values() ) add(ci); for( ElementInfo<T,C> ei1 : types.getElementMappings(null).values() ) add(ei1); for( EnumLeafInfo<T,C> ei : types.enums().values() ) add(ei); for( ArrayInfo<T,C> a : types.arrays().values()) add(a); }
public void add( EnumLeafInfo<T,C> envm ) { assert envm!=null; String nsUri = null; if(envm.isElement()) { // put element -> type reference nsUri = envm.getElementName().getNamespaceURI(); Namespace ns = getNamespace(nsUri); ns.enums.add(envm); ns.addDependencyTo(envm.getTypeName()); // schedule writing this global element add(envm.getElementName(),false,envm); } final QName typeName = envm.getTypeName(); if (typeName != null) { nsUri = typeName.getNamespaceURI(); } else { if(nsUri==null) return; // anonymous type } Namespace n = getNamespace(nsUri); n.enums.add(envm); // search for foreign namespace references n.addDependencyTo(envm.getBaseType().getTypeName()); }
private boolean addAllSubtypes(T type) { Navigator<T,C,F,M> nav = nav(); // this allows the explicitly referenced type to be sucked in to the model NonElement<T,C> t = parent.builder.getClassInfo(nav.asDecl(type),this); if(!(t instanceof ClassInfo)) // this is leaf. return false; boolean result = false; ClassInfo<T,C> c = (ClassInfo<T,C>) t; if(c.isElement()) { types.add(c.asElement()); result = true; } // look for other possible types for( ClassInfo<T,C> ci : parent.owner.beans().values() ) { if(ci.isElement() && nav.isSubClassOf(ci.getType(),type)) { types.add(ci.asElement()); result = true; } } // don't allow local elements to substitute. for( ElementInfo<T,C> ei : parent.owner.getElementMappings(null).values()) { if(nav.isSubClassOf(ei.getType(),type)) { types.add(ei); result = true; } } return result; }
private NonElement<Type,Class> getXmlType(RuntimeTypeInfoSet tis, TypeReference tr) { if(tr==null) throw new IllegalArgumentException(); XmlJavaTypeAdapter xjta = tr.get(XmlJavaTypeAdapter.class); XmlList xl = tr.get(XmlList.class); Ref<Type,Class> ref = new Ref<Type,Class>(annotationReader, tis.getNavigator(), tr.type, xjta, xl ); return tis.getTypeInfo(ref); }
public QName getTypeName(TypeReference tr) { try { NonElement<Type,Class> xt = getXmlType(getTypeInfoSet(),tr); if(xt==null) throw new IllegalArgumentException(); return xt.getTypeName(); } catch (IllegalAnnotationsException e) { // impossible given that JAXBRIContext has been successfully built in the first place throw new AssertionError(e); } }
/** * Called after all the {@link TypeInfo}s are collected into the governing {@link TypeInfoSet}. * * Derived class can do additional actions to complete the model. */ protected void link() { if(id==ID.IDREF) { // make sure that the refereced type has ID for (TypeInfo<T,C> ti : ref()) { if(!ti.canBeReferencedByIDREF()) parent.builder.reportError(new IllegalAnnotationException( Messages.INVALID_IDREF.format( parent.builder.nav.getTypeName(ti.getType())), this )); } } }
/** * Examine the specified element ref and determine if a swaRef attribute needs to be generated * @param typeRef */ private boolean generateSwaRefAdapter(NonElementRef<T,C> typeRef) { return generateSwaRefAdapter(typeRef.getSource()); }
/** * return the string representation of the processContents mode of the * give wildcard, or null if it is the schema default "strict" * */ private static String getProcessContentsModeName(WildcardMode wc) { switch(wc) { case LAX: case SKIP: return wc.name().toLowerCase(); case STRICT: return null; default: throw new IllegalStateException(); } }
/** * Examine the specified element ref and determine if a swaRef attribute needs to be generated */ private boolean generateSwaRefAdapter(PropertyInfo<T,C> prop) { final Adapter<T,C> adapter = prop.getAdapter(); if (adapter == null) return false; final Object o = navigator.asDecl(SwaRefAdapter.class); if (o == null) return false; return (o.equals(adapter.adapterType)); }
private boolean addGenericElement(ElementInfo<T,C> ei) { if(ei==null) return false; types.add(ei); for( ElementInfo<T,C> subst : ei.getSubstitutionMembers() ) addGenericElement(subst); return true; }
public PropertyInfo<T,C> getProperty(String name) { for( PropertyInfo<T,C> p: getProperties() ) { if(p.getName().equals(name)) return p; } return null; }
public final boolean isSimpleType() { List<? extends PropertyInfo> props = getProperties(); if(props.size()!=1) return false; return props.get(0).kind()==PropertyKind.VALUE; }
/** * A {@link ClassInfo} can be referenced by {@link XmlIDREF} if * it has an ID property. */ public boolean canBeReferencedByIDREF() { for (PropertyInfo<T,C> p : getProperties()) { if(p.id()== ID.ID) return true; } ClassInfoImpl<T,C,F,M> base = getBaseClass(); if(base!=null) return base.canBeReferencedByIDREF(); else return false; }
/** * Creates a {@link RuntimeTypeInfoSet}. */ public RuntimeTypeInfoSet getTypeInfoSet() throws IllegalAnnotationsException { // check cache if(typeInfoSetCache!=null) { RuntimeTypeInfoSet r = typeInfoSetCache.get(); if(r!=null) return r; } final RuntimeModelBuilder builder = new RuntimeModelBuilder(this,annotationReader,subclassReplacements,defaultNsUri); IllegalAnnotationsException.Builder errorHandler = new IllegalAnnotationsException.Builder(); builder.setErrorHandler(errorHandler); for( Class c : classes ) { if(c==CompositeStructure.class) // CompositeStructure doesn't have TypeInfo, so skip it. // We'll add JaxBeanInfo for this later automatically continue; builder.getTypeInfo(new Ref<Type,Class>(c)); } this.hasSwaRef |= builder.hasSwaRef; RuntimeTypeInfoSet r = builder.link(); errorHandler.check(); assert r!=null : "if no error was reported, the link must be a success"; typeInfoSetCache = new WeakReference<RuntimeTypeInfoSet>(r); return r; }
/** * Checks the uniqueness of the type name. */ private void addTypeName(NonElement<T, C> r) { QName t = r.getTypeName(); if(t==null) return; TypeInfo old = typeNames.put(t,r); if(old!=null) { // collision reportError(new IllegalAnnotationException( Messages.CONFLICTING_XML_TYPE_MAPPING.format(r.getTypeName()), old, r )); } }