schemaunwrapperextension.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 411 行 · 第 1/2 页
JAVA
411 行
}
}
private void processAttributes(XmlSchemaComplexType complexType,
AxisMessage message,
List partNameList,
String qnameSuffix) {
QName opName = message.getAxisOperation().getName();
XmlSchemaObjectCollection xmlObjectCollection = complexType.getAttributes();
XmlSchemaObject item;
XmlSchemaAttribute xmlSchemaAttribute;
for (Iterator iter = xmlObjectCollection.getIterator(); iter.hasNext();) {
item = (XmlSchemaObject) iter.next();
if (item instanceof XmlSchemaAttribute) {
xmlSchemaAttribute = (XmlSchemaAttribute) item;
String partName = xmlSchemaAttribute.getName();
partNameList.add(
WSDLUtil.getPartQName(opName.getLocalPart(),
qnameSuffix,
partName));
}
}
}
private void processComplexContentModel(XmlSchemaComplexType cmplxType,
AxisMessage message,
List partNameList,
String qnameSuffix) throws CodeGenerationException {
XmlSchemaContentModel contentModel = cmplxType.getContentModel();
if (contentModel instanceof XmlSchemaComplexContent) {
XmlSchemaComplexContent xmlSchemaComplexContent = (XmlSchemaComplexContent) contentModel;
XmlSchemaContent content = xmlSchemaComplexContent.getContent();
if (content instanceof XmlSchemaComplexContentExtension) {
XmlSchemaComplexContentExtension schemaExtension = (XmlSchemaComplexContentExtension) content;
// process particles inside this extension, if any
if (schemaExtension.getParticle() != null) {
processXMLSchemaSequence(schemaExtension.getParticle(), message, partNameList,
qnameSuffix);
}
// now we need to get the schema of the extension type from the parent schema. For that let's first retrieve
// the parent schema
AxisService axisService = message.getAxisOperation().getAxisService();
ArrayList schemasList = axisService.getSchema();
XmlSchema parentSchema = null;
XmlSchema schema = null;
XmlSchemaType extensionSchemaType = null;
for (Iterator iter = schemasList.iterator(); iter.hasNext();) {
schema = (XmlSchema) iter.next();
extensionSchemaType = getSchemaType(schema, schemaExtension.getBaseTypeName());
if (extensionSchemaType != null) {
break;
}
}
// ok now we got the parent schema. Now let's get the extension's schema type
handleAllCasesOfComplexTypes(extensionSchemaType, message, partNameList,
qnameSuffix);
}
}
}
private XmlSchemaType getSchemaType(XmlSchema schema, QName typeName) {
XmlSchemaType xmlSchemaType = null;
if (schema != null) {
xmlSchemaType = schema.getTypeByName(typeName);
if (xmlSchemaType == null) {
// try to find in an import or an include
XmlSchemaObjectCollection includes = schema.getIncludes();
if (includes != null) {
Iterator includesIter = includes.getIterator();
Object object = null;
while (includesIter.hasNext()) {
object = includesIter.next();
if (object instanceof XmlSchemaImport) {
XmlSchema schema1 = ((XmlSchemaImport) object).getSchema();
xmlSchemaType = getSchemaType(schema1, typeName);
}
if (object instanceof XmlSchemaInclude) {
XmlSchema schema1 = ((XmlSchemaInclude) object).getSchema();
xmlSchemaType = getSchemaType(schema1, typeName);
}
if (xmlSchemaType != null) {
break;
}
}
}
}
}
return xmlSchemaType;
}
private void processXMLSchemaSequence(XmlSchemaParticle schemaParticle,
AxisMessage message,
List partNameList,
String qnameSuffix) throws CodeGenerationException {
if (schemaParticle instanceof XmlSchemaSequence) {
// get the name of the operation name and namespace,
// part name and hang them somewhere ? The ideal place
// would be the property bag in the codegen config!
QName opName = message.getAxisOperation().getName();
XmlSchemaSequence sequence = (XmlSchemaSequence) schemaParticle;
XmlSchemaObjectCollection items = sequence.getItems();
// if this is an empty sequence, return
if (items.getCount() == 0) {
return;
}
for (Iterator i = items.getIterator(); i.hasNext();) {
Object item = i.next();
// get each and every element in the sequence and
// traverse through them
if (item instanceof XmlSchemaElement) {
//add the element name to the part name list
XmlSchemaElement xmlSchemaElement = (XmlSchemaElement) item;
XmlSchemaType schemaType = xmlSchemaElement.getSchemaType();
String partName = null;
if (xmlSchemaElement.getRefName() != null) {
partName = xmlSchemaElement.getRefName().getLocalPart();
} else {
partName = xmlSchemaElement.getName();
}
// part names are not unique across messages. Hence
// we need some way of making the part name a unique
// one (due to the fact that the type mapper
// is a global list of types).
// The seemingly best way to do that is to
// specify a namespace for the part QName reference which
// is stored in the list. This part qname is
// temporary and should not be used with it's
// namespace URI (which happened to be the operation name)
// with _input attached to it
partNameList.add(
WSDLUtil.getPartQName(opName.getLocalPart(),
qnameSuffix,
partName));
// if the particle contains anything other than
// a XMLSchemaElement then we are not in a position
// to unwrap it
} else if (item instanceof XmlSchemaAny) {
// if this is an instance of xs:any, then there is no part name for it. Using ANY_ELEMENT_FIELD_NAME
// for it for now
//we have to handle both maxoccurs 1 and maxoccurs > 1 situation
XmlSchemaAny xmlSchemaAny = (XmlSchemaAny) item;
partNameList.add(
WSDLUtil.getPartQName(opName.getLocalPart(),
qnameSuffix,
Constants.ANY_ELEMENT_FIELD_NAME));
} else {
throw new CodeGenerationException(
CodegenMessages.getMessage("extension.unsupportedSchemaFormat",
"unknown type", "Element"));
}
}
//we do not know how to deal with other particles
//such as xs:all or xs:choice. Usually occurs when
//passed with the user built WSDL where the style
//is document.
} else if (schemaParticle instanceof XmlSchemaChoice) {
throw new CodeGenerationException(
CodegenMessages.getMessage("extension.unsupportedSchemaFormat",
"choice", "sequence"));
} else if (schemaParticle instanceof XmlSchemaAll) {
throw new CodeGenerationException(
CodegenMessages.getMessage("extension.unsupportedSchemaFormat",
"all", "sequence"));
} else {
throw new CodeGenerationException(
CodegenMessages.getMessage("extension.unsupportedSchemaFormat",
"unknown", "sequence"));
}
}
/**
* Generate a parametes object
*
* @param key
* @param value
*/
private Parameter getParameter(String key, Object value) {
Parameter myParameter = new Parameter();
myParameter.setName(key);
myParameter.setValue(value);
return myParameter;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?