Search in sources :

Example 1 with XmlSchema

use of javax.xml.bind.annotation.XmlSchema in project platformlayer by platformlayer.

the class XmlHelper method getXmlElementInfo.

public static ElementInfo getXmlElementInfo(Class<?> clazz) {
    String elementName = null;
    String namespace = null;
    XmlType xmlType = clazz.getAnnotation(XmlType.class);
    if (xmlType != null) {
        elementName = xmlType.name();
        namespace = xmlType.namespace();
    } else {
        XmlRootElement xmlRootElement = clazz.getAnnotation(XmlRootElement.class);
        if (xmlRootElement != null) {
            elementName = xmlRootElement.name();
            namespace = xmlRootElement.namespace();
        }
    }
    if ("##default".equals(elementName)) {
        elementName = StringUtils.uncapitalize(clazz.getSimpleName());
    }
    if ("##default".equals(namespace)) {
        namespace = null;
    }
    if (namespace == null) {
        Package itemPackage = clazz.getPackage();
        XmlSchema xmlSchema = itemPackage.getAnnotation(XmlSchema.class);
        if (xmlSchema != null) {
            namespace = getXmlNamespace(xmlSchema);
        }
    }
    if (elementName != null && namespace != null) {
        return new ElementInfo(namespace, elementName);
    }
    return null;
}
Also used : XmlRootElement(javax.xml.bind.annotation.XmlRootElement) XmlSchema(javax.xml.bind.annotation.XmlSchema) XmlType(javax.xml.bind.annotation.XmlType)

Example 2 with XmlSchema

use of javax.xml.bind.annotation.XmlSchema in project midpoint by Evolveum.

the class PrismBeanInspector method determineNamespaceUncached.

private String determineNamespaceUncached(Class<? extends Object> beanClass) {
    XmlType xmlType = beanClass.getAnnotation(XmlType.class);
    if (xmlType == null) {
        return null;
    }
    String namespace = xmlType.namespace();
    if (BeanMarshaller.DEFAULT_PLACEHOLDER.equals(namespace)) {
        XmlSchema xmlSchema = beanClass.getPackage().getAnnotation(XmlSchema.class);
        namespace = xmlSchema.namespace();
    }
    if (StringUtils.isBlank(namespace) || BeanMarshaller.DEFAULT_PLACEHOLDER.equals(namespace)) {
        return null;
    }
    return namespace;
}
Also used : XmlSchema(javax.xml.bind.annotation.XmlSchema) XmlType(javax.xml.bind.annotation.XmlType)

Example 3 with XmlSchema

use of javax.xml.bind.annotation.XmlSchema in project midpoint by Evolveum.

the class PrismBeanInspector method determineTypeForClassUncached.

private QName determineTypeForClassUncached(Class<? extends Object> beanClass) {
    XmlType xmlType = beanClass.getAnnotation(XmlType.class);
    if (xmlType == null) {
        return null;
    }
    String namespace = xmlType.namespace();
    if (BeanMarshaller.DEFAULT_PLACEHOLDER.equals(namespace)) {
        XmlSchema xmlSchema = beanClass.getPackage().getAnnotation(XmlSchema.class);
        namespace = xmlSchema.namespace();
    }
    if (StringUtils.isBlank(namespace) || BeanMarshaller.DEFAULT_PLACEHOLDER.equals(namespace)) {
        return null;
    }
    return new QName(namespace, xmlType.name());
}
Also used : XmlSchema(javax.xml.bind.annotation.XmlSchema) QName(javax.xml.namespace.QName) XmlType(javax.xml.bind.annotation.XmlType)

Example 4 with XmlSchema

use of javax.xml.bind.annotation.XmlSchema in project zm-mailbox by Zimbra.

the class WsdlDocGenerator method getNamespace.

private static String getNamespace(Class<?> jaxbClass, Map<Package, String> pkgToNamespace) {
    Package pkg = jaxbClass.getPackage();
    String namespace = pkgToNamespace.get(pkg);
    if (namespace == null) {
        XmlSchema schemaAnnot = pkg.getAnnotation(XmlSchema.class);
        if (schemaAnnot != null) {
            namespace = schemaAnnot.namespace();
            // XmlNs[] xmlns = schemaAnnot.xmlns();  Useful if we need prefix for namespace
            pkgToNamespace.put(pkg, namespace);
        }
    }
    return namespace;
}
Also used : XmlSchema(javax.xml.bind.annotation.XmlSchema)

Example 5 with XmlSchema

use of javax.xml.bind.annotation.XmlSchema in project zm-mailbox by Zimbra.

the class JaxbInfo method getQName.

private org.dom4j.QName getQName(JaxbNodeInfo elemNode) {
    String elemNs = elemNode.getNamespace();
    if (DEFAULT_MARKER.equals(elemNs)) {
        XmlSchema xmlSchemaAnnot = jaxbClass.getPackage().getAnnotation(XmlSchema.class);
        elemNs = XmlNsForm.QUALIFIED.equals(xmlSchemaAnnot.elementFormDefault()) ? xmlSchemaAnnot.namespace() : "";
    }
    org.dom4j.Namespace dom4jNS = new org.dom4j.Namespace("", elemNs);
    return new org.dom4j.QName(elemNode.getName(), dom4jNS);
}
Also used : XmlSchema(javax.xml.bind.annotation.XmlSchema)

Aggregations

XmlSchema (javax.xml.bind.annotation.XmlSchema)11 XmlType (javax.xml.bind.annotation.XmlType)6 XmlRootElement (javax.xml.bind.annotation.XmlRootElement)5 QName (javax.xml.namespace.QName)5 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Source (javax.xml.transform.Source)1 SAXSource (javax.xml.transform.sax.SAXSource)1 StreamSource (javax.xml.transform.stream.StreamSource)1 Schema (javax.xml.validation.Schema)1 SchemaFactory (javax.xml.validation.SchemaFactory)1 InputSource (org.xml.sax.InputSource)1 SAXException (org.xml.sax.SAXException)1