java类javax.xml.bind.annotation.XmlAccessorType的实例源码

ClassInfoImpl.java 文件源码 项目:OpenJSharp 阅读 27 收藏 0 点赞 0 评论 0
/**
 * 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;
}
WebServiceWrapperGenerator.java 文件源码 项目:OpenJSharp 阅读 30 收藏 0 点赞 0 评论 0
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);
    }
WebServiceWrapperGenerator.java 文件源码 项目:openjdk-jdk10 阅读 33 收藏 0 点赞 0 评论 0
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);
    }
ClassInfoImpl.java 文件源码 项目:openjdk-jdk10 阅读 25 收藏 0 点赞 0 评论 0
/**
 * 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;
}
WebServiceWrapperGenerator.java 文件源码 项目:openjdk9 阅读 23 收藏 0 点赞 0 评论 0
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);
    }
ClassInfoImpl.java 文件源码 项目:openjdk9 阅读 36 收藏 0 点赞 0 评论 0
/**
 * 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;
}
ClassInfoImpl.java 文件源码 项目:lookaside_java-1.8.0-openjdk 阅读 19 收藏 0 点赞 0 评论 0
/**
 * 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;
}
WebServiceWrapperGenerator.java 文件源码 项目:lookaside_java-1.8.0-openjdk 阅读 25 收藏 0 点赞 0 评论 0
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);
    }
ImmutableJaxbGenerator.java 文件源码 项目:kc-rice 阅读 18 收藏 0 点赞 0 评论 0
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"));
}
JavaTypeAnalyzer.java 文件源码 项目:jaxrs-analyzer 阅读 27 收藏 0 点赞 0 评论 0
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;
}
ClassInfoImpl.java 文件源码 项目:infobip-open-jdk-8 阅读 22 收藏 0 点赞 0 评论 0
/**
 * 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;
}
WebServiceWrapperGenerator.java 文件源码 项目:infobip-open-jdk-8 阅读 21 收藏 0 点赞 0 评论 0
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);
    }
ClassInfoImpl.java 文件源码 项目:cxf-plus 阅读 28 收藏 0 点赞 0 评论 0
/**
 * 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;
}
ClassInfoImpl.java 文件源码 项目:OLD-OpenJDK8 阅读 31 收藏 0 点赞 0 评论 0
/**
 * 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;
}
WebServiceWrapperGenerator.java 文件源码 项目:OLD-OpenJDK8 阅读 25 收藏 0 点赞 0 评论 0
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);
    }
ImmutableJaxbGenerator.java 文件源码 项目:rice 阅读 22 收藏 0 点赞 0 评论 0
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"));
}
ClassInfoImpl.java 文件源码 项目:openjdk-icedtea7 阅读 27 收藏 0 点赞 0 评论 0
/**
 * 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;
}
ImmutableJaxbGenerator.java 文件源码 项目:kuali_rice 阅读 21 收藏 0 点赞 0 评论 0
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"));
}
ModelSanityCheckerTest.java 文件源码 项目:Camel 阅读 24 收藏 0 点赞 0 评论 0
private Set<Class<?>> discoverJaxbClasses() {
    PackageScanClassResolver resolver = new DefaultPackageScanClassResolver();
    String[] packages = Constants.JAXB_CONTEXT_PACKAGES.split(":");
    return resolver.findAnnotated(XmlAccessorType.class, packages);
}
JAXBEncoderDecoder.java 文件源码 项目:cxf-plus 阅读 30 收藏 0 点赞 0 评论 0
public static void marshallException(Marshaller marshaller, Exception elValue,
                                     MessagePartInfo part, Object source) {
    XMLStreamWriter writer = getStreamWriter(source);
    QName qn = part.getElementQName();
    try {
        writer.writeStartElement("ns1", qn.getLocalPart(), qn.getNamespaceURI());
        Class<?> cls = part.getTypeClass();
        XmlAccessorType accessorType = cls.getAnnotation(XmlAccessorType.class);
        if (accessorType == null && cls.getPackage() != null) {
            accessorType = cls.getPackage().getAnnotation(XmlAccessorType.class);
        }
        XmlAccessType accessType = accessorType != null
            ? accessorType.value() : XmlAccessType.PUBLIC_MEMBER;
        String namespace = part.getElementQName().getNamespaceURI();

        SchemaInfo sch = part.getMessageInfo().getOperation().getInterface()
            .getService().getSchema(namespace);
        if (sch != null) {
            if (!sch.isElementFormQualified()) {
                namespace = null;
            }
        } else {
            LOG.warning("Schema associated with " + namespace + " is null");
        }

        for (Field f : cls.getDeclaredFields()) {
            if (JAXBContextInitializer.isFieldAccepted(f, accessType)) {
                QName fname = new QName(namespace, f.getName());
                f.setAccessible(true);
                if (JAXBSchemaInitializer.isArray(f.getGenericType())) {
                    writeArrayObject(marshaller, writer, fname, f.get(elValue));                        
                } else {
                    writeObject(marshaller, writer, new JAXBElement(fname, String.class, 
                                                                    f.get(elValue)));
                }
            }
        }
        for (Method m : cls.getMethods()) {
            if (JAXBContextInitializer.isMethodAccepted(m, accessType)) {
                int idx = m.getName().startsWith("get") ? 3 : 2;
                String name = m.getName().substring(idx);
                name = Character.toLowerCase(name.charAt(0)) + name.substring(1);
                QName mname = new QName(namespace, name);
                if (JAXBSchemaInitializer.isArray(m.getGenericReturnType())) {
                    writeArrayObject(marshaller, writer, mname, m.invoke(elValue));
                } else {
                    writeObject(marshaller, writer, new JAXBElement(mname, String.class, 
                                                                    m.invoke(elValue)));
                }
            }
        }

        writer.writeEndElement();
        writer.flush();
    } catch (Exception e) {
        throw new Fault(new Message("MARSHAL_ERROR", LOG, e.getMessage()), e);
    }
}
DateModuleResultXmlTest.java 文件源码 项目:kalibro 阅读 19 收藏 0 点赞 0 评论 0
@Test
public void shouldHaveClassAnnotations() {
    Class<DateModuleResultXml> xmlClass = DateModuleResultXml.class;
    assertEquals("dateModuleResult", xmlClass.getAnnotation(XmlRootElement.class).name());
    assertEquals(XmlAccessType.FIELD, xmlClass.getAnnotation(XmlAccessorType.class).value());
}
DateMetricResultXmlTest.java 文件源码 项目:kalibro 阅读 18 收藏 0 点赞 0 评论 0
@Test
public void shouldHaveClassAnnotations() {
    Class<DateMetricResultXml> xmlClass = DateMetricResultXml.class;
    assertEquals("dateMetricResult", xmlClass.getAnnotation(XmlRootElement.class).name());
    assertEquals(XmlAccessType.FIELD, xmlClass.getAnnotation(XmlAccessorType.class).value());
}
ProcessTimeXmlTest.java 文件源码 项目:kalibro 阅读 21 收藏 0 点赞 0 评论 0
@Test
public void shouldHaveClassAnnotations() {
    Class<ProcessTimeXml> xmlClass = ProcessTimeXml.class;
    assertEquals("stateTime", xmlClass.getAnnotation(XmlRootElement.class).name());
    assertEquals(XmlAccessType.FIELD, xmlClass.getAnnotation(XmlAccessorType.class).value());
}
XmlTest.java 文件源码 项目:kalibro 阅读 21 收藏 0 点赞 0 评论 0
@Test
public void shouldHaveFieldXmlAccess() throws ClassNotFoundException {
    XmlAccessorType accessorType = dtoClass().getAnnotation(XmlAccessorType.class);
    assertNotNull(accessorType);
    assertEquals(XmlAccessType.FIELD, accessorType.value());
}


问题


面经


文章

微信
公众号

扫码关注公众号