defaultschemagenerator.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 972 行 · 第 1/3 页
JAVA
972 行
classTypeName = "java.lang.Object";
} else {
classTypeName = getQualifiedName(type);
}
if (isArrayType && "byte".equals(classTypeName)) {
classTypeName = "base64Binary";
isArrayType = false;
}
if (isDataHandler(type)) {
classTypeName = "base64Binary";
}
QName schemaTypeName = typeTable.getSimpleSchemaTypeName(classTypeName);
if (schemaTypeName == null) {
schemaTypeName = generateSchema(type);
addContentToMethodSchemaType(sequence,
schemaTypeName,
partName,
isArrayType);
String schemaNamespace;
schemaNamespace = resolveSchemaNamespace(getQualifiedName(type.getContainingPackage()));
addImport(getXmlSchema(schemaNamespace), schemaTypeName);
} else {
addContentToMethodSchemaType(sequence,
schemaTypeName,
partName,
isArrayType);
}
return schemaTypeName;
}
protected boolean isDataHandler(JClass clazz){
if(clazz == null ){
return false;
}
String classType = clazz.getQualifiedName();
if("java.lang.Object".equals(classType)){
return false;
}
if ("javax.activation.DataHandler".equals(classType)) {
return true;
} else {
JClass supuerClass = clazz.getSuperclass();
if (supuerClass != null) {
return isDataHandler(supuerClass);
} else {
return false;
}
}
}
protected void addContentToMethodSchemaType(XmlSchemaSequence sequence,
QName schemaTypeName,
String paraName,
boolean isArray) {
XmlSchemaElement elt1 = new XmlSchemaElement();
elt1.setName(paraName);
elt1.setSchemaTypeName(schemaTypeName);
if (sequence != null) {
sequence.getItems().add(elt1);
}
if (isArray) {
elt1.setMaxOccurs(Long.MAX_VALUE);
}
elt1.setMinOccurs(0);
if (!("int".equals(schemaTypeName.getLocalPart()) ||
"double".equals(schemaTypeName.getLocalPart()) ||
"long".equals(schemaTypeName.getLocalPart()) ||
"boolean".equals(schemaTypeName.getLocalPart()) ||
"short".equals(schemaTypeName.getLocalPart()) ||
"float".equals(schemaTypeName.getLocalPart()) )) {
elt1.setNillable(true);
}
}
private XmlSchemaComplexType createSchemaTypeForMethodPart(String localPartName) {
XmlSchema xmlSchema = getXmlSchema(schemaTargetNameSpace);
QName elementName =
new QName(this.schemaTargetNameSpace, localPartName, this.schema_namespace_prefix);
XmlSchemaComplexType complexType = getComplexTypeForElement(xmlSchema, elementName);
if (complexType == null) {
complexType = new XmlSchemaComplexType(xmlSchema);
XmlSchemaElement globalElement = new XmlSchemaElement();
globalElement.setSchemaType(complexType);
globalElement.setName(localPartName);
globalElement.setQName(elementName);
xmlSchema.getItems().add(globalElement);
xmlSchema.getElements().add(elementName, globalElement);
}
typeTable.addComplexSchema(localPartName, elementName);
return complexType;
}
private XmlSchemaComplexType createSchemaTypeForFault(String localPartName) {
XmlSchema xmlSchema = getXmlSchema(schemaTargetNameSpace);
QName elementName =
new QName(this.schemaTargetNameSpace, localPartName, this.schema_namespace_prefix);
XmlSchemaComplexType complexType = getComplexTypeForElement(xmlSchema, elementName);
if (complexType == null) {
complexType = new XmlSchemaComplexType(xmlSchema);
XmlSchemaElement globalElement = new XmlSchemaElement();
globalElement.setSchemaType(complexType);
globalElement.setName(localPartName);
globalElement.setQName(elementName);
xmlSchema.getItems().add(globalElement);
xmlSchema.getElements().add(elementName, globalElement);
}
return complexType;
}
protected XmlSchemaComplexType getComplexTypeForElement(XmlSchema xmlSchema, QName name) {
Iterator iterator = xmlSchema.getItems().getIterator();
while (iterator.hasNext()) {
XmlSchemaObject object = (XmlSchemaObject) iterator.next();
if (object instanceof XmlSchemaElement && ((XmlSchemaElement) object).getQName().equals(name)) {
return (XmlSchemaComplexType) ((XmlSchemaElement) object).getSchemaType();
}
}
return null;
}
private XmlSchema getXmlSchema(String targetNamespace) {
XmlSchema xmlSchema;
if ((xmlSchema = (XmlSchema) schemaMap.get(targetNamespace)) == null) {
String targetNamespacePrefix = null;
if (targetNamespace.equals(schemaTargetNameSpace) &&
schema_namespace_prefix != null) {
targetNamespacePrefix = schema_namespace_prefix;
} else {
targetNamespacePrefix = generatePrefix();
}
xmlSchema = new XmlSchema(targetNamespace, xmlSchemaCollection);
xmlSchema.setAttributeFormDefault(getAttrFormDefaultSetting());
xmlSchema.setElementFormDefault(getElementFormDefaultSetting());
targetNamespacePrefixMap.put(targetNamespace, targetNamespacePrefix);
schemaMap.put(targetNamespace, xmlSchema);
NamespaceMap prefixmap = new NamespaceMap();
prefixmap.put(DEFAULT_SCHEMA_NAMESPACE_PREFIX, URI_2001_SCHEMA_XSD);
prefixmap.put(targetNamespacePrefix, targetNamespace);
xmlSchema.setNamespaceContext(prefixmap);
}
return xmlSchema;
}
public TypeTable getTypeTable() {
return typeTable;
}
public JMethod[] getMethods() {
return methods;
}
protected String generatePrefix() {
return NAME_SPACE_PREFIX + prefixCount++;
}
public void setExcludeMethods(ArrayList excludeMethods) {
if (excludeMethods == null) excludeMethods = new ArrayList();
this.excludeMethods = excludeMethods;
}
public String getSchemaTargetNameSpace() {
return schemaTargetNameSpace;
}
protected void addImport(XmlSchema xmlSchema, QName schemaTypeName) {
NamespacePrefixList map = xmlSchema.getNamespaceContext();
if (map instanceof NamespaceMap && !((NamespaceMap) map).values().
contains(schemaTypeName.getNamespaceURI())) {
XmlSchemaImport importElement = new XmlSchemaImport();
importElement.setNamespace(schemaTypeName.getNamespaceURI());
xmlSchema.getItems().add(importElement);
((NamespaceMap) xmlSchema.getNamespaceContext()).
put(generatePrefix(), schemaTypeName.getNamespaceURI());
}
}
public String getAttrFormDefault() {
return attrFormDefault;
}
public void setAttrFormDefault(String attrFormDefault) {
this.attrFormDefault = attrFormDefault;
}
public String getElementFormDefault() {
return elementFormDefault;
}
public void setElementFormDefault(String elementFormDefault) {
this.elementFormDefault = elementFormDefault;
}
protected XmlSchemaForm getAttrFormDefaultSetting() {
if (FORM_DEFAULT_UNQUALIFIED.equals(getAttrFormDefault())) {
return new XmlSchemaForm(XmlSchemaForm.UNQUALIFIED);
} else {
return new XmlSchemaForm(XmlSchemaForm.QUALIFIED);
}
}
protected XmlSchemaForm getElementFormDefaultSetting() {
if (FORM_DEFAULT_UNQUALIFIED.equals(getElementFormDefault())) {
return new XmlSchemaForm(XmlSchemaForm.UNQUALIFIED);
} else {
return new XmlSchemaForm(XmlSchemaForm.QUALIFIED);
}
}
public ArrayList getExtraClasses() {
if (extraClasses == null) {
extraClasses = new ArrayList();
}
return extraClasses;
}
public void setExtraClasses(ArrayList extraClasses) {
this.extraClasses = extraClasses;
}
protected String resolveSchemaNamespace(String packageName) throws Exception {
//if all types must go into the wsdl types schema namespace
if (useWSDLTypesNamespace) {
//return schemaTargetNameSpace;
return (String) pkg2nsmap.get("all");
} else {
if (pkg2nsmap != null && !pkg2nsmap.isEmpty()) {
//if types should go into namespaces that are mapped against the package name for the type
if (pkg2nsmap.get(packageName) != null) {
//return that mapping
return (String) pkg2nsmap.get(packageName);
} else {
return getNsGen().schemaNamespaceFromPackageName(packageName).toString();
}
} else {
// if pkg2nsmap is null and if not default schema ns found for the custom bean
return getNsGen().schemaNamespaceFromPackageName(packageName).toString();
}
}
}
public boolean isUseWSDLTypesNamespace() {
return useWSDLTypesNamespace;
}
public void setUseWSDLTypesNamespace(boolean useWSDLTypesNamespace) {
this.useWSDLTypesNamespace = useWSDLTypesNamespace;
}
public Map getPkg2nsmap() {
return pkg2nsmap;
}
public void setPkg2nsmap(Map pkg2nsmap) {
this.pkg2nsmap = pkg2nsmap;
}
public String getTargetNamespace() {
return targetNamespace;
}
protected String getSimpleName(JMethod method) {
return method.getSimpleName();
}
protected String getSimpleName(JClass type) {
return type.getSimpleName();
}
protected String getSimpleName(JProperty peroperty) {
return peroperty.getSimpleName();
}
protected String getSimpleName(JParameter parameter) {
return parameter.getSimpleName();
}
protected String getQualifiedName(JMethod method) {
return method.getQualifiedName();
}
protected String getQualifiedName(JClass type) {
return type.getQualifiedName();
}
protected String getQualifiedName(JProperty peroperty) {
return peroperty.getQualifiedName();
}
protected String getQualifiedName(JParameter parameter) {
return parameter.getQualifiedName();
}
protected String getQualifiedName(JPackage packagez) {
return packagez.getQualifiedName();
}
public void setNonRpcMethods(ArrayList nonRpcMethods) {
if (nonRpcMethods != null) {
this.nonRpcMethods = nonRpcMethods;
}
}
public void setAxisService(AxisService service) {
this.service = service;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?