Java Code Examples for javax.xml.bind.annotation.XmlAccessType#FIELD
The following examples show how to use
javax.xml.bind.annotation.XmlAccessType#FIELD .
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: JavaTypeAnalyzer.java From jaxrs-analyzer with Apache License 2.0 | 6 votes |
private static boolean isRelevant(final Field field, final XmlAccessType accessType) { if (field.isSynthetic()) return false; if (hasIgnoreAnnotation(field) || isTypeIgnored(field.getType())) { ignoredFieldNames.add(field.getName()); return false; } if (isAnnotationPresent(field, XmlElement.class)) return true; final int modifiers = field.getModifiers(); if (accessType == XmlAccessType.FIELD) // always take, unless static or transient return !Modifier.isTransient(modifiers) && !Modifier.isStatic(modifiers) && !isAnnotationPresent(field, XmlTransient.class); else if (accessType == XmlAccessType.PUBLIC_MEMBER) // only for public, non-static return Modifier.isPublic(modifiers) && !Modifier.isStatic(modifiers) && !isAnnotationPresent(field, XmlTransient.class); return false; }
Example 2
Source File: Utils.java From cxf with Apache License 2.0 | 5 votes |
static boolean isMethodAccepted(Method method, XmlAccessType accessType, boolean acceptSetters) { // ignore bridge, static, @XmlTransient methods plus methods declared in Throwable if (method.isBridge() || Modifier.isStatic(method.getModifiers()) || method.isAnnotationPresent(XmlTransient.class) || method.getDeclaringClass().equals(Throwable.class) || "getClass".equals(method.getName())) { return false; } // Allow only public methods if PUBLIC_MEMBER access is requested if (accessType == XmlAccessType.PUBLIC_MEMBER && !Modifier.isPublic(method.getModifiers())) { return false; } if (isGetter(method)) { // does nothing } else if (isSetter(method)) { if (!acceptSetters) { return false; } } else { // we accept only getters and setters return false; } // let JAXB annotations decide if NONE or FIELD access is requested if (accessType == XmlAccessType.NONE || accessType == XmlAccessType.FIELD) { return JAXBContextInitializer.checkJaxbAnnotation(method.getAnnotations()); } // method accepted return true; }
Example 3
Source File: ClassInfoImpl.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
private void findFieldProperties(C c, XmlAccessType at) { // always find properties from the super class first C sc = nav().getSuperClass(c); if (shouldRecurseSuperClass(sc)) { findFieldProperties(sc,at); } for( F f : nav().getDeclaredFields(c) ) { Annotation[] annotations = reader().getAllFieldAnnotations(f,this); boolean isDummy = reader().hasFieldAnnotation(OverrideAnnotationOf.class, f); if( nav().isTransient(f) ) { // it's an error for transient field to have any binding annotation if(hasJAXBAnnotation(annotations)) builder.reportError(new IllegalAnnotationException( Messages.TRANSIENT_FIELD_NOT_BINDABLE.format(nav().getFieldName(f)), getSomeJAXBAnnotation(annotations))); } else if( nav().isStaticField(f) ) { // static fields are bound only when there's explicit annotation. if(hasJAXBAnnotation(annotations)) addProperty(createFieldSeed(f),annotations, false); } else { if(at==XmlAccessType.FIELD ||(at==XmlAccessType.PUBLIC_MEMBER && nav().isPublicField(f)) || hasJAXBAnnotation(annotations)) { if (isDummy) { ClassInfo<T, C> top = getBaseClass(); while ((top != null) && (top.getProperty("content") == null)) { top = top.getBaseClass(); } DummyPropertyInfo prop = (DummyPropertyInfo) top.getProperty("content"); PropertySeed seed = createFieldSeed(f); ((DummyPropertyInfo)prop).addType(createReferenceProperty(seed)); } else { addProperty(createFieldSeed(f), annotations, false); } } checkFieldXmlLocation(f); } } }
Example 4
Source File: ClassInfoImpl.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
private void findFieldProperties(C c, XmlAccessType at) { // always find properties from the super class first C sc = nav().getSuperClass(c); if (shouldRecurseSuperClass(sc)) { findFieldProperties(sc,at); } for( F f : nav().getDeclaredFields(c) ) { Annotation[] annotations = reader().getAllFieldAnnotations(f,this); boolean isDummy = reader().hasFieldAnnotation(OverrideAnnotationOf.class, f); if( nav().isTransient(f) ) { // it's an error for transient field to have any binding annotation if(hasJAXBAnnotation(annotations)) builder.reportError(new IllegalAnnotationException( Messages.TRANSIENT_FIELD_NOT_BINDABLE.format(nav().getFieldName(f)), getSomeJAXBAnnotation(annotations))); } else if( nav().isStaticField(f) ) { // static fields are bound only when there's explicit annotation. if(hasJAXBAnnotation(annotations)) addProperty(createFieldSeed(f),annotations, false); } else { if(at==XmlAccessType.FIELD ||(at==XmlAccessType.PUBLIC_MEMBER && nav().isPublicField(f)) || hasJAXBAnnotation(annotations)) { if (isDummy) { ClassInfo<T, C> top = getBaseClass(); while ((top != null) && (top.getProperty("content") == null)) { top = top.getBaseClass(); } DummyPropertyInfo prop = (DummyPropertyInfo) top.getProperty("content"); PropertySeed seed = createFieldSeed(f); ((DummyPropertyInfo)prop).addType(createReferenceProperty(seed)); } else { addProperty(createFieldSeed(f), annotations, false); } } checkFieldXmlLocation(f); } } }
Example 5
Source File: ClassInfoImpl.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
private void findFieldProperties(C c, XmlAccessType at) { // always find properties from the super class first C sc = nav().getSuperClass(c); if (shouldRecurseSuperClass(sc)) { findFieldProperties(sc,at); } for( F f : nav().getDeclaredFields(c) ) { Annotation[] annotations = reader().getAllFieldAnnotations(f,this); boolean isDummy = reader().hasFieldAnnotation(OverrideAnnotationOf.class, f); if( nav().isTransient(f) ) { // it's an error for transient field to have any binding annotation if(hasJAXBAnnotation(annotations)) builder.reportError(new IllegalAnnotationException( Messages.TRANSIENT_FIELD_NOT_BINDABLE.format(nav().getFieldName(f)), getSomeJAXBAnnotation(annotations))); } else if( nav().isStaticField(f) ) { // static fields are bound only when there's explicit annotation. if(hasJAXBAnnotation(annotations)) addProperty(createFieldSeed(f),annotations, false); } else { if(at==XmlAccessType.FIELD ||(at==XmlAccessType.PUBLIC_MEMBER && nav().isPublicField(f)) || hasJAXBAnnotation(annotations)) { if (isDummy) { ClassInfo<T, C> top = getBaseClass(); while ((top != null) && (top.getProperty("content") == null)) { top = top.getBaseClass(); } DummyPropertyInfo prop = (DummyPropertyInfo) top.getProperty("content"); PropertySeed seed = createFieldSeed(f); ((DummyPropertyInfo)prop).addType(createReferenceProperty(seed)); } else { addProperty(createFieldSeed(f), annotations, false); } } checkFieldXmlLocation(f); } } }
Example 6
Source File: ClassInfoImpl.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
private void findFieldProperties(C c, XmlAccessType at) { // always find properties from the super class first C sc = nav().getSuperClass(c); if (shouldRecurseSuperClass(sc)) { findFieldProperties(sc,at); } for( F f : nav().getDeclaredFields(c) ) { Annotation[] annotations = reader().getAllFieldAnnotations(f,this); boolean isDummy = reader().hasFieldAnnotation(OverrideAnnotationOf.class, f); if( nav().isTransient(f) ) { // it's an error for transient field to have any binding annotation if(hasJAXBAnnotation(annotations)) builder.reportError(new IllegalAnnotationException( Messages.TRANSIENT_FIELD_NOT_BINDABLE.format(nav().getFieldName(f)), getSomeJAXBAnnotation(annotations))); } else if( nav().isStaticField(f) ) { // static fields are bound only when there's explicit annotation. if(hasJAXBAnnotation(annotations)) addProperty(createFieldSeed(f),annotations, false); } else { if(at==XmlAccessType.FIELD ||(at==XmlAccessType.PUBLIC_MEMBER && nav().isPublicField(f)) || hasJAXBAnnotation(annotations)) { if (isDummy) { ClassInfo<T, C> top = getBaseClass(); while ((top != null) && (top.getProperty("content") == null)) { top = top.getBaseClass(); } DummyPropertyInfo prop = (DummyPropertyInfo) top.getProperty("content"); PropertySeed seed = createFieldSeed(f); ((DummyPropertyInfo)prop).addType(createReferenceProperty(seed)); } else { addProperty(createFieldSeed(f), annotations, false); } } checkFieldXmlLocation(f); } } }
Example 7
Source File: ClassInfoImpl.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private void findFieldProperties(C c, XmlAccessType at) { // always find properties from the super class first C sc = nav().getSuperClass(c); if (shouldRecurseSuperClass(sc)) { findFieldProperties(sc,at); } for( F f : nav().getDeclaredFields(c) ) { Annotation[] annotations = reader().getAllFieldAnnotations(f,this); boolean isDummy = reader().hasFieldAnnotation(OverrideAnnotationOf.class, f); if( nav().isTransient(f) ) { // it's an error for transient field to have any binding annotation if(hasJAXBAnnotation(annotations)) builder.reportError(new IllegalAnnotationException( Messages.TRANSIENT_FIELD_NOT_BINDABLE.format(nav().getFieldName(f)), getSomeJAXBAnnotation(annotations))); } else if( nav().isStaticField(f) ) { // static fields are bound only when there's explicit annotation. if(hasJAXBAnnotation(annotations)) addProperty(createFieldSeed(f),annotations, false); } else { if(at==XmlAccessType.FIELD ||(at==XmlAccessType.PUBLIC_MEMBER && nav().isPublicField(f)) || hasJAXBAnnotation(annotations)) { if (isDummy) { ClassInfo<T, C> top = getBaseClass(); while ((top != null) && (top.getProperty("content") == null)) { top = top.getBaseClass(); } DummyPropertyInfo prop = (DummyPropertyInfo) top.getProperty("content"); PropertySeed seed = createFieldSeed(f); ((DummyPropertyInfo)prop).addType(createReferenceProperty(seed)); } else { addProperty(createFieldSeed(f), annotations, false); } } checkFieldXmlLocation(f); } } }
Example 8
Source File: ClassInfoImpl.java From hottub with GNU General Public License v2.0 | 4 votes |
private void findFieldProperties(C c, XmlAccessType at) { // always find properties from the super class first C sc = nav().getSuperClass(c); if (shouldRecurseSuperClass(sc)) { findFieldProperties(sc,at); } for( F f : nav().getDeclaredFields(c) ) { Annotation[] annotations = reader().getAllFieldAnnotations(f,this); boolean isDummy = reader().hasFieldAnnotation(OverrideAnnotationOf.class, f); if( nav().isTransient(f) ) { // it's an error for transient field to have any binding annotation if(hasJAXBAnnotation(annotations)) builder.reportError(new IllegalAnnotationException( Messages.TRANSIENT_FIELD_NOT_BINDABLE.format(nav().getFieldName(f)), getSomeJAXBAnnotation(annotations))); } else if( nav().isStaticField(f) ) { // static fields are bound only when there's explicit annotation. if(hasJAXBAnnotation(annotations)) addProperty(createFieldSeed(f),annotations, false); } else { if(at==XmlAccessType.FIELD ||(at==XmlAccessType.PUBLIC_MEMBER && nav().isPublicField(f)) || hasJAXBAnnotation(annotations)) { if (isDummy) { ClassInfo<T, C> top = getBaseClass(); while ((top != null) && (top.getProperty("content") == null)) { top = top.getBaseClass(); } DummyPropertyInfo prop = (DummyPropertyInfo) top.getProperty("content"); PropertySeed seed = createFieldSeed(f); ((DummyPropertyInfo)prop).addType(createReferenceProperty(seed)); } else { addProperty(createFieldSeed(f), annotations, false); } } checkFieldXmlLocation(f); } } }
Example 9
Source File: ClassInfoImpl.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
private void findFieldProperties(C c, XmlAccessType at) { // always find properties from the super class first C sc = nav().getSuperClass(c); if (shouldRecurseSuperClass(sc)) { findFieldProperties(sc,at); } for( F f : nav().getDeclaredFields(c) ) { Annotation[] annotations = reader().getAllFieldAnnotations(f,this); boolean isDummy = reader().hasFieldAnnotation(OverrideAnnotationOf.class, f); if( nav().isTransient(f) ) { // it's an error for transient field to have any binding annotation if(hasJAXBAnnotation(annotations)) builder.reportError(new IllegalAnnotationException( Messages.TRANSIENT_FIELD_NOT_BINDABLE.format(nav().getFieldName(f)), getSomeJAXBAnnotation(annotations))); } else if( nav().isStaticField(f) ) { // static fields are bound only when there's explicit annotation. if(hasJAXBAnnotation(annotations)) addProperty(createFieldSeed(f),annotations, false); } else { if(at==XmlAccessType.FIELD ||(at==XmlAccessType.PUBLIC_MEMBER && nav().isPublicField(f)) || hasJAXBAnnotation(annotations)) { if (isDummy) { ClassInfo<T, C> top = getBaseClass(); while ((top != null) && (top.getProperty("content") == null)) { top = top.getBaseClass(); } DummyPropertyInfo prop = (DummyPropertyInfo) top.getProperty("content"); PropertySeed seed = createFieldSeed(f); ((DummyPropertyInfo)prop).addType(createReferenceProperty(seed)); } else { addProperty(createFieldSeed(f), annotations, false); } } checkFieldXmlLocation(f); } } }
Example 10
Source File: ClassInfoImpl.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
private void findFieldProperties(C c, XmlAccessType at) { // always find properties from the super class first C sc = nav().getSuperClass(c); if (shouldRecurseSuperClass(sc)) { findFieldProperties(sc,at); } for( F f : nav().getDeclaredFields(c) ) { Annotation[] annotations = reader().getAllFieldAnnotations(f,this); boolean isDummy = reader().hasFieldAnnotation(OverrideAnnotationOf.class, f); if( nav().isTransient(f) ) { // it's an error for transient field to have any binding annotation if(hasJAXBAnnotation(annotations)) builder.reportError(new IllegalAnnotationException( Messages.TRANSIENT_FIELD_NOT_BINDABLE.format(nav().getFieldName(f)), getSomeJAXBAnnotation(annotations))); } else if( nav().isStaticField(f) ) { // static fields are bound only when there's explicit annotation. if(hasJAXBAnnotation(annotations)) addProperty(createFieldSeed(f),annotations, false); } else { if(at==XmlAccessType.FIELD ||(at==XmlAccessType.PUBLIC_MEMBER && nav().isPublicField(f)) || hasJAXBAnnotation(annotations)) { if (isDummy) { ClassInfo<T, C> top = getBaseClass(); while ((top != null) && (top.getProperty("content") == null)) { top = top.getBaseClass(); } DummyPropertyInfo prop = (DummyPropertyInfo) top.getProperty("content"); PropertySeed seed = createFieldSeed(f); ((DummyPropertyInfo)prop).addType(createReferenceProperty(seed)); } else { addProperty(createFieldSeed(f), annotations, false); } } checkFieldXmlLocation(f); } } }
Example 11
Source File: JAXBContextInitializer.java From cxf with Apache License 2.0 | 4 votes |
/** * Checks if the method is accepted as a JAXB property getter. */ static boolean isMethodAccepted(Method method, XmlAccessType accessType) { // We only accept non static property getters which are not marked @XmlTransient if (Modifier.isStatic(method.getModifiers()) || method.isAnnotationPresent(XmlTransient.class) || !Modifier.isPublic(method.getModifiers()) || "getClass".equals(method.getName())) { return false; } // must not have parameters and return type must not be void if (method.getReturnType() == Void.class || method.getReturnType() == Void.TYPE || method.getParameterTypes().length != 0 || (method.getDeclaringClass().equals(Throwable.class) && !("getMessage".equals(method.getName()))) || !(method.getName().startsWith("get") || method.getName().startsWith("is"))) { return false; } int beginIndex = 3; if (method.getName().startsWith("is")) { beginIndex = 2; } Method setter = null; try { setter = method.getDeclaringClass() .getMethod("set" + method.getName().substring(beginIndex), new Class[] {method.getReturnType()}); } catch (Exception e) { //getter, but no setter } if (setter != null) { if (setter.isAnnotationPresent(XmlTransient.class) || !Modifier.isPublic(setter.getModifiers())) { return false; } } else if (!Collection.class.isAssignableFrom(method.getReturnType()) && !Throwable.class.isAssignableFrom(method.getDeclaringClass())) { //no setter, it's not a collection (thus getter().add(...)), and //not an Exception, return false; } if (accessType == XmlAccessType.NONE || accessType == XmlAccessType.FIELD) { return checkJaxbAnnotation(method.getAnnotations()); } return true; }