cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r639519 [3/3] - in /incubator/cxf/trunk: ./ api/src/main/java/org/apache/cxf/wsdl/ common/common/src/main/java/org/apache/cxf/common/classloader/ common/common/src/main/java/org/apache/cxf/common/xmlschema/ distribution/src/main/release/bin...
Date Fri, 21 Mar 2008 02:28:50 GMT
Modified: incubator/cxf/trunk/tools/corba/src/main/java/org/apache/cxf/tools/corba/processors/wsdl/WSDLToProcessor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/corba/src/main/java/org/apache/cxf/tools/corba/processors/wsdl/WSDLToProcessor.java?rev=639519&r1=639518&r2=639519&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/corba/src/main/java/org/apache/cxf/tools/corba/processors/wsdl/WSDLToProcessor.java
(original)
+++ incubator/cxf/trunk/tools/corba/src/main/java/org/apache/cxf/tools/corba/processors/wsdl/WSDLToProcessor.java
Thu Mar 20 19:28:42 2008
@@ -19,59 +19,36 @@
 
 package org.apache.cxf.tools.corba.processors.wsdl;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
 import java.util.logging.Logger;
 
-import javax.wsdl.Binding;
 import javax.wsdl.Definition;
-import javax.wsdl.Import;
-import javax.wsdl.Message;
-import javax.wsdl.PortType;
-import javax.wsdl.Service;
-import javax.wsdl.Types;
 import javax.wsdl.WSDLException;
-import javax.wsdl.extensions.ExtensionRegistry;
-import javax.wsdl.extensions.UnknownExtensibilityElement;
-import javax.wsdl.extensions.schema.Schema;
-import javax.wsdl.extensions.schema.SchemaImport;
-import javax.wsdl.factory.WSDLFactory;
-import javax.wsdl.xml.WSDLReader;
 
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.xmlschema.SchemaCollection;
+import org.apache.cxf.service.model.ServiceSchemaInfo;
 import org.apache.cxf.tools.common.Processor;
 import org.apache.cxf.tools.common.ToolContext;
 import org.apache.cxf.tools.common.ToolException;
 import org.apache.cxf.tools.corba.common.ProcessorEnvironment;
-import org.apache.ws.commons.schema.XmlSchema;
-import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.cxf.wsdl.WSDLManager;
+import org.apache.cxf.wsdl11.WSDLServiceBuilder;
 
 public class WSDLToProcessor implements Processor {
     
     protected static final Logger LOG = 
         LogUtils.getL7dLogger(WSDLToProcessor.class);
-    protected Definition wsdlDefinition;    
+    protected Definition wsdlDefinition; 
+    protected ServiceSchemaInfo schemas;
+    
     protected ToolContext toolContext;
-    protected WSDLFactory wsdlFactory;
-    protected WSDLReader wsdlReader;
     
-    private XmlSchema schematype;
     private ProcessorEnvironment env;
-    private ExtensionRegistry extReg;        
-    private List<Definition> importedDefinitions = new ArrayList<Definition>();
   
-    private XmlSchemaCollection schemaCol = new XmlSchemaCollection();
-    private Map<String, XmlSchema> schematypeList = new HashMap<String, XmlSchema>();
-    private List<Schema> schemaList;  
-    private List<String> schemaTargetNamespaces = new ArrayList<String>();
-    
     
     
     public WSDLToProcessor() {
-        schemaList = new ArrayList<Schema>();
     }
 
     public void setEnvironment(ToolContext toolCtx) {
@@ -80,17 +57,16 @@
 
     public void parseWSDL(String wsdlUrl) {
         try {           
-            WSDLFactory factory = WSDLFactory.newInstance();
-            WSDLReader reader = factory.newWSDLReader();
-            reader.setFeature("javax.wsdl.verbose", false);
-            reader.setFeature("javax.wsdl.importDocuments", true);            
-            if (getExtensionRegistry() != null) {
-                reader.setExtensionRegistry(extReg);
-            }
-            wsdlDefinition = reader.readWSDL(wsdlUrl);
-            schemaCol.setBaseUri(wsdlDefinition.getDocumentBaseURI());
-            parseImports(wsdlDefinition);
-            buildWSDLDefinition();    
+            Bus bus = BusFactory.getDefaultBus();
+            WSDLManager mgr = bus.getExtension(WSDLManager.class);
+            wsdlDefinition = mgr.getDefinition(wsdlUrl);
+            WSDLServiceBuilder builder = new WSDLServiceBuilder(bus);
+            builder.buildMockServices(wsdlDefinition);
+            schemas = mgr.getSchemasForDefinition(wsdlDefinition);
+            
+            //remove this as we're going to be modifying it
+            mgr.removeDefinition(wsdlDefinition);
+            
         } catch (WSDLException we) {
             org.apache.cxf.common.i18n.Message msg = 
                     new org.apache.cxf.common.i18n.Message(
@@ -99,126 +75,14 @@
         } 
     }
             
-    private void buildWSDLDefinition() {
-        for (Definition def : importedDefinitions) {
-            this.wsdlDefinition.addNamespace(def.getPrefix(def.getTargetNamespace()), def
-                .getTargetNamespace());
-            Object[] services = def.getServices().values().toArray();
-            for (int i = 0; i < services.length; i++) {
-                this.wsdlDefinition.addService((Service)services[i]);
-            }
-
-            Object[] messages = def.getMessages().values().toArray();
-            for (int i = 0; i < messages.length; i++) {
-                this.wsdlDefinition.addMessage((Message)messages[i]);
-            }
-
-            Object[] bindings = def.getBindings().values().toArray();
-            for (int i = 0; i < bindings.length; i++) {
-                this.wsdlDefinition.addBinding((Binding)bindings[i]);
-            }
-
-            Object[] portTypes = def.getPortTypes().values().toArray();
-            for (int i = 0; i < portTypes.length; i++) {
-                this.wsdlDefinition.addPortType((PortType)portTypes[i]);
-            }
-        }
-    }
-
-    @SuppressWarnings("unchecked")
-    private void parseImports(Definition def) {
-        List<Import> importList = new ArrayList<Import>();
-        Map imports = def.getImports();
-        for (Iterator iter = imports.keySet().iterator(); iter.hasNext();) {
-            String uri = (String)iter.next();
-            importList.addAll((List<Import>)imports.get(uri));
-        }
-        for (Import impt : importList) {
-            parseImports(impt.getDefinition());
-            importedDefinitions.add(impt.getDefinition());
-        }
-    }
-
-    private void extractSchema(Definition def) {
-        Types typesElement = def.getTypes();
-        if (typesElement != null) {
-            Iterator ite = typesElement.getExtensibilityElements().iterator();
-            while (ite.hasNext()) {
-                Object obj = ite.next();
-                org.w3c.dom.Element schemaElem = null;
-                if (obj instanceof Schema) {
-                    Schema schema = (Schema) obj;
-                    addSchema(schema);
-                    schemaElem = schema.getElement();
-                } else if (obj instanceof UnknownExtensibilityElement) {
-                    org.w3c.dom.Element elem = ((UnknownExtensibilityElement) obj).getElement();
-                    if (elem.getLocalName().equals("schema")) {
-                        schemaElem = elem;
-                    }
-                }
-                
-                if (schemaElem != null) {
-                    String uri = def.getDocumentBaseURI() + "#types";
-                    String ns = schemaElem.getAttribute("targetNamespace");
-                    if (!schematypeList.containsKey("{" + ns + "}" + uri)) {
-                        schematype = schemaCol.read(schemaElem, uri);                   

-                        schematypeList.put("{" + ns + "}" + uri, schematype);           
        
-                    }
-                }
-            }
-        }
-                
-    }        
 
     public void process() throws ToolException {
         if (env == null) {
             env = new ProcessorEnvironment();
             env.put("wsdlurl", wsdlDefinition.getDocumentBaseURI());
         }
-
-        schemaTargetNamespaces.clear();
-        extractSchema(wsdlDefinition);
-        for (Definition def : importedDefinitions) {
-            extractSchema(def);
-        }
-        schemaTargetNamespaces.clear();     
     }
     
-    private boolean isSchemaImported(Schema schema) {
-        return schemaList.contains(schema);
-    }
-    
-    private boolean isSchemaParsed(String targetNamespace) {
-        if (!schemaTargetNamespaces.contains(targetNamespace)) {
-            schemaTargetNamespaces.add(targetNamespace);
-            return false;
-        } else {
-            return true;
-        }
-    }
-    
-    @SuppressWarnings("unchecked")
-    private void addSchema(Schema schema) {
-        Map<String, List> imports = schema.getImports();
-        if (imports != null && imports.size() > 0) {
-            Collection<String> importKeys = imports.keySet();
-            for (String importNamespace : importKeys) {
-                if (!isSchemaParsed(importNamespace + "?file=" + schema.getDocumentBaseURI()))
{
-                    List<SchemaImport> schemaImports = imports.get(importNamespace);
-                    for (SchemaImport schemaImport : schemaImports) {
-                        Schema tempImport = schemaImport.getReferencedSchema();
-                        if (tempImport != null && !isSchemaImported(tempImport))
{
-                            addSchema(tempImport);
-                        }
-                    }
-                }
-            }
-        }
-        if (!isSchemaImported(schema)) {
-            schemaList.add(schema);            
-        }
-    }
-
     public Definition getWSDLDefinition() {
         return this.wsdlDefinition;
     }
@@ -227,12 +91,10 @@
         wsdlDefinition = definition;
     }
 
-    public XmlSchema getXmlSchemaType() {
-        return this.schematype;
-    }
 
-    public Collection<XmlSchema> getXmlSchemaTypes() {
-        return this.schematypeList.values();
+
+    public SchemaCollection getXmlSchemaTypes() {
+        return schemas.getSchemaCollection();
     }
         
     public void setEnvironment(ProcessorEnvironment environement) {
@@ -243,11 +105,5 @@
         return this.env;
     }
 
-    public void setExtensionRegistry(ExtensionRegistry reg) {
-        extReg = reg;
-    }
-    
-    public ExtensionRegistry getExtensionRegistry() {
-        return extReg;
-    }   
+
 }



Mime
View raw message