下面列出了怎么用javax.xml.bind.annotation.XmlNs的API类实例代码及写法,或者点击链接到github查看源代码。
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();
}
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();
}
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();
}
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();
}
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();
}
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();
}
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();
}
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();
}
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;
}
public XmlNs[] xmlns() {
return core.xmlns();
}
public XmlNs[] xmlns() {
return core.xmlns();
}
public XmlNs[] xmlns() {
return core.xmlns();
}
public XmlNs[] xmlns() {
return core.xmlns();
}
public XmlNs[] xmlns() {
return core.xmlns();
}
public XmlNs[] xmlns() {
return core.xmlns();
}
public XmlNs[] xmlns() {
return core.xmlns();
}
public XmlNs[] xmlns() {
return core.xmlns();
}
/**
* 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;
}
/**
* Returns declared XmlNs annotations (from package-level annotation XmlSchema
*
* @return set of all present XmlNs annotations
*/
public Set<XmlNs> getXmlNsSet() {
return xmlNsSet;
}
/**
* Returns declared XmlNs annotations (from package-level annotation XmlSchema
*
* @return set of all present XmlNs annotations
*/
public Set<XmlNs> getXmlNsSet() {
return xmlNsSet;
}
/**
* Returns declared XmlNs annotations (from package-level annotation XmlSchema
*
* @return set of all present XmlNs annotations
*/
public Set<XmlNs> getXmlNsSet() {
return xmlNsSet;
}
/**
* Returns declared XmlNs annotations (from package-level annotation XmlSchema
*
* @return set of all present XmlNs annotations
*/
public Set<XmlNs> getXmlNsSet() {
return xmlNsSet;
}
/**
* Returns declared XmlNs annotations (from package-level annotation XmlSchema
*
* @return set of all present XmlNs annotations
*/
public Set<XmlNs> getXmlNsSet() {
return xmlNsSet;
}
/**
* Returns declared XmlNs annotations (from package-level annotation XmlSchema
*
* @return set of all present XmlNs annotations
*/
public Set<XmlNs> getXmlNsSet() {
return xmlNsSet;
}
/**
* Returns declared XmlNs annotations (from package-level annotation XmlSchema
*
* @return set of all present XmlNs annotations
*/
public Set<XmlNs> getXmlNsSet() {
return xmlNsSet;
}
/**
* Returns declared XmlNs annotations (from package-level annotation XmlSchema
*
* @return set of all present XmlNs annotations
*/
public Set<XmlNs> getXmlNsSet() {
return xmlNsSet;
}