namespaces.add(elemName.getNamespaceURI()); Schema schema = schemas.getSchema(elemName.getNamespaceURI()); if (schema.getImports() != null) { for (Iterator iter = schema.getImports().iterator(); iter.hasNext();) { String ns = (String) iter.next(); namespaces.add(ns);
if (elemName != null) { namespaces.add(elemName.getNamespaceURI()); Schema schema = schemas.getSchema(elemName.getNamespaceURI()); if (schema.getImports() != null) { for (Iterator iter = schema.getImports().iterator(); iter.hasNext();) { String ns = (String) iter.next(); namespaces.add(ns); }
    private Definition flattenDefinition(QName name) throws Exception {        // Check that schemas have been loaded        initialize();        // Create new definition        Definition flat = WSDLFactory.newInstance().newDefinition();        flat.setTargetNamespace(name.getNamespaceURI());        addNamespaces(flat, definition);        // Create port type        PortType defPort = definition.getPortType(name);        PortType flatPort = flat.createPortType();        flatPort.setQName(defPort.getQName());        flatPort.setUndefined(false);        // Import all operations and related messages        for (Iterator itOper = defPort.getOperations().iterator(); itOper.hasNext();) {            Operation defOper = (Operation) itOper.next();            Operation flatOper = flat.createOperation();            flatOper.setName(defOper.getName());            flatOper.setStyle(defOper.getStyle());            flatOper.setUndefined(false);            if (defOper.getInput() != null) {                Input flatInput = flat.createInput();                flatInput.setName(defOper.getInput().getName());                if (defOper.getInput().getMessage() != null) {                    Message flatInputMsg = copyMessage(defOper.getInput().getMessage(), flat);                    flatInput.setMessage(flatInputMsg);                    flat.addMessage(flatInputMsg);                }                flatOper.setInput(flatInput);            }            if (defOper.getOutput() != null) {                Output flatOutput = flat.createOutput();                flatOutput.setName(defOper.getOutput().getName());                if (defOper.getOutput().getMessage() != null) {                    Message flatOutputMsg = copyMessage(defOper.getOutput().getMessage(), flat);                    flatOutput.setMessage(flatOutputMsg);                    flat.addMessage(flatOutputMsg);                }                flatOper.setOutput(flatOutput);            }            for (Iterator itFault = defOper.getFaults().values().iterator(); itFault.hasNext();) {                Fault defFault = (Fault) itFault.next();                Fault flatFault = flat.createFault();                flatFault.setName(defFault.getName());                if (defFault.getMessage() != null) {                    Message flatFaultMsg = copyMessage(defFault.getMessage(), flat);                    flatFault.setMessage(flatFaultMsg);                    flat.addMessage(flatFaultMsg);                }                flatOper.addFault(flatFault);            }            flatPort.addOperation(flatOper);        }        // Get all needed direct schemas        Set namespaces = new HashSet();        for (Iterator itMsg = flat.getMessages().values().iterator(); itMsg.hasNext();) {            Message msg = (Message) itMsg.next();            for (Iterator itPart = msg.getParts().values().iterator(); itPart.hasNext();) {                Part part = (Part) itPart.next();                QName elemName = part.getElementName();                namespaces.add(elemName.getNamespaceURI());                Schema schema = schemas.getSchema(elemName.getNamespaceURI());                if (schema.getImports() != null) {                    for (Iterator iter = schema.getImports().iterator(); iter.hasNext();) {                        String ns = (String) iter.next();                        namespaces.add(ns);                    }                }            }        }        // Import schemas in definition        if (namespaces.size() > 0) {            Types types = flat.createTypes();            for (Iterator iter = namespaces.iterator(); iter.hasNext();) {                String ns = (String) iter.next();                javax.wsdl.extensions.schema.Schema imp = new SchemaImpl();                imp.setElement(schemas.getSchema(ns).getRoot());                imp.setElementType(new QName("http://www.w3.org/2001/XMLSchema", "schema"));                types.addExtensibilityElement(imp);            }            flat.setTypes(types);        }        flat.addPortType(flatPort);        return flat;    }