下面列出了怎么用javax.xml.bind.annotation.XmlSchema的API类实例代码及写法,或者点击链接到github查看源代码。
protected final void initConfiguration(JaxWsImplementorInfo ii) {
if (ii.isWebServiceProvider()) {
jaxWsConfiguration = new WebServiceProviderConfiguration();
jaxWsConfiguration.setServiceFactory(this);
getServiceConfigurations().add(0, jaxWsConfiguration);
setWrapped(false);
setDataBinding(new SourceDataBinding());
setMethodDispatcher(new JAXWSProviderMethodDispatcher(implInfo));
} else {
jaxWsConfiguration = new JaxWsServiceConfiguration();
jaxWsConfiguration.setServiceFactory(this);
getServiceConfigurations().add(0, jaxWsConfiguration);
Class<?> seiClass = ii.getEndpointClass();
if (seiClass != null && seiClass.getPackage() != null) {
XmlSchema schema = seiClass.getPackage().getAnnotation(XmlSchema.class);
if (schema != null && XmlNsForm.QUALIFIED.equals(schema.elementFormDefault())) {
setQualifyWrapperSchema(true);
}
}
setMethodDispatcher(new JAXWSMethodDispatcher(implInfo));
}
loadWSFeatureAnnotation(ii.getSEIClass(), ii.getImplementorClass());
}
final QName parseElementName(XmlElementDecl e) {
String local = e.name();
String nsUri = e.namespace();
if(nsUri.equals("##default")) {
// if defaulted ...
XmlSchema xs = reader().getPackageAnnotation(XmlSchema.class,
nav().getDeclaringClassForMethod(method),this);
if(xs!=null)
nsUri = xs.namespace();
else {
nsUri = builder.defaultNsUri;
}
}
return new QName(nsUri.intern(),local.intern());
}
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;
}
private static String getNamespace(final Package targetPackage) {
String namespaceURI;
if (targetPackage == null) {
namespaceURI = "";
} else {
final XmlSchema xmlSchemaAnnotation = targetPackage
.getAnnotation(XmlSchema.class);
if (xmlSchemaAnnotation == null) {
namespaceURI = "";
} else {
final String packageNamespace = xmlSchemaAnnotation.namespace();
if (packageNamespace == null || "".equals(packageNamespace)) {
namespaceURI = "";
} else {
namespaceURI = packageNamespace;
}
}
}
return namespaceURI;
}
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();
}
/**
* Parses an {@link XmlRootElement} annotation on a class
* and determine the element name.
*
* @return null
* if none was found.
*/
protected final QName parseElementName(ClassDeclT clazz) {
XmlRootElement e = reader().getClassAnnotation(XmlRootElement.class,clazz,this);
if(e==null)
return null;
String local = e.name();
if(local.equals("##default")) {
// if defaulted...
local = NameConverter.standard.toVariableName(nav().getClassShortName(clazz));
}
String nsUri = e.namespace();
if(nsUri.equals("##default")) {
// if defaulted ...
XmlSchema xs = reader().getPackageAnnotation(XmlSchema.class,clazz,this);
if(xs!=null)
nsUri = xs.namespace();
else {
nsUri = builder.defaultNsUri;
}
}
return new QName(nsUri.intern(),local.intern());
}
/**
* Parses an {@link XmlRootElement} annotation on a class
* and determine the element name.
*
* @return null
* if none was found.
*/
protected final QName parseElementName(ClassDeclT clazz) {
XmlRootElement e = reader().getClassAnnotation(XmlRootElement.class,clazz,this);
if(e==null)
return null;
String local = e.name();
if(local.equals("##default")) {
// if defaulted...
local = NameConverter.standard.toVariableName(nav().getClassShortName(clazz));
}
String nsUri = e.namespace();
if(nsUri.equals("##default")) {
// if defaulted ...
XmlSchema xs = reader().getPackageAnnotation(XmlSchema.class,clazz,this);
if(xs!=null)
nsUri = xs.namespace();
else {
nsUri = builder.defaultNsUri;
}
}
return new QName(nsUri.intern(),local.intern());
}
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();
}
final QName parseElementName(XmlElementDecl e) {
String local = e.name();
String nsUri = e.namespace();
if(nsUri.equals("##default")) {
// if defaulted ...
XmlSchema xs = reader().getPackageAnnotation(XmlSchema.class,
nav().getDeclaringClassForMethod(method),this);
if(xs!=null)
nsUri = xs.namespace();
else {
nsUri = builder.defaultNsUri;
}
}
return new QName(nsUri.intern(),local.intern());
}
final QName parseElementName(XmlElementDecl e) {
String local = e.name();
String nsUri = e.namespace();
if(nsUri.equals("##default")) {
// if defaulted ...
XmlSchema xs = reader().getPackageAnnotation(XmlSchema.class,
nav().getDeclaringClassForMethod(method),this);
if(xs!=null)
nsUri = xs.namespace();
else {
nsUri = builder.defaultNsUri;
}
}
return new QName(nsUri.intern(),local.intern());
}
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();
}
/**
* Parses an {@link XmlRootElement} annotation on a class
* and determine the element name.
*
* @return null
* if none was found.
*/
protected final QName parseElementName(ClassDeclT clazz) {
XmlRootElement e = reader().getClassAnnotation(XmlRootElement.class,clazz,this);
if(e==null)
return null;
String local = e.name();
if(local.equals("##default")) {
// if defaulted...
local = NameConverter.standard.toVariableName(nav().getClassShortName(clazz));
}
String nsUri = e.namespace();
if(nsUri.equals("##default")) {
// if defaulted ...
XmlSchema xs = reader().getPackageAnnotation(XmlSchema.class,clazz,this);
if(xs!=null)
nsUri = xs.namespace();
else {
nsUri = builder.defaultNsUri;
}
}
return new QName(nsUri.intern(),local.intern());
}
/**
* Parses an {@link XmlRootElement} annotation on a class
* and determine the element name.
*
* @return null
* if none was found.
*/
protected final QName parseElementName(ClassDeclT clazz) {
XmlRootElement e = reader().getClassAnnotation(XmlRootElement.class,clazz,this);
if(e==null)
return null;
String local = e.name();
if(local.equals("##default")) {
// if defaulted...
local = NameConverter.standard.toVariableName(nav().getClassShortName(clazz));
}
String nsUri = e.namespace();
if(nsUri.equals("##default")) {
// if defaulted ...
XmlSchema xs = reader().getPackageAnnotation(XmlSchema.class,clazz,this);
if(xs!=null)
nsUri = xs.namespace();
else {
nsUri = builder.defaultNsUri;
}
}
return new QName(nsUri.intern(),local.intern());
}
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 String getEffectiveNamespaceFor(XmlElementRef r) {
String nsUri = r.namespace();
XmlSchema xs = reader().getPackageAnnotation( XmlSchema.class, parent.getClazz(), this );
if(xs!=null && xs.attributeFormDefault()== XmlNsForm.QUALIFIED) {
// JAX-RPC doesn't want the default namespace URI swapping to take effect to
// local "unqualified" elements. UGLY.
if(nsUri.length()==0)
nsUri = parent.builder.defaultNsUri;
}
return nsUri;
}
private QName calcXmlName(String uri,String local) {
// compute the default
TODO.checkSpec();
if(local.length()==0 || local.equals("##default"))
local = seed.getName();
if(uri.equals("##default")) {
XmlSchema xs = reader().getPackageAnnotation( XmlSchema.class, parent.getClazz(), this );
// JAX-RPC doesn't want the default namespace URI swapping to take effect to
// local "unqualified" elements. UGLY.
if(xs!=null) {
switch(xs.elementFormDefault()) {
case QUALIFIED:
QName typeName = parent.getTypeName();
if(typeName!=null)
uri = typeName.getNamespaceURI();
else
uri = xs.namespace();
if(uri.length()==0)
uri = parent.builder.defaultNsUri;
break;
case UNQUALIFIED:
case UNSET:
uri = "";
}
} else {
uri = "";
}
}
return new QName(uri.intern(),local.intern());
}
public Map<String,String> getSchemaLocations() {
Map<String, String> r = new HashMap<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 loc = xs.location();
if(loc.equals(XmlSchema.NO_LOCATION))
continue; // unspecified
r.put(xs.namespace(),loc);
}
return r;
}
public final XmlNsForm getElementFormDefault(String nsUri) {
for (ClassInfoImpl<T, C, F, M> ci : beans().values()) {
XmlSchema xs = reader.getPackageAnnotation( XmlSchema.class, ci.getClazz(), null );
if(xs==null)
continue;
if(!xs.namespace().equals(nsUri))
continue;
XmlNsForm xnf = xs.elementFormDefault();
if(xnf!=XmlNsForm.UNSET)
return xnf;
}
return XmlNsForm.UNSET;
}
/**
* Parses a (potentially-null) {@link XmlType} annotation on a class
* and determine the actual value.
*
* @param clazz
* The class on which the XmlType annotation is checked.
* @param t
* The {@link XmlType} annotation on the clazz. This value
* is taken as a parameter to improve the performance for the case where
* 't' is pre-computed.
*/
protected final QName parseTypeName(ClassDeclT clazz, XmlType t) {
String nsUri="##default";
String local="##default";
if(t!=null) {
nsUri = t.namespace();
local = t.name();
}
if(local.length()==0)
return null; // anonymous
if(local.equals("##default"))
// if defaulted ...
local = NameConverter.standard.toVariableName(nav().getClassShortName(clazz));
if(nsUri.equals("##default")) {
// if defaulted ...
XmlSchema xs = reader().getPackageAnnotation(XmlSchema.class,clazz,this);
if(xs!=null)
nsUri = xs.namespace();
else {
nsUri = builder.defaultNsUri;
}
}
return new QName(nsUri.intern(),local.intern());
}
private QName calcXmlName(XmlAttribute att) {
String uri;
String local;
uri = att.namespace();
local = att.name();
// compute the default
if(local.equals("##default"))
local = NameConverter.standard.toVariableName(getName());
if(uri.equals("##default")) {
XmlSchema xs = reader().getPackageAnnotation( XmlSchema.class, parent.getClazz(), this );
// JAX-RPC doesn't want the default namespace URI swapping to take effect to
// local "unqualified" elements. UGLY.
if(xs!=null) {
switch(xs.attributeFormDefault()) {
case QUALIFIED:
uri = parent.getTypeName().getNamespaceURI();
if(uri.length()==0)
uri = parent.builder.defaultNsUri;
break;
case UNQUALIFIED:
case UNSET:
uri = "";
}
} else
uri = "";
}
return new QName(uri.intern(),local.intern());
}
private static QName translate(Class<?> clazz) {
Annotation[] arr$ = clazz.getPackage().getAnnotations();
int len$ = arr$.length;
for(int i$ = 0; i$ < len$; ++i$) {
Annotation annotation = arr$[i$];
if (annotation instanceof XmlSchema) {
XmlSchema schema = (XmlSchema)annotation;
return new QName(schema.namespace(), clazz.getSimpleName());
}
}
LOG.debug("Unable to determine QName for class:" + clazz + " using package as namespace.");
return new QName(clazz.getPackage().getName(), clazz.getSimpleName());
}
private static QName translate(Class<?> clazz) {
Annotation[] arr$ = clazz.getPackage().getAnnotations();
int len$ = arr$.length;
for(int i$ = 0; i$ < len$; ++i$) {
Annotation annotation = arr$[i$];
if (annotation instanceof XmlSchema) {
XmlSchema schema = (XmlSchema)annotation;
return new QName(schema.namespace(), clazz.getSimpleName());
}
}
LOG.debug("Unable to determine QName for class:" + clazz + " using package as namespace.");
return new QName(clazz.getPackage().getName(), clazz.getSimpleName());
}
private QName calcXmlName(String uri,String local) {
// compute the default
TODO.checkSpec();
if(local.length()==0 || local.equals("##default"))
local = seed.getName();
if(uri.equals("##default")) {
XmlSchema xs = reader().getPackageAnnotation( XmlSchema.class, parent.getClazz(), this );
// JAX-RPC doesn't want the default namespace URI swapping to take effect to
// local "unqualified" elements. UGLY.
if(xs!=null) {
switch(xs.elementFormDefault()) {
case QUALIFIED:
QName typeName = parent.getTypeName();
if(typeName!=null)
uri = typeName.getNamespaceURI();
else
uri = xs.namespace();
if(uri.length()==0)
uri = parent.builder.defaultNsUri;
break;
case UNQUALIFIED:
case UNSET:
uri = "";
}
} else {
uri = "";
}
}
return new QName(uri.intern(),local.intern());
}
private static QName translate(Class<?> clazz) {
Annotation[] arr$ = clazz.getPackage().getAnnotations();
int len$ = arr$.length;
for(int i$ = 0; i$ < len$; ++i$) {
Annotation annotation = arr$[i$];
if (annotation instanceof XmlSchema) {
XmlSchema schema = (XmlSchema)annotation;
return new QName(schema.namespace(), clazz.getSimpleName());
}
}
LOG.debug("Unable to determine QName for class:" + clazz + " using package as namespace.");
return new QName(clazz.getPackage().getName(), clazz.getSimpleName());
}
private QName calcXmlName(XmlAttribute att) {
String uri;
String local;
uri = att.namespace();
local = att.name();
// compute the default
if(local.equals("##default"))
local = NameConverter.standard.toVariableName(getName());
if(uri.equals("##default")) {
XmlSchema xs = reader().getPackageAnnotation( XmlSchema.class, parent.getClazz(), this );
// JAX-RPC doesn't want the default namespace URI swapping to take effect to
// local "unqualified" elements. UGLY.
if(xs!=null) {
switch(xs.attributeFormDefault()) {
case QUALIFIED:
uri = parent.getTypeName().getNamespaceURI();
if(uri.length()==0)
uri = parent.builder.defaultNsUri;
break;
case UNQUALIFIED:
case UNSET:
uri = "";
}
} else
uri = "";
}
return new QName(uri.intern(),local.intern());
}
public Map<String,String> getSchemaLocations() {
Map<String, String> r = new HashMap<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 loc = xs.location();
if(loc.equals(XmlSchema.NO_LOCATION))
continue; // unspecified
r.put(xs.namespace(),loc);
}
return r;
}
public final XmlNsForm getElementFormDefault(String nsUri) {
for (ClassInfoImpl<T, C, F, M> ci : beans().values()) {
XmlSchema xs = reader.getPackageAnnotation( XmlSchema.class, ci.getClazz(), null );
if(xs==null)
continue;
if(!xs.namespace().equals(nsUri))
continue;
XmlNsForm xnf = xs.elementFormDefault();
if(xnf!=XmlNsForm.UNSET)
return xnf;
}
return XmlNsForm.UNSET;
}
private String getEffectiveNamespaceFor(XmlElementRef r) {
String nsUri = r.namespace();
XmlSchema xs = reader().getPackageAnnotation( XmlSchema.class, parent.getClazz(), this );
if(xs!=null && xs.attributeFormDefault()== XmlNsForm.QUALIFIED) {
// JAX-RPC doesn't want the default namespace URI swapping to take effect to
// local "unqualified" elements. UGLY.
if(nsUri.length()==0)
nsUri = parent.builder.defaultNsUri;
}
return nsUri;
}
/**
* Parses a (potentially-null) {@link XmlType} annotation on a class
* and determine the actual value.
*
* @param clazz
* The class on which the XmlType annotation is checked.
* @param t
* The {@link XmlType} annotation on the clazz. This value
* is taken as a parameter to improve the performance for the case where
* 't' is pre-computed.
*/
protected final QName parseTypeName(ClassDeclT clazz, XmlType t) {
String nsUri="##default";
String local="##default";
if(t!=null) {
nsUri = t.namespace();
local = t.name();
}
if(local.length()==0)
return null; // anonymous
if(local.equals("##default"))
// if defaulted ...
local = NameConverter.standard.toVariableName(nav().getClassShortName(clazz));
if(nsUri.equals("##default")) {
// if defaulted ...
XmlSchema xs = reader().getPackageAnnotation(XmlSchema.class,clazz,this);
if(xs!=null)
nsUri = xs.namespace();
else {
nsUri = builder.defaultNsUri;
}
}
return new QName(nsUri.intern(),local.intern());
}