javax.xml.bind.annotation.XmlNs Java Examples

The following examples show how to use javax.xml.bind.annotation.XmlNs. 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: TypeInfoSetImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public Map<String,String> getXmlNs(String namespaceUri) {
    if(xmlNsCache==null) {
        xmlNsCache = new HashMap<String,Map<String,String>>();

        for (ClassInfoImpl<T, C, F, M> ci : beans().values()) {
            XmlSchema xs = reader.getPackageAnnotation( XmlSchema.class, ci.getClazz(), null );
            if(xs==null)
                continue;

            String uri = xs.namespace();
            Map<String,String> m = xmlNsCache.get(uri);
            if(m==null)
                xmlNsCache.put(uri,m=new HashMap<String, String>());

            for( XmlNs xns : xs.xmlns() ) {
                m.put(xns.prefix(),xns.namespaceURI());
            }
        }
    }

    Map<String,String> r = xmlNsCache.get(namespaceUri);
    if(r!=null)     return r;
    else            return Collections.emptyMap();
}
 
Example #2
Source File: XmlTypeUtils.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private static String getPrefix(final Package targetPackage,
		String namespaceURI) {
	String prefix;
	final Map<String, String> namespacePrefixes = new HashMap<String, String>();
	if (targetPackage != null) {
		final XmlSchema xmlSchemaAnnotation = targetPackage
				.getAnnotation(XmlSchema.class);
		if (xmlSchemaAnnotation != null) {
			for (XmlNs xmlns : xmlSchemaAnnotation.xmlns()) {
				namespacePrefixes.put(xmlns.namespaceURI(), xmlns.prefix());
			}
		}
	}

	prefix = namespacePrefixes.get(namespaceURI);
	return prefix;
}
 
Example #3
Source File: TypeInfoSetImpl.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public Map<String,String> getXmlNs(String namespaceUri) {
    if(xmlNsCache==null) {
        xmlNsCache = new HashMap<String,Map<String,String>>();

        for (ClassInfoImpl<T, C, F, M> ci : beans().values()) {
            XmlSchema xs = reader.getPackageAnnotation( XmlSchema.class, ci.getClazz(), null );
            if(xs==null)
                continue;

            String uri = xs.namespace();
            Map<String,String> m = xmlNsCache.get(uri);
            if(m==null)
                xmlNsCache.put(uri,m=new HashMap<String, String>());

            for( XmlNs xns : xs.xmlns() ) {
                m.put(xns.prefix(),xns.namespaceURI());
            }
        }
    }

    Map<String,String> r = xmlNsCache.get(namespaceUri);
    if(r!=null)     return r;
    else            return Collections.emptyMap();
}
 
Example #4
Source File: TypeInfoSetImpl.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public Map<String,String> getXmlNs(String namespaceUri) {
    if(xmlNsCache==null) {
        xmlNsCache = new HashMap<String,Map<String,String>>();

        for (ClassInfoImpl<T, C, F, M> ci : beans().values()) {
            XmlSchema xs = reader.getPackageAnnotation( XmlSchema.class, ci.getClazz(), null );
            if(xs==null)
                continue;

            String uri = xs.namespace();
            Map<String,String> m = xmlNsCache.get(uri);
            if(m==null)
                xmlNsCache.put(uri,m=new HashMap<String, String>());

            for( XmlNs xns : xs.xmlns() ) {
                m.put(xns.prefix(),xns.namespaceURI());
            }
        }
    }

    Map<String,String> r = xmlNsCache.get(namespaceUri);
    if(r!=null)     return r;
    else            return Collections.emptyMap();
}
 
Example #5
Source File: TypeInfoSetImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public Map<String,String> getXmlNs(String namespaceUri) {
    if(xmlNsCache==null) {
        xmlNsCache = new HashMap<String,Map<String,String>>();

        for (ClassInfoImpl<T, C, F, M> ci : beans().values()) {
            XmlSchema xs = reader.getPackageAnnotation( XmlSchema.class, ci.getClazz(), null );
            if(xs==null)
                continue;

            String uri = xs.namespace();
            Map<String,String> m = xmlNsCache.get(uri);
            if(m==null)
                xmlNsCache.put(uri,m=new HashMap<String, String>());

            for( XmlNs xns : xs.xmlns() ) {
                m.put(xns.prefix(),xns.namespaceURI());
            }
        }
    }

    Map<String,String> r = xmlNsCache.get(namespaceUri);
    if(r!=null)     return r;
    else            return Collections.emptyMap();
}
 
Example #6
Source File: TypeInfoSetImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public Map<String,String> getXmlNs(String namespaceUri) {
    if(xmlNsCache==null) {
        xmlNsCache = new HashMap<String,Map<String,String>>();

        for (ClassInfoImpl<T, C, F, M> ci : beans().values()) {
            XmlSchema xs = reader.getPackageAnnotation( XmlSchema.class, ci.getClazz(), null );
            if(xs==null)
                continue;

            String uri = xs.namespace();
            Map<String,String> m = xmlNsCache.get(uri);
            if(m==null)
                xmlNsCache.put(uri,m=new HashMap<String, String>());

            for( XmlNs xns : xs.xmlns() ) {
                m.put(xns.prefix(),xns.namespaceURI());
            }
        }
    }

    Map<String,String> r = xmlNsCache.get(namespaceUri);
    if(r!=null)     return r;
    else            return Collections.emptyMap();
}
 
Example #7
Source File: TypeInfoSetImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public Map<String,String> getXmlNs(String namespaceUri) {
    if(xmlNsCache==null) {
        xmlNsCache = new HashMap<String,Map<String,String>>();

        for (ClassInfoImpl<T, C, F, M> ci : beans().values()) {
            XmlSchema xs = reader.getPackageAnnotation( XmlSchema.class, ci.getClazz(), null );
            if(xs==null)
                continue;

            String uri = xs.namespace();
            Map<String,String> m = xmlNsCache.get(uri);
            if(m==null)
                xmlNsCache.put(uri,m=new HashMap<String, String>());

            for( XmlNs xns : xs.xmlns() ) {
                m.put(xns.prefix(),xns.namespaceURI());
            }
        }
    }

    Map<String,String> r = xmlNsCache.get(namespaceUri);
    if(r!=null)     return r;
    else            return Collections.emptyMap();
}
 
Example #8
Source File: TypeInfoSetImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public Map<String,String> getXmlNs(String namespaceUri) {
    if(xmlNsCache==null) {
        xmlNsCache = new HashMap<String,Map<String,String>>();

        for (ClassInfoImpl<T, C, F, M> ci : beans().values()) {
            XmlSchema xs = reader.getPackageAnnotation( XmlSchema.class, ci.getClazz(), null );
            if(xs==null)
                continue;

            String uri = xs.namespace();
            Map<String,String> m = xmlNsCache.get(uri);
            if(m==null)
                xmlNsCache.put(uri,m=new HashMap<String, String>());

            for( XmlNs xns : xs.xmlns() ) {
                m.put(xns.prefix(),xns.namespaceURI());
            }
        }
    }

    Map<String,String> r = xmlNsCache.get(namespaceUri);
    if(r!=null)     return r;
    else            return Collections.emptyMap();
}
 
Example #9
Source File: TypeInfoSetImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public Map<String,String> getXmlNs(String namespaceUri) {
    if(xmlNsCache==null) {
        xmlNsCache = new HashMap<String,Map<String,String>>();

        for (ClassInfoImpl<T, C, F, M> ci : beans().values()) {
            XmlSchema xs = reader.getPackageAnnotation( XmlSchema.class, ci.getClazz(), null );
            if(xs==null)
                continue;

            String uri = xs.namespace();
            Map<String,String> m = xmlNsCache.get(uri);
            if(m==null)
                xmlNsCache.put(uri,m=new HashMap<String, String>());

            for( XmlNs xns : xs.xmlns() ) {
                m.put(xns.prefix(),xns.namespaceURI());
            }
        }
    }

    Map<String,String> r = xmlNsCache.get(namespaceUri);
    if(r!=null)     return r;
    else            return Collections.emptyMap();
}
 
Example #10
Source File: AnnotationConsistencyCheck.java    From sis with Apache License 2.0 4 votes vote down vote up
/**
 * Replaces {@value #DEFAULT} value by the {@link XmlSchema} namespace if needed,
 * then performs validity check on the resulting namespace. This method checks that:
 *
 * <ul>
 *   <li>The namespace is not redundant with the package-level {@link XmlSchema} namespace.</li>
 *   <li>The namespace is declared in a package-level {@link XmlNs} annotation.</li>
 *   <li>The namespace starts with the {@linkplain #getExpectedNamespaceStart expected namespace}.</li>
 * </ul>
 *
 * @param  namespace  the namespace given by the {@code @XmlRootElement} or {@code @XmlElement} annotation.
 * @param  impl       the implementation or wrapper class from which to get the package namespace.
 * @param  uml        the {@code @UML} annotation, or {@code null} if none.
 * @return the actual namespace (same as {@code namespace} if it was not {@value #DEFAULT}).
 */
private String assertExpectedNamespace(String namespace, final Class<?> impl, final UML uml) {
    assertNotNull("Missing namespace.", namespace);
    assertFalse("Missing namespace.", namespace.trim().isEmpty());
    /*
     * Get the namespace declared at the package level, and ensure the the
     * given namespace is not redundant with that package-level namespace.
     */
    final XmlSchema schema = impl.getPackage().getAnnotation(XmlSchema.class);
    assertNotNull("Missing @XmlSchema annotation in package-info.", schema);
    final String schemaNamespace = schema.namespace();      // May be XMLConstants.NULL_NS_URI
    assertFalse("Namespace declaration is redundant with package-info @XmlSchema.", namespace.equals(schemaNamespace));
    /*
     * Resolve the namespace given in argument: using the class-level namespace if needed,
     * or the package-level namespace if the class-level one is not defined.
     */
    if (DEFAULT.equals(namespace)) {
        final XmlType type = impl.getAnnotation(XmlType.class);
        if (type == null || DEFAULT.equals(namespace = type.namespace())) {
            namespace = schemaNamespace;
        }
        assertFalse("No namespace defined.", XMLConstants.NULL_NS_URI.equals(namespace));
    }
    /*
     * Check that the namespace is declared in the package-level @XmlNs annotation.
     * We do not verify the validity of those @XmlNs annotations, since this is the
     * purpose of the 'testPackageAnnotations()' method.
     */
    boolean found = false;
    for (final XmlNs ns : schema.xmlns()) {
        if (namespace.equals(ns.namespaceURI())) {
            found = true;
            break;
        }
    }
    if (!found) {
        fail("Namespace for " + impl + " is not declared in the package @XmlSchema.xmlns().");
    }
    /*
     * Check that the namespace is one of the namespaces controlled by the specification.
     * We check only the namespace start, since some specifications define many namespaces
     * under a common root (e.g. "http://standards.iso.org/iso/19115/-3/").
     */
    if (uml != null && false) {     // This verification is available only on development branches.
        final String expected = getExpectedNamespaceStart(impl, uml);
        if (!namespace.startsWith(expected)) {
            fail("Expected " + expected + "… namespace for that ISO specification but got " + namespace);
        }
    }
    return namespace;
}
 
Example #11
Source File: XmlSchemaQuick.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public XmlNs[] xmlns() {
    return core.xmlns();
}
 
Example #12
Source File: XmlSchemaQuick.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public XmlNs[] xmlns() {
    return core.xmlns();
}
 
Example #13
Source File: XmlSchemaQuick.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public XmlNs[] xmlns() {
    return core.xmlns();
}
 
Example #14
Source File: XmlSchemaQuick.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public XmlNs[] xmlns() {
    return core.xmlns();
}
 
Example #15
Source File: XmlSchemaQuick.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public XmlNs[] xmlns() {
    return core.xmlns();
}
 
Example #16
Source File: XmlSchemaQuick.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public XmlNs[] xmlns() {
    return core.xmlns();
}
 
Example #17
Source File: XmlSchemaQuick.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public XmlNs[] xmlns() {
    return core.xmlns();
}
 
Example #18
Source File: XmlSchemaQuick.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public XmlNs[] xmlns() {
    return core.xmlns();
}
 
Example #19
Source File: JAXBContextImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns declared XmlNs annotations (from package-level annotation XmlSchema
 *
 * @return set of all present XmlNs annotations
 */
public Set<XmlNs> getXmlNsSet() {
    return xmlNsSet;
}
 
Example #20
Source File: JAXBContextImpl.java    From jdk8u60 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns declared XmlNs annotations (from package-level annotation XmlSchema
 *
 * @return set of all present XmlNs annotations
 */
public Set<XmlNs> getXmlNsSet() {
    return xmlNsSet;
}
 
Example #21
Source File: JAXBContextImpl.java    From hottub with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns declared XmlNs annotations (from package-level annotation XmlSchema
 *
 * @return set of all present XmlNs annotations
 */
public Set<XmlNs> getXmlNsSet() {
    return xmlNsSet;
}
 
Example #22
Source File: JAXBContextImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns declared XmlNs annotations (from package-level annotation XmlSchema
 *
 * @return set of all present XmlNs annotations
 */
public Set<XmlNs> getXmlNsSet() {
    return xmlNsSet;
}
 
Example #23
Source File: JAXBContextImpl.java    From openjdk-8-source with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns declared XmlNs annotations (from package-level annotation XmlSchema
 *
 * @return set of all present XmlNs annotations
 */
public Set<XmlNs> getXmlNsSet() {
    return xmlNsSet;
}
 
Example #24
Source File: JAXBContextImpl.java    From TencentKona-8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns declared XmlNs annotations (from package-level annotation XmlSchema
 *
 * @return set of all present XmlNs annotations
 */
public Set<XmlNs> getXmlNsSet() {
    return xmlNsSet;
}
 
Example #25
Source File: JAXBContextImpl.java    From openjdk-8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns declared XmlNs annotations (from package-level annotation XmlSchema
 *
 * @return set of all present XmlNs annotations
 */
public Set<XmlNs> getXmlNsSet() {
    return xmlNsSet;
}
 
Example #26
Source File: JAXBContextImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns declared XmlNs annotations (from package-level annotation XmlSchema
 *
 * @return set of all present XmlNs annotations
 */
public Set<XmlNs> getXmlNsSet() {
    return xmlNsSet;
}