Refine search
/** * 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 )); } }
public void link() { super.link(); if (!(NonElement.ANYTYPE_NAME.equals(type.getTypeName()) || type.isSimpleType() || id()==ID.IDREF)) { parent.builder.reportError(new IllegalAnnotationException( Messages.SIMPLE_TYPE_IS_REQUIRED.format(), seed )); } if(!isCollection() && seed.hasAnnotation(XmlList.class)) { parent.builder.reportError(new IllegalAnnotationException( Messages.XMLLIST_ON_SINGLE_PROPERTY.format(), this )); } }
/** * Makes sure that the method doesn't have any annotation, if it does, * report it as an error */ private void ensureNoAnnotation(M method) { Annotation[] annotations = reader().getAllMethodAnnotations(method,this); for( Annotation a : annotations ) { if(isJAXBAnnotation(a)) { builder.reportError(new IllegalAnnotationException( Messages.ANNOTATION_ON_WRONG_METHOD.format(), a)); return; } } }
/** * @param builder * used for reporting errors. */ public final void add( ElementInfoImpl<T,C,F,M> ei, ModelBuilder<T,C,F,M> builder ) { C scope = null; if(ei.getScope()!=null) scope = ei.getScope().getClazz(); Map<QName,ElementInfoImpl<T,C,F,M>> m = elementMappings.get(scope); if(m==null) elementMappings.put(scope,m=new LinkedHashMap<QName,ElementInfoImpl<T,C,F,M>>()); ElementInfoImpl<T,C,F,M> existing = m.put(ei.getElementName(),ei); if(existing!=null) { QName en = ei.getElementName(); builder.reportError( new IllegalAnnotationException( Messages.CONFLICTING_XML_ELEMENT_MAPPING.format(en.getNamespaceURI(),en.getLocalPart()), ei, existing )); } }
/** * Called after all the {@link TypeInfo}s are collected into the {@link #owner}. */ /*package*/ void link() { // substitution head if(anno.substitutionHeadName().length()!=0) { QName name = new QName( anno.substitutionHeadNamespace(), anno.substitutionHeadName() ); substitutionHead = owner.getElementInfo(null,name); if(substitutionHead==null) { builder.reportError( new IllegalAnnotationException(Messages.NON_EXISTENT_ELEMENT_MAPPING.format( name.getNamespaceURI(),name.getLocalPart()), anno)); // recover by ignoring this substitution declaration } else substitutionHead.addSubstitutionMember(this); } else substitutionHead = null; super.link(); }
accFactory = factoryAnn.value().newInstance(); } catch (InstantiationException e) { builder.reportError(new IllegalAnnotationException( Messages.ACCESSORFACTORY_INSTANTIATION_EXCEPTION.format( factoryAnn.getClass().getName(), nav().getClassName(clazz)), this)); } catch (IllegalAccessException e) { builder.reportError(new IllegalAnnotationException( Messages.ACCESSORFACTORY_ACCESS_EXCEPTION.format( factoryAnn.getClass().getName(), nav().getClassName(clazz)),this));
/** * 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 )); } } }
@Override public RuntimeEnumConstantImpl createEnumConstant(String name, String literal, Field constant, EnumConstantImpl<Type,Class,Field,Method> last) { T t; try { try { constant.setAccessible(true); } catch (SecurityException e) { // in case the constant is already accessible, swallow this error. // if the constant is indeed not accessible, we will get IllegalAccessException // in the following line, and that is not too late. } t = (T)constant.get(null); } catch (IllegalAccessException e) { // impossible, because this is an enum constant throw new IllegalAccessError(e.getMessage()); } B b = null; try { b = baseXducer.parse(literal); } catch (Exception e) { builder.reportError(new IllegalAnnotationException( Messages.INVALID_XML_ENUM_VALUE.format(literal,baseType.getType().toString()), e, new FieldLocatable<Field>(this,constant,nav()) )); } parseMap.put(b,t); printMap.put(t,b); return new RuntimeEnumConstantImpl(this, name, literal, last); }
/** * Called after all the {@link com.sun.xml.bind.v2.model.core.TypeInfo}s are collected into the {@link #owner}. */ @Override /*package*/ void link() { getProperties(); // make sure properties!=null // property name collision cehck Map<String,PropertyInfoImpl> names = new HashMap<String,PropertyInfoImpl>(); for( PropertyInfoImpl<T,C,F,M> p : properties ) { p.link(); PropertyInfoImpl old = names.put(p.getName(),p); if(old!=null) { builder.reportError(new IllegalAnnotationException( Messages.PROPERTY_COLLISION.format(p.getName()), p, old )); } } super.link(); }
static MimeType calcExpectedMediaType(AnnotationSource primarySource, ModelBuilder builder ) { XmlMimeType xmt = primarySource.readAnnotation(XmlMimeType.class); if(xmt==null) return null; try { return new MimeType(xmt.value()); } catch (MimeTypeParseException e) { builder.reportError(new IllegalAnnotationException( Messages.ILLEGAL_MIME_TYPE.format(xmt.value(),e.getMessage()), xmt )); return null; } } }
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); }
if(vp!=null) { builder.reportError(new IllegalAnnotationException( Messages.MULTIPLE_VALUE_PROPERTY.format(), vp, p )); builder.reportError(new IllegalAnnotationException( Messages.XMLVALUE_IN_DERIVED_TYPE.format(), p )); builder.reportError(new IllegalAnnotationException( Messages.ELEMENT_AND_VALUE_PROPERTY.format(), vp, ep ));
@Override protected RuntimePropertySeed createFieldSeed(Field field) { final boolean readOnly = Modifier.isStatic(field.getModifiers()); Accessor acc; try { if (supressAccessorWarnings) { acc = ((InternalAccessorFactory)accessorFactory).createFieldAccessor(clazz, field, readOnly, supressAccessorWarnings); } else { acc = accessorFactory.createFieldAccessor(clazz, field, readOnly); } } catch(JAXBException e) { builder.reportError(new IllegalAnnotationException( Messages.CUSTOM_ACCESSORFACTORY_FIELD_ERROR.format( nav().getClassName(clazz), e.toString()), this )); acc = Accessor.getErrorInstance(); // error recovery } return new RuntimePropertySeed(super.createFieldSeed(field), acc ); }
@Override public RuntimePropertySeed createAccessorSeed(Method getter, Method setter) { Accessor acc; try { acc = accessorFactory.createPropertyAccessor(clazz, getter, setter); } catch(JAXBException e) { builder.reportError(new IllegalAnnotationException( Messages.CUSTOM_ACCESSORFACTORY_PROPERTY_ERROR.format( nav().getClassName(clazz), e.toString()), this )); acc = Accessor.getErrorInstance(); // error recovery } return new RuntimePropertySeed( super.createAccessorSeed(getter,setter), acc ); }
private ID calcId() { if(seed.hasAnnotation(XmlID.class)) { // check the type if(!nav().isSameType(getIndividualType(), nav().ref(String.class))) parent.builder.reportError(new IllegalAnnotationException( Messages.ID_MUST_BE_STRING.format(getName()), seed ) ); return ID.ID; } else if(seed.hasAnnotation(XmlIDREF.class)) { return ID.IDREF; } else { return ID.NONE; } }
builder.reportError(new IllegalAnnotationException( Messages.MISSING_JAXB_PROPERTIES.format(getPackageName()), this )); ei = builder.createElementInfo(this,m); } catch (IllegalAnnotationException e) { builder.reportError(e); continue; // recover by ignoring this element
protected void link() { super.link(); for (TypeRefImpl<TypeT, ClassDeclT> ref : getTypes() ) { ref.link(); } if(isValueList()) { // ugly test, because IDREF's are represented as text on the wire, // it's OK to be a value list in that case. if(id()!= ID.IDREF) { // check if all the item types are simple types // this can't be done when we compute types because // not all TypeInfos are available yet for (TypeRefImpl<TypeT,ClassDeclT> ref : types) { if(!ref.getTarget().isSimpleType()) { parent.builder.reportError(new IllegalAnnotationException( Messages.XMLLIST_NEEDS_SIMPLETYPE.format( nav().getTypeName(ref.getTarget().getType())), this )); break; } } } if(!isCollection()) parent.builder.reportError(new IllegalAnnotationException( Messages.XMLLIST_ON_SINGLE_PROPERTY.format(), this )); } } }
public ERPropertyInfoImpl(ClassInfoImpl<TypeT, ClassDeclT, FieldT, MethodT> classInfo, PropertySeed<TypeT, ClassDeclT, FieldT, MethodT> propertySeed) { super(classInfo, propertySeed); XmlElementWrapper e = seed.readAnnotation(XmlElementWrapper.class); boolean nil = false; boolean required = false; if(!isCollection()) { xmlName = null; if(e!=null) classInfo.builder.reportError(new IllegalAnnotationException( Messages.XML_ELEMENT_WRAPPER_ON_NON_COLLECTION.format( nav().getClassName(parent.getClazz())+'.'+seed.getName()), e )); } else { if(e!=null) { xmlName = calcXmlName(e); nil = e.nillable(); required = e.required(); } else xmlName = null; } wrapperNillable = nil; wrapperRequired = required; }
builder.reportError(new IllegalAnnotationException( Messages.CANT_HANDLE_INTERFACE.format(nav().getClassName(clazz)), this )); if(!nav().hasDefaultConstructor(clazz)){ if(nav().isInnerClass(clazz)) { builder.reportError(new IllegalAnnotationException( Messages.CANT_HANDLE_INNER_CLASS.format(nav().getClassName(clazz)), this )); } else if (elementName != null) { builder.reportError(new IllegalAnnotationException( Messages.NO_DEFAULT_CONSTRUCTOR.format(nav().getClassName(clazz)), this ));
parent.builder.reportError(new IllegalAnnotationException( Messages.MUTUALLY_EXCLUSIVE_ANNOTATIONS.format( nav().getClassName(parent.getClazz())+'#'+seed.getName(), ref.annotationType().getName(), refs.annotationType().getName()), parent.builder.reportError(new IllegalAnnotationException( Messages.NO_XML_ELEMENT_DECL.format( getEffectiveNamespaceFor(r), r.name()), this )); } else { parent.builder.reportError(new IllegalAnnotationException( Messages.INVALID_XML_ELEMENT_REF.format(type),this)); parent.builder.reportError(new IllegalAnnotationException( Messages.MUTUALLY_EXCLUSIVE_ANNOTATIONS.format( nav().getClassName(parent.getClazz())+'#'+seed.getName(), parent.builder.reportError(new IllegalAnnotationException( Messages.NO_XML_ELEMENT_DECL.format( getEffectiveNamespaceFor(r), r.name()), )); } else { parent.builder.reportError(new IllegalAnnotationException( Messages.INVALID_XML_ELEMENT_REF.format(),this));