com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationException Java Examples

The following examples show how to use com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SingleTypePropertyInfoImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
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
        ));
    }
}
 
Example #2
Source File: ElementInfoImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #3
Source File: ElementInfoImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #4
Source File: Util.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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;
    }
}
 
Example #5
Source File: SingleTypePropertyInfoImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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
        ));
    }
}
 
Example #6
Source File: ClassInfoImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Report errors for unused propOrder entries.
 */
public void checkUnusedProperties() {
    for( int i=0; i<used.length; i++ )
        if(used[i]==null) {
            String unusedName = propOrder[i];
            String nearest = EditDistance.findNearest(unusedName, new AbstractList<String>() {
                public String get(int index) {
                    return properties.get(index).getName();
                }

                public int size() {
                    return properties.size();
                }
            });
            boolean isOverriding = (i > (properties.size()-1)) ? false : properties.get(i).hasAnnotation(OverrideAnnotationOf.class);
            if (!isOverriding) {
                builder.reportError(new IllegalAnnotationException(
                Messages.PROPERTY_ORDER_CONTAINS_UNUSED_ENTRY.format(unusedName,nearest),ClassInfoImpl.this));
            }
        }
}
 
Example #7
Source File: TypeInfoSetImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @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 ));
    }
}
 
Example #8
Source File: SingleTypePropertyInfoImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
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
        ));
    }
}
 
Example #9
Source File: ClassInfoImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Called after all the {@link 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();
}
 
Example #10
Source File: Util.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
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;
    }
}
 
Example #11
Source File: RuntimeClassInfoImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@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 );
}
 
Example #12
Source File: AbstractInlineAnnotationReaderImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public final <A extends Annotation> A getMethodAnnotation(Class<A> annotation, M getter, M setter, Locatable srcPos) {
    A a1 = getter==null?null:getMethodAnnotation(annotation,getter,srcPos);
    A a2 = setter==null?null:getMethodAnnotation(annotation,setter,srcPos);

    if(a1==null) {
        if(a2==null)
            return null;
        else
            return a2;
    } else {
        if(a2==null)
            return a1;
        else {
            // both are present
            getErrorHandler().error(new IllegalAnnotationException(
                Messages.DUPLICATE_ANNOTATIONS.format(
                    annotation.getName(), fullName(getter),fullName(setter)),
                a1, a2 ));
            // recover by ignoring one of them
            return a1;
        }
    }
}
 
Example #13
Source File: ClassInfoImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Called after all the {@link 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();
}
 
Example #14
Source File: ClassInfoImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Report errors for unused propOrder entries.
 */
public void checkUnusedProperties() {
    for( int i=0; i<used.length; i++ )
        if(used[i]==null) {
            String unusedName = propOrder[i];
            String nearest = EditDistance.findNearest(unusedName, new AbstractList<String>() {
                public String get(int index) {
                    return properties.get(index).getName();
                }

                public int size() {
                    return properties.size();
                }
            });
            boolean isOverriding = (i > (properties.size()-1)) ? false : properties.get(i).hasAnnotation(OverrideAnnotationOf.class);
            if (!isOverriding) {
                builder.reportError(new IllegalAnnotationException(
                Messages.PROPERTY_ORDER_CONTAINS_UNUSED_ENTRY.format(unusedName,nearest),ClassInfoImpl.this));
            }
        }
}
 
Example #15
Source File: ClassInfoImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Called after all the {@link 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();
}
 
Example #16
Source File: ClassInfoImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Report errors for unused propOrder entries.
 */
public void checkUnusedProperties() {
    for( int i=0; i<used.length; i++ )
        if(used[i]==null) {
            String unusedName = propOrder[i];
            String nearest = EditDistance.findNearest(unusedName, new AbstractList<String>() {
                public String get(int index) {
                    return properties.get(index).getName();
                }

                public int size() {
                    return properties.size();
                }
            });
            boolean isOverriding = (i > (properties.size()-1)) ? false : properties.get(i).hasAnnotation(OverrideAnnotationOf.class);
            if (!isOverriding) {
                builder.reportError(new IllegalAnnotationException(
                Messages.PROPERTY_ORDER_CONTAINS_UNUSED_ENTRY.format(unusedName,nearest),ClassInfoImpl.this));
            }
        }
}
 
Example #17
Source File: AbstractInlineAnnotationReaderImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public final <A extends Annotation> A getMethodAnnotation(Class<A> annotation, M getter, M setter, Locatable srcPos) {
    A a1 = getter==null?null:getMethodAnnotation(annotation,getter,srcPos);
    A a2 = setter==null?null:getMethodAnnotation(annotation,setter,srcPos);

    if(a1==null) {
        if(a2==null)
            return null;
        else
            return a2;
    } else {
        if(a2==null)
            return a1;
        else {
            // both are present
            getErrorHandler().error(new IllegalAnnotationException(
                Messages.DUPLICATE_ANNOTATIONS.format(
                    annotation.getName(), fullName(getter),fullName(setter)),
                a1, a2 ));
            // recover by ignoring one of them
            return a1;
        }
    }
}
 
Example #18
Source File: TypeInfoSetImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @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 ));
    }
}
 
Example #19
Source File: ElementInfoImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #20
Source File: TypeInfoSetImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @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 ));
    }
}
 
Example #21
Source File: RuntimeClassInfoImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@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 );
}
 
Example #22
Source File: Util.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
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;
    }
}
 
Example #23
Source File: RuntimeElementInfoImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public RuntimeElementInfoImpl(RuntimeModelBuilder modelBuilder, RegistryInfoImpl registry, Method method) throws IllegalAnnotationException {
    super(modelBuilder, registry, method);

    Adapter<Type,Class> a = getProperty().getAdapter();

    if(a!=null)
        adapterType = a.adapterType;
    else
        adapterType = null;
}
 
Example #24
Source File: RuntimeClassInfoImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@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 );
}
 
Example #25
Source File: ClassInfoImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private int checkedGet(PropertyInfoImpl p) {
    Integer i = get(p.getName());
    if(i==null) {
        // missing
        if (p.kind().isOrdered)
            builder.reportError(new IllegalAnnotationException(
                Messages.PROPERTY_MISSING_FROM_ORDER.format(p.getName()),p));

        // give it an order to recover from an error
        i = size();
        put(p.getName(),i);
    }

    // mark the used field
    int ii = i;
    if(ii<used.length) {
        if(used[ii]!=null && used[ii]!=p) {
            if(collidedNames==null) collidedNames = new HashSet<String>();

            if(collidedNames.add(p.getName()))
                // report the error only on the first time
                builder.reportError(new IllegalAnnotationException(
                    Messages.DUPLICATE_PROPERTIES.format(p.getName()),p,used[ii]));
        }
        used[ii] = p;
    }

    return i;
}
 
Example #26
Source File: ClassInfoImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
PropertySorter() {
    super(propOrder.length);
    for( String name : propOrder )
        if(put(name,size())!=null) {
            // two properties with the same name
            builder.reportError(new IllegalAnnotationException(
                Messages.DUPLICATE_ENTRY_IN_PROP_ORDER.format(name),ClassInfoImpl.this));
        }
}
 
Example #27
Source File: ClassInfoImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
        }
    }
}
 
Example #28
Source File: PropertyInfoImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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;
    }
}
 
Example #29
Source File: ModelBuilder.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 ));
    }
}
 
Example #30
Source File: ClassInfoImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
        }
    }
}