extensionutility.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 648 行 · 第 1/2 页
JAVA
648 行
if (cmplxType.getContentModel() == null) {
processSchemaSequence(cmplxType.getParticle(), mapper, opName, schemaMap, qnameSuffix);
} else {
processComplexContentModel(cmplxType, mapper, opName, schemaMap, qnameSuffix);
}
processAttributes(cmplxType, opName, qnameSuffix, mapper);
}
}
private static void processAttributes(XmlSchemaComplexType complexType,
String opName,
String qnameSuffix,
TypeMapper typeMap) {
XmlSchemaObjectCollection xmlObjectCollection = complexType.getAttributes();
XmlSchemaObject item;
for (Iterator iter = xmlObjectCollection.getIterator(); iter.hasNext();) {
item = (XmlSchemaObject) iter.next();
XmlSchemaAttribute xmlSchemaAttribute;
if (item instanceof XmlSchemaAttribute) {
xmlSchemaAttribute = (XmlSchemaAttribute) item;
populateClassName(xmlSchemaAttribute.getMetaInfoMap(),
typeMap,
opName,
false,
xmlSchemaAttribute.getName(),
qnameSuffix);
}
}
}
private static 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 static void processComplexContentModel(XmlSchemaComplexType cmplxType,
TypeMapper mapper,
String opName,
Map schemaMap,
String qnameSuffix) {
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
processSchemaSequence(schemaExtension.getParticle(), mapper, opName, schemaMap, qnameSuffix);
XmlSchema xmlSchema = null;
XmlSchemaType extensionSchemaType = null;
for (Iterator iter = schemaMap.values().iterator();iter.hasNext();){
xmlSchema = (XmlSchema) iter.next();
extensionSchemaType = getSchemaType(xmlSchema,schemaExtension.getBaseTypeName());
if (extensionSchemaType != null){
break;
}
}
processXMLSchemaComplexType(extensionSchemaType, mapper, opName, schemaMap, qnameSuffix);
}
}
}
private static void processSchemaSequence(XmlSchemaParticle particle,
TypeMapper mapper,
String opName,
Map schemaMap,
String qnameSuffix) {
if (particle instanceof XmlSchemaSequence) {
XmlSchemaObjectCollection items = ((XmlSchemaSequence) particle).getItems();
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) {
//populate the map with the partname - class name
//attached to the schema element
XmlSchemaElement xmlSchemaElement = (XmlSchemaElement) item;
boolean isArray = xmlSchemaElement.getMaxOccurs() > 1;
XmlSchemaType schemaType = xmlSchemaElement.getSchemaType();
String partName = null;
if (xmlSchemaElement.getRefName() != null) {
partName = xmlSchemaElement.getRefName().getLocalPart();
} else {
partName = xmlSchemaElement.getName();
}
// get the element class name from the element and populate the mapper
populateClassName(xmlSchemaElement.getMetaInfoMap(),
mapper,
opName,
isArray,
partName,
qnameSuffix);
} 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
XmlSchemaAny xmlSchemaAny = (XmlSchemaAny) item;
boolean isArray = xmlSchemaAny.getMaxOccurs() > 1;
QName partQName = WSDLUtil.getPartQName(opName,
qnameSuffix,
Constants.ANY_ELEMENT_FIELD_NAME);
if (isArray) {
mapper.addTypeMappingName(partQName, "org.apache.axiom.om.OMElement[]");
} else {
mapper.addTypeMappingName(partQName, "org.apache.axiom.om.OMElement");
}
}
}
}
}
// private static void
/**
* Util method to populate the class name into the typeMap
*
*/
private static void populateClassName(Map metaInfoMap,
TypeMapper typeMap,
String opName,
boolean isArray,
String partName,
String qnameSuffix) {
if (metaInfoMap != null) {
String className = (String) metaInfoMap.
get(SchemaConstants.SchemaCompilerInfoHolder.CLASSNAME_KEY);
// this is a temporary patch
// the acual problem is keeping the class name details on the schemaType in
// XmlSchema compiler.
// we have to store them in XmlElement
if (isArray && !className.endsWith("[]")) {
className += "[]";
} else if (!isArray && className.endsWith("[]")) {
className = className.substring(0, className.length() - 2);
}
QName partQName = WSDLUtil.getPartQName(opName,
qnameSuffix,
partName);
typeMap.addTypeMappingName(partQName, className);
if (Boolean.TRUE.equals(
metaInfoMap.get(SchemaConstants.
SchemaCompilerInfoHolder.CLASSNAME_PRIMITVE_KEY))) {
//this type is primitive - add that to the type mapper status
//for now lets add a boolean
typeMap.addTypeMappingStatus(partQName, Boolean.TRUE);
}
}
}
/**
* Look for a given schema type given the schema type Qname
*
* @param schemaMap
* @return null if the schema is not found
*/
private static XmlSchemaType findSchemaType(Map schemaMap, QName schemaTypeName) {
//find the schema
XmlSchema schema = (XmlSchema) schemaMap.get(schemaTypeName.getNamespaceURI());
if (schema != null) {
return schema.getTypeByName(schemaTypeName);
}
return null;
}
/**
* populate parameters from the user
*
* @param options
*/
private static void populateUserparameters(CompilerOptions options, CodeGenConfiguration configuration) {
Map propertyMap = configuration.getProperties();
if (propertyMap.containsKey(SchemaConstants.SchemaCompilerArguments.WRAP_SCHEMA_CLASSES)) {
if (Boolean.valueOf(
propertyMap.get(SchemaConstants.SchemaCompilerArguments.WRAP_SCHEMA_CLASSES).toString()).
booleanValue()) {
options.setWrapClasses(true);
} else {
options.setWrapClasses(false);
}
}
if (propertyMap.containsKey(SchemaConstants.SchemaCompilerArguments.WRITE_SCHEMA_CLASSES)) {
if (Boolean.valueOf(
propertyMap.get(SchemaConstants.SchemaCompilerArguments.WRITE_SCHEMA_CLASSES).toString()).
booleanValue()) {
options.setWriteOutput(true);
} else {
options.setWriteOutput(false);
}
}
// add the custom package name
if (propertyMap.containsKey(SchemaConstants.SchemaCompilerArguments.PACKAGE)) {
String packageName = (String) propertyMap.get(SchemaConstants.SchemaCompilerArguments.PACKAGE);
if (packageName != null || !"".equals(packageName)) {
options.setPackageName(packageName);
}
}
// set the package namespace to uri details
options.setNs2PackageMap(configuration.getUri2PackageNameMap());
//add custom mapper package name
if (propertyMap.containsKey(SchemaConstants.SchemaCompilerArguments.MAPPER_PACKAGE)) {
String packageName = (String) propertyMap.get(SchemaConstants.SchemaCompilerArguments.MAPPER_PACKAGE);
if (packageName != null || !"".equals(packageName)) {
options.setMapperClassPackage(packageName);
}
}
if (propertyMap.containsKey(SchemaConstants.SchemaCompilerArguments.OFF_STRICT_VALIDATION)){
options.setOffStrictValidation(true);
}
//set helper mode
//this becomes effective only if the classes are unpacked
if (!options.isWrapClasses()) {
if (propertyMap.containsKey(SchemaConstants.SchemaCompilerArguments.HELPER_MODE)) {
options.setHelperMode(true);
}
}
}
/**
* populate the default options - called before the applying of user parameters
*
* @param options
*/
private static void populateDefaultOptions(CompilerOptions options,
CodeGenConfiguration configuration) {
//create the output directory
File outputDir = configuration.isFlattenFiles() ?
configuration.getOutputLocation() :
new File(configuration.getOutputLocation(), configuration.getSourceLocation());
if (!outputDir.exists()) {
outputDir.mkdirs();
}
/// these options need to be taken from the command line
options.setOutputLocation(outputDir);
options.setNs2PackageMap(configuration.getUri2PackageNameMap() == null ?
new HashMap() :
configuration.getUri2PackageNameMap());
//default setting is to set the wrap status depending on whether it's
//the server side or the client side
if (configuration.isServerSide()) {
//for the serverside we generate unwrapped by default
options.setWrapClasses(false);
//for the serverside we write the output by default
options.setWriteOutput(true);
} else {
// for the client let the users preference be the word here
options.setWrapClasses(configuration.isPackClasses());
//for the client side the default setting is not to write the
//output
options.setWriteOutput(!configuration.isPackClasses());
}
if (configuration.isGenerateAll()) {
options.setGenerateAll(true);
}
if (configuration.isBackwordCompatibilityMode()) {
options.setBackwordCompatibilityMode(true);
}
if (configuration.isSuppressPrefixesMode()) {
options.setSuppressPrefixesMode(true);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?