javax.xml.bind.annotation.XmlAccessorType Java Examples

The following examples show how to use javax.xml.bind.annotation.XmlAccessorType. 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: JaxbUnionExtensionTest.java    From raml-java-tools with Apache License 2.0 6 votes vote down vote up
@Test
public void implementationClassCreated() {

    JaxbUnionExtension jaxb = new JaxbUnionExtension();
    TypeSpec.Builder classBuilder = TypeSpec.classBuilder("my.BuiltClass");

    TypeSpec.Builder builder = jaxb.classCreated(null, unionTypeDeclaration, classBuilder, EventType.IMPLEMENTATION);
    TypeSpec buildClass = builder.build();

    TypeSpecAssert.assertThat(buildClass)
            .hasName("my.BuiltClass");

    AnnotationSpecAssert.assertThat(buildClass.annotations.get(0)).hasType(ClassName.get(XmlAccessorType.class));
    assertEquals("javax.xml.bind.annotation.XmlAccessType.FIELD", builder.build().annotations.get(0).members.get("value").get(0).toString());

    AnnotationSpecAssert.assertThat(buildClass.annotations.get(1)).hasType(ClassName.get(XmlRootElement.class));
    assertEquals("null", builder.build().annotations.get(1).members.get("name").get(0).toString());
    assertEquals("\"##default\"", builder.build().annotations.get(1).members.get("namespace").get(0).toString());
}
 
Example #2
Source File: ClassInfoImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Computes the {@link XmlAccessType} on this class by looking at {@link XmlAccessorType}
 * annotations.
 */
private XmlAccessType getAccessType() {
    XmlAccessorType xat = getClassOrPackageAnnotation(XmlAccessorType.class);
    if(xat!=null)
        return xat.value();
    else
        return XmlAccessType.PUBLIC_MEMBER;
}
 
Example #3
Source File: Utils.java    From cxf with Apache License 2.0 5 votes vote down vote up
static XmlAccessType getXmlAccessType(Class<?> cls) {
    XmlAccessorType accessorType = cls.getAnnotation(XmlAccessorType.class);
    if (accessorType == null && cls.getPackage() != null) {
        accessorType = cls.getPackage().getAnnotation(XmlAccessorType.class);
    }
    return accessorType != null
        ? accessorType.value() : XmlAccessType.PUBLIC_MEMBER;
}
 
Example #4
Source File: ImmutableJaxbGenerator.java    From rice with Educational Community License v2.0 5 votes vote down vote up
private void renderClassLevelAnnotations(JDefinedClass classModel, List<FieldModel> fields) throws Exception {
	JFieldRef constantsClass = classModel.staticRef(Util.CONSTANTS_CLASS_NAME);
	JFieldRef elementsClass = classModel.staticRef(Util.ELEMENTS_CLASS_NAME);
	JClass coreConstants = codeModel.ref(CoreConstants.class);
	JFieldRef commonElementsRef = coreConstants.staticRef("CommonElements");
	
	// XmlRootElement
	JAnnotationUse rootElementAnnotation = classModel.annotate(XmlRootElement.class);
	rootElementAnnotation.param("name", constantsClass.ref(Util.ROOT_ELEMENT_NAME_FIELD));
	
	// XmlAccessorType
	JAnnotationUse xmlAccessorTypeAnnotation = classModel.annotate(XmlAccessorType.class);
	xmlAccessorTypeAnnotation.param("value", XmlAccessType.NONE);
	
	// XmlType
	JAnnotationUse xmlTypeAnnotation = classModel.annotate(XmlType.class);
	xmlTypeAnnotation.param("name", constantsClass.ref(Util.TYPE_NAME_FIELD));
	JAnnotationArrayMember propOrderMember = xmlTypeAnnotation.paramArray("propOrder");
	for (FieldModel field : fields) {
		if (Util.isCommonElement(field.fieldName)) {
			propOrderMember.param(commonElementsRef.ref(Util.toConstantsVariable(field.fieldName)));
		} else {
			propOrderMember.param(elementsClass.ref(Util.toConstantsVariable(field.fieldName)));
		}
	}
	propOrderMember.param(commonElementsRef.ref("FUTURE_ELEMENTS"));
}
 
Example #5
Source File: JavaTypeAnalyzer.java    From jaxrs-analyzer with Apache License 2.0 5 votes vote down vote up
private XmlAccessType getXmlAccessType(final Class<?> clazz) {
    Class<?> current = clazz;

    while (current != null) {
        if (isAnnotationPresent(current, XmlAccessorType.class))
            return getAnnotation(current, XmlAccessorType.class).value();
        current = current.getSuperclass();
    }

    return XmlAccessType.PUBLIC_MEMBER;
}
 
Example #6
Source File: WebServiceWrapperGenerator.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private void writeXmlElementDeclaration(JDefinedClass cls, String elementName, String namespaceUri) {

       if (cls == null)
            return;
        JAnnotationUse xmlRootElementAnn = cls.annotate(XmlRootElement.class);
        xmlRootElementAnn.param("name", elementName);
        if (namespaceUri.length() > 0) {
            xmlRootElementAnn.param("namespace", namespaceUri);
        }
        JAnnotationUse xmlAccessorTypeAnn = cls.annotate(cm.ref(XmlAccessorType.class));
        xmlAccessorTypeAnn.param("value", XmlAccessType.FIELD);
    }
 
Example #7
Source File: ClassInfoImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Computes the {@link XmlAccessType} on this class by looking at {@link XmlAccessorType}
 * annotations.
 */
private XmlAccessType getAccessType() {
    XmlAccessorType xat = getClassOrPackageAnnotation(XmlAccessorType.class);
    if(xat!=null)
        return xat.value();
    else
        return XmlAccessType.PUBLIC_MEMBER;
}
 
Example #8
Source File: WebServiceWrapperGenerator.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private void writeXmlElementDeclaration(JDefinedClass cls, String elementName, String namespaceUri) {

       if (cls == null)
            return;
        JAnnotationUse xmlRootElementAnn = cls.annotate(XmlRootElement.class);
        xmlRootElementAnn.param("name", elementName);
        if (namespaceUri.length() > 0) {
            xmlRootElementAnn.param("namespace", namespaceUri);
        }
        JAnnotationUse xmlAccessorTypeAnn = cls.annotate(cm.ref(XmlAccessorType.class));
        xmlAccessorTypeAnn.param("value", XmlAccessType.FIELD);
    }
 
Example #9
Source File: ClassInfoImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Computes the {@link XmlAccessType} on this class by looking at {@link XmlAccessorType}
 * annotations.
 */
private XmlAccessType getAccessType() {
    XmlAccessorType xat = getClassOrPackageAnnotation(XmlAccessorType.class);
    if(xat!=null)
        return xat.value();
    else
        return XmlAccessType.PUBLIC_MEMBER;
}
 
Example #10
Source File: WebServiceWrapperGenerator.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void writeXmlElementDeclaration(JDefinedClass cls, String elementName, String namespaceUri) {

       if (cls == null)
            return;
        JAnnotationUse xmlRootElementAnn = cls.annotate(XmlRootElement.class);
        xmlRootElementAnn.param("name", elementName);
        if (namespaceUri.length() > 0) {
            xmlRootElementAnn.param("namespace", namespaceUri);
        }
        JAnnotationUse xmlAccessorTypeAnn = cls.annotate(cm.ref(XmlAccessorType.class));
        xmlAccessorTypeAnn.param("value", XmlAccessType.FIELD);
    }
 
Example #11
Source File: ClassInfoImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Computes the {@link XmlAccessType} on this class by looking at {@link XmlAccessorType}
 * annotations.
 */
private XmlAccessType getAccessType() {
    XmlAccessorType xat = getClassOrPackageAnnotation(XmlAccessorType.class);
    if(xat!=null)
        return xat.value();
    else
        return XmlAccessType.PUBLIC_MEMBER;
}
 
Example #12
Source File: ClassInfoImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Computes the {@link XmlAccessType} on this class by looking at {@link XmlAccessorType}
 * annotations.
 */
private XmlAccessType getAccessType() {
    XmlAccessorType xat = getClassOrPackageAnnotation(XmlAccessorType.class);
    if(xat!=null)
        return xat.value();
    else
        return XmlAccessType.PUBLIC_MEMBER;
}
 
Example #13
Source File: WebServiceWrapperGenerator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void writeXmlElementDeclaration(JDefinedClass cls, String elementName, String namespaceUri) {

       if (cls == null)
            return;
        JAnnotationUse xmlRootElementAnn = cls.annotate(XmlRootElement.class);
        xmlRootElementAnn.param("name", elementName);
        if (namespaceUri.length() > 0) {
            xmlRootElementAnn.param("namespace", namespaceUri);
        }
        JAnnotationUse xmlAccessorTypeAnn = cls.annotate(cm.ref(XmlAccessorType.class));
        xmlAccessorTypeAnn.param("value", XmlAccessType.FIELD);
    }
 
Example #14
Source File: WebServiceWrapperGenerator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private void writeXmlElementDeclaration(JDefinedClass cls, String elementName, String namespaceUri) {

       if (cls == null)
            return;
        JAnnotationUse xmlRootElementAnn = cls.annotate(XmlRootElement.class);
        xmlRootElementAnn.param("name", elementName);
        if (namespaceUri.length() > 0) {
            xmlRootElementAnn.param("namespace", namespaceUri);
        }
        JAnnotationUse xmlAccessorTypeAnn = cls.annotate(cm.ref(XmlAccessorType.class));
        xmlAccessorTypeAnn.param("value", XmlAccessType.FIELD);
    }
 
Example #15
Source File: ClassInfoImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Computes the {@link XmlAccessType} on this class by looking at {@link XmlAccessorType}
 * annotations.
 */
private XmlAccessType getAccessType() {
    XmlAccessorType xat = getClassOrPackageAnnotation(XmlAccessorType.class);
    if(xat!=null)
        return xat.value();
    else
        return XmlAccessType.PUBLIC_MEMBER;
}
 
Example #16
Source File: WebServiceWrapperGenerator.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void writeXmlElementDeclaration(JDefinedClass cls, String elementName, String namespaceUri) {

       if (cls == null)
            return;
        JAnnotationUse xmlRootElementAnn = cls.annotate(XmlRootElement.class);
        xmlRootElementAnn.param("name", elementName);
        if (namespaceUri.length() > 0) {
            xmlRootElementAnn.param("namespace", namespaceUri);
        }
        JAnnotationUse xmlAccessorTypeAnn = cls.annotate(cm.ref(XmlAccessorType.class));
        xmlAccessorTypeAnn.param("value", XmlAccessType.FIELD);
    }
 
Example #17
Source File: ClassInfoImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Computes the {@link XmlAccessType} on this class by looking at {@link XmlAccessorType}
 * annotations.
 */
private XmlAccessType getAccessType() {
    XmlAccessorType xat = getClassOrPackageAnnotation(XmlAccessorType.class);
    if(xat!=null)
        return xat.value();
    else
        return XmlAccessType.PUBLIC_MEMBER;
}
 
Example #18
Source File: WebServiceWrapperGenerator.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private void writeXmlElementDeclaration(JDefinedClass cls, String elementName, String namespaceUri) {

       if (cls == null)
            return;
        JAnnotationUse xmlRootElementAnn = cls.annotate(XmlRootElement.class);
        xmlRootElementAnn.param("name", elementName);
        if (namespaceUri.length() > 0) {
            xmlRootElementAnn.param("namespace", namespaceUri);
        }
        JAnnotationUse xmlAccessorTypeAnn = cls.annotate(cm.ref(XmlAccessorType.class));
        xmlAccessorTypeAnn.param("value", XmlAccessType.FIELD);
    }
 
Example #19
Source File: ClassInfoImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Computes the {@link XmlAccessType} on this class by looking at {@link XmlAccessorType}
 * annotations.
 */
private XmlAccessType getAccessType() {
    XmlAccessorType xat = getClassOrPackageAnnotation(XmlAccessorType.class);
    if(xat!=null)
        return xat.value();
    else
        return XmlAccessType.PUBLIC_MEMBER;
}
 
Example #20
Source File: WebServiceWrapperGenerator.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void writeXmlElementDeclaration(JDefinedClass cls, String elementName, String namespaceUri) {

       if (cls == null)
            return;
        JAnnotationUse xmlRootElementAnn = cls.annotate(XmlRootElement.class);
        xmlRootElementAnn.param("name", elementName);
        if (namespaceUri.length() > 0) {
            xmlRootElementAnn.param("namespace", namespaceUri);
        }
        JAnnotationUse xmlAccessorTypeAnn = cls.annotate(cm.ref(XmlAccessorType.class));
        xmlAccessorTypeAnn.param("value", XmlAccessType.FIELD);
    }
 
Example #21
Source File: WrapperBeanAnnotator.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void annotate(final JavaAnnotatable clz) {
    WrapperBeanClass beanClass = null;
    if (clz instanceof WrapperBeanClass) {
        beanClass = (WrapperBeanClass) clz;
    } else {
        throw new RuntimeException("WrapperBeanAnnotator expect JavaClass as input");
    }

    JAnnotation xmlRootElement = new JAnnotation(XmlRootElement.class);
    xmlRootElement.addElement(new JAnnotationElement("name",
                                                     beanClass.getElementName().getLocalPart()));
    xmlRootElement.addElement(new JAnnotationElement("namespace",
                                                     beanClass.getElementName().getNamespaceURI()));

    JAnnotation xmlAccessorType = new JAnnotation(XmlAccessorType.class);
    xmlAccessorType.addElement(new JAnnotationElement(null, XmlAccessType.FIELD));

    XmlType tp = null;
    if (sourceClass != null) {
        tp = sourceClass.getAnnotation(XmlType.class);
    }
    JAnnotation xmlType = new JAnnotation(XmlType.class);
    if (tp == null) {
        xmlType.addElement(new JAnnotationElement("name",
                                              beanClass.getElementName().getLocalPart()));
        xmlType.addElement(new JAnnotationElement("namespace",
                                              beanClass.getElementName().getNamespaceURI()));
    } else {
        if (!"##default".equals(tp.name())) {
            xmlType.addElement(new JAnnotationElement("name",
                                                      tp.name()));
        }
        if (!"##default".equals(tp.namespace())) {
            xmlType.addElement(new JAnnotationElement("namespace",
                                                      tp.namespace()));
        }
        if (!StringUtils.isEmpty(tp.factoryMethod())) {
            xmlType.addElement(new JAnnotationElement("factoryMethod",
                                                      tp.factoryMethod()));
        }
        if (tp.propOrder().length != 1
            || !StringUtils.isEmpty(tp.propOrder()[0])) {
            xmlType.addElement(new JAnnotationElement("propOrder",
                                                  tp.propOrder()));
        }

    }
    List<String> props = new ArrayList<>();
    for (JavaField f : beanClass.getFields()) {
        props.add(f.getParaName());
    }
    if (props.size() > 1) {
        xmlType.addElement(new JAnnotationElement("propOrder",
                                                  props));
    }

    // Revisit: why annotation is string?
    beanClass.addAnnotation(xmlRootElement);
    beanClass.addAnnotation(xmlAccessorType);
    beanClass.addAnnotation(xmlType);
}