0

我在 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;
                    } 
            }
4

1 回答 1

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;
    }
于 2014-03-21T10:45:07.527 回答