我在WSDL文件中导入了嵌套模式,我需要提取模式名称,但我只能在一个级别上执行,而不是嵌套模式。请帮助
Map mp = new HashMap();
for( Object o : def.getTypes().getExtensibilityElements()) {
if( o instanceof javax.wsdl.extensions.schema.Schema ) {
// org.w3c.dom.Element elt = ((javax.wsdl.extensions.schema.SchemaImport) o) //.getElement();
Schema sc = (javax.wsdl.extensions.schema.Schema) o;
mp.put(sc.getElement().getNamespaceURI(),sc);
mp.putAll(sc.getImports());
System.out.println(mp);
//++i;
}
}
答案 0 :(得分:0)
在网上获得解决方案,分享与我相同的方法:
for( Object o : def.getTypes().getExtensibilityElements()) {
if( o instanceof javax.wsdl.extensions.schema.Schema ) {
Schema sc = (javax.wsdl.extensions.schema.Schema) o;
mp.put(sc.getElement().getNamespaceURI(),sc);
mp.putAll(sc.getImports());
readPackagesFromImports(sc);
System.out.println(mp);
}
}
And here goes the readPackagesFromImports method:
private static ArrayList<String> readPackagesFromImports(Schema schema) throws SchemaReaderException{
ArrayList<String> schemaImportPkgList = new ArrayList<String>();
Map map = schema.getImports();
Collection collection = map.values();
for(Iterator i =collection.iterator(); i.hasNext(); ){
Vector value = (Vector) i.next();
for(Object vectorObj:value){
SchemaImport si = (SchemaImport)vectorObj;
System.out.println("Reading import for SchemaLocation ="+si.getSchemaLocationURI());
Schema refSchema = si.getReferencedSchema();
//Implementing recursion for reading import within import
//First read inline schema for imported schema
ArrayList<String> inlineSchemaPkgList = readPackagesFromInlineSchema(refSchema);
for(String packageString:inlineSchemaPkgList){
if(packageString!=null){
schemaImportPkgList.add(packageString);
}
}
//Lets read if import has any imports by recurisvely calling readPackageFromImport again....
ArrayList<String> rec_ImportPkgList = readPackagesFromImports(refSchema);
for(String packageString:rec_ImportPkgList){
if(packageString!=null){
schemaImportPkgList.add(packageString);
}
}
}
}
return schemaImportPkgList;
}