cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r608894 [8/10] - in /incubator/cxf/trunk: ./ buildtools/src/main/resources/ common/schemas/src/main/resources/schemas/wsdl/ etc/eclipse/ maven-plugins/corba/ parent/ rt/bindings/corba/ rt/bindings/corba/src/main/java/org/apache/yoko/binding...
Date Fri, 04 Jan 2008 15:47:53 GMT
Modified: incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/PortTypeVisitor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/PortTypeVisitor.java?rev=608894&r1=608893&r2=608894&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/PortTypeVisitor.java (original)
+++ incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/PortTypeVisitor.java Fri Jan  4 07:47:28 2008
@@ -15,16 +15,20 @@
  * KIND, either express or implied. See the License for the
  * specific language governing permissions and limitations
  * under the License.
-*/
+ */
 
 package org.apache.yoko.tools.processors.idl;
 
+import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
 import javax.wsdl.Binding;
+import javax.wsdl.BindingOperation;
 import javax.wsdl.Definition;
+import javax.wsdl.Fault;
+import javax.wsdl.Operation;
 import javax.wsdl.PortType;
 import javax.wsdl.WSDLException;
 import javax.wsdl.extensions.ExtensionRegistry;
@@ -33,24 +37,27 @@
 
 import antlr.collections.AST;
 
+import org.apache.cxf.helpers.CastUtils;
 import org.apache.schemas.yoko.bindings.corba.BindingType;
 
+import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.ws.commons.schema.XmlSchemaType;
 import org.apache.yoko.wsdl.CorbaConstants;
 import org.apache.yoko.wsdl.CorbaTypeImpl;
 
 public class PortTypeVisitor extends VisitorBase {   
 
-    Definition definition;
     ExtensionRegistry extReg;
     PortType portType;
-    String module;
+    Definition rootDefinition;
 
     public PortTypeVisitor(Scope scope,
+                           Definition defn,
+                           XmlSchema schemaRef,
                            WSDLASTVisitor wsdlASTVisitor) {
-        super(scope, wsdlASTVisitor);
-        definition = wsdlVisitor.getDefinition();
+        super(scope, defn, schemaRef, wsdlASTVisitor);
         extReg = definition.getExtensionRegistry();
+        rootDefinition = wsdlASTVisitor.getDefinition();
     }
 
     public static boolean accept(AST node) {
@@ -89,110 +96,153 @@
 
     // Visits a fully declared interface
     private void visitInterface(AST identifierNode) {
-        String interfaceName = identifierNode.toString();        
-        Scope interfaceScope = new Scope(getScope(), interfaceName);        
-        
-        portType = definition.createPortType();
-        portType.setQName(new QName(definition.getTargetNamespace(), interfaceScope.toString()));
-        portType.setUndefined(false);
-        definition.addPortType(portType);
-        Binding binding = createBinding();
-        
-        AST specNode = identifierNode.getNextSibling();        
-        if  (specNode.getType() == IDLTokenTypes.LCURLY) {
-            specNode = specNode.getNextSibling();
-        }
+        try {
+            String interfaceName = identifierNode.toString();        
+            Scope interfaceScope = new Scope(getScope(), interfaceName);
+            portType = definition.createPortType();
+
+            String portTypeName = interfaceScope.toString();
+
+            XmlSchema newSchema = schema;
+            if (!mapper.isDefaultMapping()) {
+                portTypeName = interfaceScope.tail();
+                //add a schema based on the interface
+                String tns = mapper.map(interfaceScope);
+                newSchema = manager.createXmlSchemaForDefinition(definition, tns, schemas);
+                definition.addNamespace(interfaceScope.toString("_"), tns);
+            }
+            String tns = definition.getTargetNamespace();
+            portType.setQName(new QName(tns, portTypeName));
+            definition.addPortType(portType);
+            portType.setUndefined(false);
+
+            Binding binding = createBinding(interfaceScope.toString());
+        
+            AST specNode = identifierNode.getNextSibling();        
+            if  (specNode.getType() == IDLTokenTypes.LCURLY) {
+                specNode = specNode.getNextSibling();
+            }
         
-        AST exportNode = null;        
-        if (specNode.getType() == IDLTokenTypes.RCURLY) {
-            exportNode = specNode.getNextSibling();        
-        } else if (specNode.getType() == IDLTokenTypes.COLON) {
-            exportNode = visitInterfaceInheritanceSpec(specNode, binding);
-            exportNode = exportNode.getNextSibling();
-        } else {            
-            exportNode = specNode;
-        }
+            AST exportNode = null;        
+            if (specNode.getType() == IDLTokenTypes.RCURLY) {
+                exportNode = specNode.getNextSibling();        
+            } else if (specNode.getType() == IDLTokenTypes.COLON) {
+                exportNode = visitInterfaceInheritanceSpec(specNode, binding, interfaceScope);
+                exportNode = exportNode.getNextSibling();
+            } else {
+                exportNode = specNode;
+            }
            
-        while (exportNode != null  
-            && exportNode.getType() != IDLTokenTypes.RCURLY) {
+            while (exportNode != null  
+                   && exportNode.getType() != IDLTokenTypes.RCURLY) {
             
-            if (TypeDclVisitor.accept(exportNode)) {
-                TypeDclVisitor visitor = new TypeDclVisitor(interfaceScope,
-                                                            wsdlVisitor);
-                visitor.visit(exportNode);
-            } else if (ConstVisitor.accept(exportNode)) {
-                ConstVisitor visitor = new ConstVisitor(interfaceScope,
-                                                        wsdlVisitor);
-                visitor.visit(exportNode);
-            } else if (ExceptionVisitor.accept(exportNode)) {
-                ExceptionVisitor visitor = new ExceptionVisitor(interfaceScope,
+                if (TypeDclVisitor.accept(exportNode)) {
+                    TypeDclVisitor visitor = new TypeDclVisitor(interfaceScope,
+                                                                definition,
+                                                                newSchema,
                                                                 wsdlVisitor);
-                visitor.visit(exportNode);
-            } else if (AttributeVisitor.accept(exportNode)) {
-                AttributeVisitor attributeVisitor = new AttributeVisitor(interfaceScope,
-                                                                         wsdlVisitor,
-                                                                         portType,
-                                                                         binding);
-                attributeVisitor.visit(exportNode);                
-
-            } else if (OperationVisitor.accept(interfaceScope, schemas, schema, 
-                                               typeMap, wsdlVisitor.getDefinition(),
-                                               exportNode, wsdlVisitor)) {
-                OperationVisitor visitor = new OperationVisitor(interfaceScope,
-                                                                wsdlVisitor,
-                                                                portType,
-                                                                binding);
-                visitor.visit(exportNode);                     
-            } else {
-                throw new RuntimeException("[InterfaceVisitor] Invalid IDL: unknown element "
-                                           + exportNode.toString());
-            }
+                    visitor.visit(exportNode);
+                } else if (ConstVisitor.accept(exportNode)) {
+                    ConstVisitor visitor = new ConstVisitor(interfaceScope,
+                                                            definition,
+                                                            newSchema,
+                                                            wsdlVisitor);
+                    visitor.visit(exportNode);
+                } else if (ExceptionVisitor.accept(exportNode)) {
+                    ExceptionVisitor visitor = new ExceptionVisitor(interfaceScope,
+                                                                    definition,
+                                                                    newSchema,
+                                                                    wsdlVisitor);
+                    visitor.visit(exportNode);
+                } else if (AttributeVisitor.accept(exportNode)) {
+                    AttributeVisitor attributeVisitor = new AttributeVisitor(interfaceScope,
+                                                                             definition,
+                                                                             newSchema,
+                                                                             wsdlVisitor,
+                                                                             portType,
+                                                                             binding);
+                    attributeVisitor.visit(exportNode);
+                } else if (OperationVisitor.accept(interfaceScope,
+                                                   definition,
+                                                   newSchema, 
+                                                   exportNode,
+                                                   wsdlVisitor)) {
+                    OperationVisitor visitor = new OperationVisitor(interfaceScope,
+                                                                    definition,
+                                                                    newSchema,
+                                                                    wsdlVisitor,
+                                                                    portType,
+                                                                    binding);
+                    visitor.visit(exportNode);
+                } else {
+                    throw new RuntimeException("[InterfaceVisitor] Invalid IDL: unknown element "
+                                               + exportNode.toString());
+                }
             
-            exportNode = exportNode.getNextSibling();
-        }
+                exportNode = exportNode.getNextSibling();
+            }
 
-        // Once we've finished declaring the interface, we should make sure it has been removed 
-        // from the list of scopedNames so that we indicate that is no longer simply forward
-        // declared.
-        Scope scopedName = new Scope(getScope(), identifierNode);
-        scopedNames.remove(scopedName);
-        
-        if (wsdlVisitor.getDeferredActions() != null) {
-            DeferredActionCollection deferredActions = wsdlVisitor.getDeferredActions();
-            List list = deferredActions.getActionsList(scopedName);
-            if (!list.isEmpty()) {
-                if (ObjectReferenceVisitor.accept(getScope(), schema, 
-                                                  wsdlVisitor.getDefinition(), identifierNode)) {
-                    ObjectReferenceVisitor visitor = new ObjectReferenceVisitor(getScope(), wsdlVisitor);
-                    visitor.visit(identifierNode);
-                    XmlSchemaType stype = visitor.getSchemaType();
-                    CorbaTypeImpl ctype = visitor.getCorbaType();
-                    Iterator iterator = list.iterator();
-                    
-                    while (iterator.hasNext()) {
-                        DeferredAction action = (DeferredAction)iterator.next();
-                        action.doDeferredAction(stype, ctype);                       
-                    }
-                    iterator = list.iterator();                    
-                    while (iterator.hasNext()) {
-                        iterator.next();
-                        iterator.remove();                       
-                    }                      
-                }    
-            }            
-        }   
+            // Once we've finished declaring the interface, we should make sure it has been removed 
+            // from the list of scopedNames so that we indicate that is no longer simply forward
+            // declared.
+            Scope scopedName = new Scope(getScope(), identifierNode);
+            scopedNames.remove(scopedName);
+        
+            if (wsdlVisitor.getDeferredActions() != null) {
+                handleDeferredActions(wsdlVisitor.getDeferredActions(), scopedName, identifierNode);
+            }
+
+            if (!mapper.isDefaultMapping()) {
+                manager.deferAttachSchemaToWSDL(definition, newSchema, false);
+                //manager.attachSchemaToWSDL(definition, newSchema, false);
+            }
+
+        } catch (Exception ex) {
+            throw new RuntimeException(ex);
+        }           
+    }
+    
+    private void handleDeferredActions(DeferredActionCollection deferredActions,
+                                       Scope scopedName,
+                                       AST identifierNode) {
+        List list = deferredActions.getActions(scopedName);
+        if ((list != null) && !list.isEmpty()) {
+            XmlSchemaType stype = null;
+            CorbaTypeImpl ctype = null;
+            if (ObjectReferenceVisitor.accept(getScope(), schema, 
+                                              definition, identifierNode, wsdlVisitor)) {
+                ObjectReferenceVisitor visitor = new ObjectReferenceVisitor(getScope(),
+                                                                            definition,
+                                                                            schema,
+                                                                            wsdlVisitor);
+                visitor.visit(identifierNode);
+                stype = visitor.getSchemaType();
+                ctype = visitor.getCorbaType();
+            }
+            Iterator iterator = list.iterator();
+            while (iterator.hasNext()) {
+                DeferredAction action = (DeferredAction) iterator.next();
+                if (action instanceof SchemaDeferredAction
+                    && (stype != null) && (ctype != null)) {
+                    SchemaDeferredAction schemaAction = (SchemaDeferredAction) action;
+                    schemaAction.execute(stype, ctype);
+                }
+            }
+            deferredActions.removeScope(scopedName);
+        }
     }
+
     
-    public Binding createBinding() {
-        String bname = portType.getQName().getLocalPart() + "CORBABinding";
-        QName bqname = new QName(definition.getTargetNamespace(),
+    public Binding createBinding(String scopedPortTypeName) {
+        String bname = scopedPortTypeName + "CORBABinding";
+        QName bqname = new QName(rootDefinition.getTargetNamespace(),
                                  bname);
         int count = 0;
         while (queryBinding(bqname)) {
             bname = bname + count;
-            bqname = new QName(definition.getTargetNamespace(), bname);
+            bqname = new QName(rootDefinition.getTargetNamespace(), bname);
         }
-        Binding binding = definition.createBinding();
+        Binding binding = rootDefinition.createBinding();
         binding.setPortType(portType);
         binding.setQName(bqname);
 
@@ -200,14 +250,14 @@
             BindingType bindingType = (BindingType)
                 extReg.createExtension(Binding.class, CorbaConstants.NE_CORBA_BINDING);
             bindingType.setRepositoryID(CorbaConstants.REPO_STRING
-                                        + portType.getQName().getLocalPart().replace('.', '/')
+                                        + scopedPortTypeName.replace('.', '/')
                                         + CorbaConstants.IDL_VERSION);
             binding.addExtensibilityElement(bindingType);
         } catch (WSDLException ex) {
             throw new RuntimeException(ex);
         }
         binding.setUndefined(false);
-        definition.addBinding(binding);
+        rootDefinition.addBinding(binding);
         return binding;
     }
 
@@ -223,44 +273,124 @@
         return false;
     }
     
-    private AST visitInterfaceInheritanceSpec(AST interfaceInheritanceSpecNode, Binding binding) {
+    private AST visitInterfaceInheritanceSpec(AST interfaceInheritanceSpecNode, Binding binding,
+                                              Scope childScope) {
         // <interface_inheritance_spec> ::= ":" <interface_name> { "," <interface_name> }*
-        
-        Scope inheritanceScope = null;
+                
         AST interfaceNameNode = interfaceInheritanceSpecNode.getFirstChild();
         BindingType corbaBinding = findCorbaBinding(binding);
+        List<Scope> inheritedScopes = new ArrayList<Scope>();
+        
         while (interfaceNameNode != null) {            
-            // TODO
-            // add interface inheritance information to XmlSchema and CorbaTypeMap here  
-            
             //check for porttypes in current & parent scopes
+            Scope interfaceScope = null;
             PortType intf = null;
             if (ScopedNameVisitor.isFullyScopedName(interfaceNameNode)) {
-                Scope interfaceScope = ScopedNameVisitor.getFullyScopedName(new Scope(), interfaceNameNode);
-                intf = findPortType(interfaceScope.toString());
+                interfaceScope = ScopedNameVisitor.getFullyScopedName(new Scope(), interfaceNameNode);
+                intf = findPortType(interfaceScope);
             }
             Scope currentScope = getScope();
             while (intf == null
                    && currentScope != currentScope.getParent()) {
-                Scope interfaceScope;
                 if (ScopedNameVisitor.isFullyScopedName(interfaceNameNode)) {
                     interfaceScope = ScopedNameVisitor.getFullyScopedName(currentScope, interfaceNameNode);
                 } else {
                     interfaceScope = new Scope(currentScope, interfaceNameNode.toString());
                 }
-                intf = findPortType(interfaceScope.toString());
+                intf = findPortType(interfaceScope);
                 currentScope = currentScope.getParent();
             }
             
             if (intf == null) {
+                if (ScopedNameVisitor.isFullyScopedName(interfaceNameNode)) {
+                    interfaceScope = ScopedNameVisitor.getFullyScopedName(new Scope(), interfaceNameNode);
+                } else {
+                    interfaceScope = new Scope(new Scope(), interfaceNameNode);
+                }
+                intf = findPortType(interfaceScope);
+            }
+
+            if (intf == null) {
                 throw new RuntimeException("[InterfaceVisitor] Unknown Interface: "
                                            + interfaceNameNode.toString());
             }
-            BindingType inheritedCorbaBinding = findCorbaBinding(findBinding(intf));
+
+            Scope defnScope = interfaceScope.getParent();
+            Definition defn = manager.getWSDLDefinition(mapper.map(defnScope));
+            inheritedScopes.add(interfaceScope);
+            
+            if (defn != null && !defn.getTargetNamespace().equals(definition.getTargetNamespace())) {
+                String key = defnScope.toString("_");
+                String fileName = getWsdlVisitor().getOutputDir()
+                    + System.getProperty("file.separator")
+                    + key;
+                manager.addWSDLDefinitionImport(definition,
+                                                defn,
+                                                key,
+                                                fileName);
+            }                        
+            
+            Binding inheritedBinding = findBinding(intf);
+            BindingType inheritedCorbaBinding = findCorbaBinding(inheritedBinding);
             corbaBinding.getBases().add(inheritedCorbaBinding.getRepositoryID());
+
+            //add all the operations of the inherited port type.            
+            for (Operation op : CastUtils.cast(intf.getOperations(), Operation.class)) {
+
+                //check to see all the inherited namespaces are added.
+                String inputNS = op.getInput().getMessage().getQName().getNamespaceURI();
+                manager.addWSDLDefinitionNamespace(definition, mapper.mapNSToPrefix(inputNS), inputNS);
+
+                // Make sure we import the wsdl for the input namespace
+                if (definition.getImports().get(inputNS) == null && !mapper.isDefaultMapping()
+                    && !definition.getTargetNamespace().equals(inputNS)) {
+                    manager.addWSDLDefinitionImport(definition, 
+                                                    manager.getWSDLDefinition(inputNS), 
+                                                    mapper.mapNSToPrefix(inputNS), 
+                                                    manager.getImportedWSDLDefinitionFile(inputNS));
+                }
+
+                String outputNS = op.getOutput().getMessage().getQName().getNamespaceURI();
+                manager.addWSDLDefinitionNamespace(definition, mapper.mapNSToPrefix(outputNS), outputNS);
+
+                // Make sure we import the wsdl for the output namespace
+                if (definition.getImports().get(outputNS) == null && !mapper.isDefaultMapping()
+                    && !definition.getTargetNamespace().equals(outputNS)) {
+                    manager.addWSDLDefinitionImport(definition, 
+                                                    manager.getWSDLDefinition(outputNS), 
+                                                    mapper.mapNSToPrefix(outputNS), 
+                                                    manager.getImportedWSDLDefinitionFile(outputNS));
+                }
+                
+                for (Iterator<Fault> faults = op.getFaults().values().iterator(); faults.hasNext();) {
+                    String faultNS = faults.next().getMessage().getQName().getNamespaceURI();
+                    manager.addWSDLDefinitionNamespace(definition, mapper.mapNSToPrefix(faultNS), faultNS);
+                    // Make sure we import the wsdl for the fault namespace
+                    if (definition.getImports().get(faultNS) == null && !mapper.isDefaultMapping()
+                        && !definition.getTargetNamespace().equals(faultNS)) {
+                        manager.addWSDLDefinitionImport(definition,
+                                                        manager.getWSDLDefinition(faultNS), 
+                                                        mapper.mapNSToPrefix(faultNS), 
+                                                        manager.getImportedWSDLDefinitionFile(faultNS));
+                    }
+                }
+                
+                portType.addOperation(op);
+            }
+
+            //add all the binding extensions of the inherited corba binding
+            for (Iterator<BindingOperation> it = inheritedBinding.getBindingOperations().iterator();
+                 it.hasNext();) {
+                binding.addBindingOperation(it.next());
+            }
             interfaceNameNode = interfaceNameNode.getNextSibling();
         }
         
+        if ((!inheritedScopes.isEmpty()) 
+            && (wsdlVisitor.getTreeMap() != null)) {
+            wsdlVisitor.getTreeMap().put(childScope, inheritedScopes);             
+        }
+        
         return interfaceInheritanceSpecNode.getNextSibling();
     }
     
@@ -276,13 +406,24 @@
     }
 
 
-    private PortType findPortType(String intfName) {
-        QName name = new QName(definition.getTargetNamespace(), intfName);
-        return definition.getPortType(name);
+    private PortType findPortType(Scope intfScope) {
+        String tns = mapper.map(intfScope.getParent());
+        String intfName = intfScope.toString();
+        Definition defn = definition;
+        if (tns != null) {           
+            defn = manager.getWSDLDefinition(tns);
+            intfName = intfScope.tail();
+        }
+        if (defn != null) {
+            tns = defn.getTargetNamespace();
+            QName name = new QName(tns, intfName);
+            return defn.getPortType(name);
+        }
+        return null;
     }
 
     private Binding findBinding(PortType intf) {
-        Object[] bindings = definition.getBindings().values().toArray();   
+        Object[] bindings = rootDefinition.getBindings().values().toArray();   
         for (int i = 0; i < bindings.length; i++) {
             Binding binding = (Binding) bindings[i];
             if (binding.getPortType().getQName().equals(intf.getQName())) {

Modified: incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/PrimitiveTypesVisitor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/PrimitiveTypesVisitor.java?rev=608894&r1=608893&r2=608894&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/PrimitiveTypesVisitor.java (original)
+++ incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/PrimitiveTypesVisitor.java Fri Jan  4 07:47:28 2008
@@ -15,27 +15,27 @@
  * KIND, either express or implied. See the License for the
  * specific language governing permissions and limitations
  * under the License.
-*/
+ */
 
 package org.apache.yoko.tools.processors.idl;
 
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.wsdl.Definition;
 import javax.xml.namespace.QName;
 
 import antlr.collections.AST;
 
+import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.ws.commons.schema.XmlSchemaCollection;
 import org.apache.ws.commons.schema.XmlSchemaType;
-import org.apache.yoko.tools.common.CorbaPrimitiveMap;
 import org.apache.yoko.tools.common.XmlSchemaPrimitiveMap;
 import org.apache.yoko.wsdl.CorbaConstants;
 import org.apache.yoko.wsdl.CorbaTypeImpl;
 
 public class PrimitiveTypesVisitor implements Visitor {
 
-    private static CorbaPrimitiveMap corbaPrimitiveMap = new CorbaPrimitiveMap();
     private static XmlSchemaPrimitiveMap xmlSchemaPrimitiveMap = new XmlSchemaPrimitiveMap();
     
     private static final List<Integer> PRIMITIVE_TYPES = new ArrayList<Integer>();
@@ -56,10 +56,13 @@
 
     private XmlSchemaType schemaType;
     private CorbaTypeImpl corbaType;
-    private Scope scope;   
+    private Scope scope;
     private XmlSchemaCollection schemas;
     
-    public PrimitiveTypesVisitor(Scope scopeRef, XmlSchemaCollection xmlSchemas) {
+    public PrimitiveTypesVisitor(Scope scopeRef,
+                                 Definition defn,
+                                 XmlSchema schemaRef,
+                                 XmlSchemaCollection xmlSchemas) {
         scope = scopeRef;
         schemas = xmlSchemas;
     }

Added: incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/SchemaDeferredAction.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/SchemaDeferredAction.java?rev=608894&view=auto
==============================================================================
--- incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/SchemaDeferredAction.java (added)
+++ incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/SchemaDeferredAction.java Fri Jan  4 07:47:28 2008
@@ -0,0 +1,27 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.yoko.tools.processors.idl;
+
+import org.apache.ws.commons.schema.XmlSchemaType;
+import org.apache.yoko.wsdl.CorbaTypeImpl;
+
+public interface SchemaDeferredAction extends DeferredAction {
+    void execute(XmlSchemaType stype, CorbaTypeImpl ctype);
+}

Propchange: incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/SchemaDeferredAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/SchemaDeferredAction.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/Scope.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/Scope.java?rev=608894&r1=608893&r2=608894&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/Scope.java (original)
+++ incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/Scope.java Fri Jan  4 07:47:28 2008
@@ -15,7 +15,7 @@
  * KIND, either express or implied. See the License for the
  * specific language governing permissions and limitations
  * under the License.
-*/
+ */
 
 package org.apache.yoko.tools.processors.idl;
 
@@ -27,7 +27,7 @@
 
 import org.apache.yoko.wsdl.CorbaConstants;
 
-public final class Scope {
+public final class Scope implements Comparable {
 
     private static final String SEPARATOR = ".";
     private List<String> scope;
@@ -38,9 +38,23 @@
         parent = this;
     }
     
+    public Scope(String scopes, String separator) {
+        java.util.StringTokenizer tokens = new java.util.StringTokenizer(scopes, separator);
+        Scope rootScope = new Scope();
+        Scope prevScope = rootScope.parent;
+        scope = rootScope.scope;
+        parent = this;
+        while (tokens.hasMoreTokens()) {
+            String token = tokens.nextToken();
+            parent = prevScope;
+            prevScope = new Scope(prevScope, token);
+            scope.add(token);
+        }
+    }
+    
     public Scope(Scope containingScope) {
         scope = new ArrayList<String>(containingScope.scope);
-        parent = containingScope;
+        parent = containingScope.getParent();
     }
     
     public Scope(Scope containingScope, String str) {
@@ -78,7 +92,7 @@
         return parent;
     }
     
-    private String toString(String separator) {
+    public String toString(String separator) {
         StringBuffer result = new StringBuffer();
         Iterator<String> it = scope.iterator();
         while (it.hasNext()) {
@@ -101,5 +115,28 @@
         result.append(CorbaConstants.IDL_VERSION);
         return result.toString();
     }
-    
+
+    public boolean equals(Object otherScope) {
+        if (otherScope != null && otherScope instanceof Scope) {
+            return toString().equals(((Scope)otherScope).toString());   
+        } else {
+            return false;
+        }
+    }
+
+    public int hashCode() {
+        return toString().hashCode();
+    }
+
+    public int compareTo(Object otherScope) {
+        if (otherScope == null) {
+            throw new RuntimeException("Cannot compare a null object");
+        }
+        if (otherScope instanceof Scope) {
+            return toString().compareTo(otherScope.toString());
+        } else {
+            throw new ClassCastException("Scope class expected but found "
+                                         + otherScope.getClass().getName());
+        }
+    }
 }

Modified: incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/ScopeNameCollection.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/ScopeNameCollection.java?rev=608894&r1=608893&r2=608894&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/ScopeNameCollection.java (original)
+++ incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/ScopeNameCollection.java Fri Jan  4 07:47:28 2008
@@ -15,7 +15,7 @@
  * KIND, either express or implied. See the License for the
  * specific language governing permissions and limitations
  * under the License.
-*/
+ */
 
 package org.apache.yoko.tools.processors.idl;
 
@@ -24,7 +24,7 @@
 
 public final class ScopeNameCollection  {
     
-    Map scopedNames = new HashMap();
+    Map<String, Scope> scopedNames = new HashMap<String, Scope>();
     
     public void add(Scope scope) {
         scopedNames.put(scope.toString(), scope);

Modified: incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/ScopedNameVisitor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/ScopedNameVisitor.java?rev=608894&r1=608893&r2=608894&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/ScopedNameVisitor.java (original)
+++ incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/ScopedNameVisitor.java Fri Jan  4 07:47:28 2008
@@ -15,11 +15,13 @@
  * KIND, either express or implied. See the License for the
  * specific language governing permissions and limitations
  * under the License.
-*/
+ */
 
 package org.apache.yoko.tools.processors.idl;
 
+import java.util.ArrayList;
 import java.util.Iterator;
+import java.util.List;
 
 import javax.wsdl.Definition;
 import javax.xml.namespace.QName;
@@ -27,7 +29,9 @@
 import antlr.collections.AST;
 
 import org.apache.schemas.yoko.bindings.corba.Alias;
+import org.apache.schemas.yoko.bindings.corba.Anonarray;
 import org.apache.schemas.yoko.bindings.corba.Anonsequence;
+import org.apache.schemas.yoko.bindings.corba.Array;
 import org.apache.schemas.yoko.bindings.corba.Sequence;
 import org.apache.schemas.yoko.bindings.corba.TypeMappingType;
 import org.apache.ws.commons.schema.XmlSchema;
@@ -43,8 +47,10 @@
     private static XmlSchemaPrimitiveMap xmlSchemaPrimitiveMap = new XmlSchemaPrimitiveMap();          
 
     public ScopedNameVisitor(Scope scope,
+                             Definition defn,
+                             XmlSchema schemaRef,
                              WSDLASTVisitor wsdlVisitor) {
-        super(scope, wsdlVisitor);             
+        super(scope, defn, schemaRef, wsdlVisitor);             
     }
     
     public void setExceptionMode(boolean value) {
@@ -52,20 +58,22 @@
     }
     
     public static boolean accept(Scope scope,
-                                 XmlSchemaCollection schemas,
-                                 XmlSchema schema,
-                                 TypeMappingType typeMap,
-                                 Definition def,
+                                 Definition defn,
+                                 XmlSchema schemaRef,
                                  AST node,                                 
                                  WSDLASTVisitor wsdlVisitor) {
         boolean result = false;
         if (PrimitiveTypesVisitor.accept(node)) {
             result = true; 
-        } else if (isforwardDeclared(scope, schema, node, getScopedNames(), wsdlVisitor)) {
+        } else if (isforwardDeclared(scope, node, wsdlVisitor)) {
+            result = true;          
+        } else if (ObjectReferenceVisitor.accept(scope,
+                                                 schemaRef,
+                                                 defn,
+                                                 node,
+                                                 wsdlVisitor)) {
             result = true;
-        } else if (ObjectReferenceVisitor.accept(scope, schema, def, node)) {
-            result = true;
-        } else if (findSchemaType(scope, schemas, schema, typeMap, node, null)) {
+        } else if (findSchemaType(scope, defn, schemaRef, node, wsdlVisitor, null)) {
             result = true;
         }
         return result;
@@ -78,33 +86,39 @@
 
         XmlSchemaType stype = null;
         CorbaTypeImpl ctype = null;        
-        
         if (PrimitiveTypesVisitor.accept(node)) {
             // primitive type            
-            PrimitiveTypesVisitor primitiveVisitor = new PrimitiveTypesVisitor(null, schemas);
+            PrimitiveTypesVisitor primitiveVisitor =
+                new PrimitiveTypesVisitor(null, definition, schema, schemas);
             primitiveVisitor.visit(node);
             
             stype = primitiveVisitor.getSchemaType();
             ctype = primitiveVisitor.getCorbaType();            
-        } else if (isforwardDeclared(getScope(), schema, node, scopedNames, wsdlVisitor)) {
+        } else if (isforwardDeclared(getScope(), node, wsdlVisitor)) {
             // forward declaration
-            Scope scope = forwardDeclared(getScope(), schema, node, scopedNames, wsdlVisitor);
+            Scope scope = forwardDeclared(getScope(),
+                                          definition,
+                                          schema,
+                                          node,
+                                          wsdlVisitor);
             setFullyQualifiedName(scope);
             // how will we create the corbatype ????
-        } else if (ObjectReferenceVisitor.accept(getScope(), schema, wsdlVisitor.getDefinition(), node)) {
+        } else if (ObjectReferenceVisitor.accept(getScope(), schema, definition, node, wsdlVisitor)) {
             ObjectReferenceVisitor objRefVisitor = new ObjectReferenceVisitor(getScope(),
+                                                                              definition,
+                                                                              schema,
                                                                               wsdlVisitor);
             objRefVisitor.visit(node);
 
             stype = objRefVisitor.getSchemaType();
-            ctype = objRefVisitor.getCorbaType();            
+            ctype = objRefVisitor.getCorbaType();           
         } else {
             VisitorTypeHolder holder = new VisitorTypeHolder();
             boolean found = findSchemaType(getScope(),
-                                           schemas,
+                                           definition,
                                            schema,
-                                           typeMap,
                                            node,
+                                           wsdlVisitor,
                                            holder);
             if (found) {
                 ctype = holder.getCorbaType();
@@ -123,9 +137,10 @@
         
     }
 
-    private static CorbaTypeImpl getCorbaSchemaType(XmlSchema schema,
+    private static CorbaTypeImpl getCorbaSchemaType(XmlSchema xmlSchema,
                                                     TypeMappingType typeMap,
-                                                    XmlSchemaType stype) {       
+                                                    XmlSchemaType stype,
+                                                    Scope scopedName) {       
         CorbaTypeImpl ctype = null;
         if (stype.getQName().equals(Constants.XSD_STRING)) {
             ctype = new CorbaTypeImpl();
@@ -133,30 +148,18 @@
             ctype.setQName(CorbaConstants.NT_CORBA_STRING);
             ctype.setType(Constants.XSD_STRING);
         } else {                    
-            QName qname = null; 
-            // Revisit: Exceptions are treated as a special case.
-            // we should be able to do this in a better way.
-            if (exceptionMode) {
-                String name = null;
-                if (stype.getName().endsWith("Type")) {
-                    name = stype.getName().substring(0, stype.getName().length() - 4);
-                } else {
-                    name = stype.getName();
-                }
-                qname = new QName(schema.getTargetNamespace(), name);                     
-            } else {
-                qname = stype.getQName();      
-            }
-            ctype = findCorbaType(typeMap, qname);
+            QName qname = stype.getQName();
+            ctype = findCorbaTypeForSchemaType(typeMap, qname, scopedName);
         }
         return ctype;
     }
          
-    protected static boolean isforwardDeclared(Scope scope, XmlSchema schema, AST node,
-                                               ScopeNameCollection scopedNames, WSDLASTVisitor wsdlVisitor) {
+    protected static boolean isforwardDeclared(Scope scope, AST node, WSDLASTVisitor wsdlVisitor) {
         boolean isForward = false;
         Scope currentScope = scope;
 
+        ScopeNameCollection scopedNames = wsdlVisitor.getScopedNames();
+
         // Check for forward declaration from local scope outwards
         if ((node.getFirstChild() == null)
             || (node.getFirstChild() != null && node.getFirstChild().getType() != IDLTokenTypes.SCOPEOP)) {
@@ -191,12 +194,15 @@
     }
      
     
-    protected static Scope forwardDeclared(Scope scope, XmlSchema schema, AST node,
-                                           ScopeNameCollection scopedNames, 
+    protected static Scope forwardDeclared(Scope scope,
+                                           Definition defn,
+                                           XmlSchema schemaRef,
+                                           AST node,
                                            WSDLASTVisitor wsdlVisitor) {
         //XmlSchemaType result = null;
         Scope result = null;
         Scope currentScope = scope;
+        ScopeNameCollection scopedNames = wsdlVisitor.getScopedNames();
 
         // Check for forward declaration from local scope outwards
         if ((node.getFirstChild() == null)
@@ -210,9 +216,14 @@
                 }
 
                 if (scopedNames.getScope(scopedName) != null) {
-                    if (ObjectReferenceVisitor.accept(scope, schema, wsdlVisitor.getDefinition(), node)) {
+                    XmlSchema xmlSchema = schemaRef;
+                    String tns = wsdlVisitor.getModuleToNSMapper().map(scopedName.getParent());
+                    if (tns != null) {
+                        xmlSchema = wsdlVisitor.getManager().getXmlSchema(tns);
+                    }
+                    if (ObjectReferenceVisitor.accept(scope, xmlSchema, defn, node, wsdlVisitor)) {
                         // checks if its a forward
-                        Visitor visitor = new ObjectReferenceVisitor(scope, wsdlVisitor);
+                        Visitor visitor = new ObjectReferenceVisitor(scope, defn, xmlSchema, wsdlVisitor);
                         visitor.visit(node);                    
                     }
                     result = scopedName;
@@ -228,29 +239,33 @@
             } else {
                 scopedName = new Scope(new Scope(), node);
             }
-            if (scopedNames.getScope(scopedName) != null) { 
-                if (ObjectReferenceVisitor.accept(scope, schema, wsdlVisitor.getDefinition(), node)) {
+            if (scopedNames.getScope(scopedName) != null) {
+                XmlSchema xmlSchema = schemaRef;
+                String tns = wsdlVisitor.getModuleToNSMapper().map(scopedName.getParent());
+                if (tns != null) {
+                    xmlSchema = wsdlVisitor.getManager().getXmlSchema(tns);
+                }
+                if (ObjectReferenceVisitor.accept(scope, xmlSchema, defn, node, wsdlVisitor)) {
                     // checks if an object ref
-                    Visitor visitor = new ObjectReferenceVisitor(scope, wsdlVisitor);
+                    Visitor visitor = new ObjectReferenceVisitor(scope, defn, xmlSchema, wsdlVisitor);
                     visitor.visit(node);
                 }
                 result = scopedName;
             }
         }
-
         return result;
     }
     
     
     protected static boolean findSchemaType(Scope scope,
-                                            XmlSchemaCollection schemas,
-                                            XmlSchema schema,
-                                            TypeMappingType typeMap,
+                                            Definition defn,
+                                            XmlSchema schemaRef,
                                             AST node,
+                                            WSDLASTVisitor wsdlVisitor,
                                             VisitorTypeHolder holder) {
                                                 
         boolean result = false;
-        Scope currentScope = scope;
+        Scope currentScope = scope;        
         
         // checks from innermost local scope outwards
         if ((node.getFirstChild() == null)
@@ -267,82 +282,263 @@
                 } else {
                     scopedName = new Scope(currentScope, node);
                 }
-                
-                result = findNonSchemaType(schemas, schema, typeMap, scopedName.toString(), holder);
-                if (!result) {
-                    QName qname = null;
+                result = findScopeSchemaType(scopedName, schemaRef, wsdlVisitor, holder);
 
-                    // Exceptions are treated as a special case as for the
-                    // doc/literal style
-                    // in the schema we will have an element and a complextype
-                    // so the name
-                    // and the typename will be different.
-                    if (exceptionMode) {
-                        qname = new QName(schema.getTargetNamespace(), scopedName.toString() + "Type");
-                    } else {
-                        qname = new QName(schema.getTargetNamespace(), scopedName.toString());
-                    }
-                    XmlSchemaType stype = schema.getTypeByName(qname);
-                    if (stype == null) {
-                        stype = schemas.getTypeByQName(qname);
-                    }
-                    if (stype != null) {
-                        result = true;
-                        if (holder != null) {
-                            holder.setSchemaType(stype);
-                            holder.setCorbaType(getCorbaSchemaType(schema, typeMap, stype));
-                        }
-                    }
+                // Search inherited scopes for the type        
+                if (!result) {
+                    result = findSchemaTypeInInheritedScope(scope, defn, schemaRef,
+                                                            node, wsdlVisitor, holder);
+                    
                 }
                 currentScope = currentScope.getParent();
             }
-
         }
+        
+        
+        
         if (!result) {
             // Global scope is our last chance to resolve the node
-            Scope scopedName = scope;
-            String name = node.toString();
-            if (isFullyScopedName(node)) {
-                scopedName = getFullyScopedName(new Scope(), node);
-                name = scopedName.toString();
+            result = findSchemaTypeInGlobalScope(scope,
+                                                 defn,
+                                                 schemaRef,
+                                                 node,
+                                                 wsdlVisitor,
+                                                 holder);
+        }
+        return result;
+    }
+    
+    private static boolean findSchemaTypeInGlobalScope(Scope scope,
+                                                       Definition defn,
+                                                       XmlSchema currentSchema,
+                                                       AST node,
+                                                       WSDLASTVisitor wsdlVisitor,
+                                                       VisitorTypeHolder holder) {
+        XmlSchemaCollection schemas = wsdlVisitor.getSchemas();
+        TypeMappingType typeMap = wsdlVisitor.getTypeMap();
+        ModuleToNSMapper mapper = wsdlVisitor.getModuleToNSMapper();
+        WSDLSchemaManager manager = wsdlVisitor.getManager();
+        
+        Scope scopedName = scope;
+        String name = node.toString();
+        if (isFullyScopedName(node)) {
+            scopedName = getFullyScopedName(new Scope(), node);
+            name = scopedName.toString();
+        }
+        boolean result = findNonSchemaType(name, wsdlVisitor, holder);
+        if (!result) {
+            XmlSchema xmlSchema = currentSchema;
+            QName qname = null;
+            String tns = mapper.map(scopedName.getParent());
+            if (tns != null) {
+                xmlSchema = manager.getXmlSchema(tns);
+                if (xmlSchema != null) {
+                    qname = new QName(xmlSchema.getTargetNamespace(), scopedName.tail());
+                }
+            } else {
+                qname = new QName(xmlSchema.getTargetNamespace(), name);
             }
-            
-            result = findNonSchemaType(schemas, schema, typeMap, name, holder);
-            if (!result) {
-                QName qname = new QName(schema.getTargetNamespace(), name);
-
+            XmlSchemaType stype = null;
+            if (qname != null) {
                 // Exceptions are treated as a special case as above
                 if (exceptionMode) {
-                    qname = new QName(schema.getTargetNamespace(), qname.getLocalPart() + "Type");
+                    qname = new QName(xmlSchema.getTargetNamespace(), qname.getLocalPart() + "Type");
                 }
-                XmlSchemaType stype = schema.getTypeByName(qname);
+                stype = xmlSchema.getTypeByName(qname);
                 if (stype == null) {
                     stype = schemas.getTypeByQName(qname);
                 }
-                if (stype != null) {
-                    result = true;
-                    if (holder != null) {
-                        holder.setSchemaType(stype);
-                        holder.setCorbaType(getCorbaSchemaType(schema, typeMap, stype));
+            }
+            if (stype != null) {
+                result = true;
+                if (holder != null) {
+                    holder.setSchemaType(stype);
+                    holder.setCorbaType(getCorbaSchemaType(xmlSchema, typeMap, stype, scopedName));
+                    //add a xmlschema import
+                    if (!currentSchema.getTargetNamespace().equals(xmlSchema.getTargetNamespace())) {
+                        String importFile = wsdlVisitor.getOutputDir()
+                            + System.getProperty("file.separator")
+                            + scopedName.getParent().toString("_");
+                        manager.addXmlSchemaImport(currentSchema, xmlSchema, importFile);
                     }
                 }
             }
         }
         return result;
     }
+
     
-    public static CorbaTypeImpl findCorbaType(TypeMappingType typeMap, QName schemaTypeName) {
+    // Searches all the inherited interfaces for the type.
+    private static boolean findSchemaTypeInInheritedScope(Scope scope, Definition defn, XmlSchema schemaRef,
+                                                          AST node, WSDLASTVisitor wsdlVisitor,
+                                                          VisitorTypeHolder holder) {
+
+        boolean result = false;                
+        List<Scope> baseScopes = (List<Scope>)wsdlVisitor.getTreeMap().get(scope);
+        if (baseScopes != null) {
+            List<Scope> scopeList = new ArrayList<Scope>();
+            for (Scope scopeName : baseScopes) {
+                scopeList.add(scopeName);
+            }
+            result = findSchemaTypeInBaseScope(scopeList, scope, defn, 
+                                               schemaRef, node, wsdlVisitor, holder);
+        }
+        return result;
+    }
+    
+    // Does a breath depth search first.
+    public static boolean findSchemaTypeInBaseScope(List<Scope> scopeList, Scope scope, 
+                                                    Definition defn, XmlSchema schemaRef,
+                                                    AST node, WSDLASTVisitor wsdlVisitor,
+                                                    VisitorTypeHolder holder) {
+        List<Scope> inheritedList = new ArrayList<Scope>();
+        boolean result = false;
+        for (Scope scopeName : scopeList) {
+            inheritedList.add(scopeName);
+        }        
+        
+        if (scopeList != null) {            
+            Iterator iterator = scopeList.iterator();
+            while (iterator.hasNext()) {
+                Scope inheritScope = (Scope)iterator.next();
+
+                Scope scopedName = new Scope(inheritScope, node);
+                result = findScopeSchemaType(scopedName, schemaRef, wsdlVisitor, holder);
+                if (!result) {
+                    inheritedList.remove(inheritScope);
+                    List<Scope> scopes = (List<Scope>)wsdlVisitor.getTreeMap().get(inheritScope);
+                    if (scopes != null) {
+                        for (Scope scopeName : scopes) {
+                            inheritedList.add(scopeName);
+                        }
+                    }
+                } else {
+                    return result;
+                }
+            }
+
+            if (!inheritedList.isEmpty()) {
+                List<Scope> baseList = new ArrayList<Scope>();
+                for (Scope scopeName : inheritedList) {
+                    baseList.add(scopeName);
+                }
+
+                result = findSchemaTypeInBaseScope(baseList, scope, defn, schemaRef, node, wsdlVisitor,
+                                                   holder);
+            }
+        }
+        return result;
+    }
+    
+    // Searches this scope for the schema type.
+    private static boolean findScopeSchemaType(Scope scopedName, XmlSchema schemaRef, 
+                                           WSDLASTVisitor wsdlVisitor, 
+                                           VisitorTypeHolder holder) {
+        
+        XmlSchemaCollection schemas = wsdlVisitor.getSchemas();
+        TypeMappingType typeMap = wsdlVisitor.getTypeMap();
+        ModuleToNSMapper mapper = wsdlVisitor.getModuleToNSMapper();
+        WSDLSchemaManager manager = wsdlVisitor.getManager();
+
+        boolean result = findNonSchemaType(scopedName.toString(), wsdlVisitor, holder);
+        if (!result) {
+            QName qname = null;
+            XmlSchema xmlSchema = schemaRef;
+            String tns = wsdlVisitor.getModuleToNSMapper().map(scopedName.getParent());
+            if (tns != null) {
+                xmlSchema = wsdlVisitor.getManager().getXmlSchema(tns);
+            }
+            XmlSchemaType stype = null;
+            if (xmlSchema != null) {
+                // Exceptions are treated as a special case as for the
+                // doc/literal style
+                // in the schema we will have an element and a complextype
+                // so the name
+                // and the typename will be different.
+
+                String scopedNameString = null;
+                if (mapper.isDefaultMapping()) {
+                    scopedNameString = scopedName.toString();
+                } else {
+                    scopedNameString = scopedName.tail();
+                }
+
+                if (exceptionMode) {
+                    qname = new QName(xmlSchema.getTargetNamespace(), scopedNameString + "Type");
+                } else {
+                    qname = new QName(xmlSchema.getTargetNamespace(), scopedNameString);
+                }
+
+                stype = xmlSchema.getTypeByName(qname);
+                if (stype == null) {
+                    stype = schemas.getTypeByQName(qname);
+                }
+            }
+            if (stype != null) {
+                result = true;
+            }
+            if (result && holder != null) {
+                holder.setSchemaType(stype);
+                holder.setCorbaType(getCorbaSchemaType(xmlSchema, typeMap, stype, scopedName));
+                // add a xmlschema import
+                if (!schemaRef.getTargetNamespace().equals(xmlSchema.getTargetNamespace())) {
+                    String importFile = wsdlVisitor.getOutputDir() + System.getProperty("file.separator")
+                                        + scopedName.getParent().toString("_");
+                    manager.addXmlSchemaImport(schemaRef, xmlSchema, importFile);
+                }
+            }
+        }
+        return result;
+    }
+    
+    
+    
+    public static CorbaTypeImpl findCorbaTypeForSchemaType(TypeMappingType typeMap, 
+                                                           QName schemaTypeName,
+                                                           Scope scopedName) {
+        CorbaTypeImpl result = null;
+        Iterator corbaTypes = typeMap.getStructOrExceptionOrUnion().iterator();
+        while (corbaTypes.hasNext()) {
+            CorbaTypeImpl type = (CorbaTypeImpl) corbaTypes.next();         
+            if ((type instanceof Sequence)
+                || (type instanceof Array)
+                || (type.getType() == null)
+                || (type instanceof Anonsequence)
+                || (type instanceof Anonarray)) {
+                //REVISIT, cannot compare the type because they are incorrect
+                if (type.getQName().getLocalPart().equals(schemaTypeName.getLocalPart())) {
+                    result = type;
+                    break;
+                }               
+                
+                // If we are using the module to ns mapping, then the name of the type in schema
+                // and in the typemap are actually different.  We should then compare with the scoped
+                // name that we are given.
+                if (type.getQName().getLocalPart().equals(scopedName.toString())) {
+                    result = type;
+                    break;
+                }
+
+            } else if (schemaTypeName.equals(type.getType())) {
+                result = type;
+                break;
+            }
+        }
+        return result;
+    }  
+
+    public static CorbaTypeImpl findCorbaType(TypeMappingType typeMap, QName typeName) {
         CorbaTypeImpl result = null;
         Iterator corbaTypes = typeMap.getStructOrExceptionOrUnion().iterator();
         while (corbaTypes.hasNext()) {
             CorbaTypeImpl type = (CorbaTypeImpl) corbaTypes.next();
-            if (type.getQName().getLocalPart().equals(schemaTypeName.getLocalPart())) {
+            if (type.getQName().equals(typeName)) {
                 result = type;
                 break;
             }
         }
         return result;
-    }       
+    }     
     
     protected static boolean isFullyScopedName(AST node) {
         if (node.getType() == IDLTokenTypes.IDENT) {
@@ -365,47 +561,28 @@
         AST scopeNode = node.getFirstChild();
         if (node.getFirstChild().getType() == IDLTokenTypes.IDENT) {
             scopedName = new Scope(scopedName, scopeNode);
-        }                                
+        }
         while (scopeNode.getNextSibling() != null) {
             scopeNode = scopeNode.getNextSibling(); 
-            scopedName = new Scope(scopedName, scopeNode);                            
-        }   
-        
+            scopedName = new Scope(scopedName, scopeNode);
+        }
         return scopedName;
     }
 
-    protected static boolean findNonSchemaType(XmlSchemaCollection schemas,
-                                               XmlSchema schema,
-                                               TypeMappingType typeMap,
-                                               String name,
+    protected static boolean findNonSchemaType(String name,
+                                               WSDLASTVisitor wsdlVisitor,
                                                VisitorTypeHolder holder) {
         boolean result = false;
+        TypeMappingType typeMap = wsdlVisitor.getTypeMap();
+        XmlSchemaCollection schemas = wsdlVisitor.getSchemas();
+
         QName qname = new QName(typeMap.getTargetNamespace(), name);
         CorbaTypeImpl corbaType = findCorbaType(typeMap, qname);
         if (corbaType != null) {
             if (corbaType instanceof Alias) {
                 result = true;
                 if (holder != null) {
-                    holder.setCorbaType(corbaType);
-                    Alias alias = (Alias) corbaType;
-                    //loop through alias base types, till you get a non-alias corba type
-                    CorbaTypeImpl type = findCorbaType(typeMap, alias.getBasetype());
-                    while ((type != null) && (type instanceof Alias)) {
-                        alias = (Alias) type;
-                        type = findCorbaType(typeMap, alias.getBasetype());
-                    }
-                    QName tname;
-                    if (type == null) {
-                        //it must be a primitive type
-                        tname = xmlSchemaPrimitiveMap.get(alias.getBasetype());
-                    } else {
-                        tname = type.getType();
-                    }         
-                    XmlSchemaType stype = schemas.getTypeByQName(tname);
-                    if (stype == null) {
-                        stype = schema.getTypeByName(tname);
-                    }
-                    holder.setSchemaType(stype);
+                    populateAliasSchemaType(corbaType, wsdlVisitor, holder);
                 }
             } else if (((corbaType instanceof Sequence) || (corbaType instanceof Anonsequence))
                        && ((corbaType.getType().equals(Constants.XSD_BASE64))
@@ -419,6 +596,38 @@
             }
         }
         return result;
+    }
+
+    protected static void populateAliasSchemaType(CorbaTypeImpl corbaType,
+                                                  WSDLASTVisitor wsdlVisitor,
+                                                  VisitorTypeHolder holder) {
+        XmlSchemaCollection schemas = wsdlVisitor.getSchemas();
+        TypeMappingType typeMap = wsdlVisitor.getTypeMap();
+        holder.setCorbaType(corbaType);
+        Alias alias = (Alias) corbaType;
+        //loop through alias base types, till you get a non-alias corba type
+        CorbaTypeImpl type = findCorbaType(typeMap, alias.getBasetype());
+        while ((type != null) && (type instanceof Alias)) {
+            alias = (Alias) type;
+            type = findCorbaType(typeMap, alias.getBasetype());
+        }
+        QName tname;
+        if (type == null) {
+            //it must be a primitive type
+            tname = xmlSchemaPrimitiveMap.get(alias.getBasetype());
+        } else {
+            tname = type.getType();
+        }
+        XmlSchemaType stype = schemas.getTypeByQName(tname);
+        if (stype == null) {
+            XmlSchema xmlSchema = wsdlVisitor.getManager().getXmlSchema(tname.getNamespaceURI());
+            if (xmlSchema != null) {
+                stype = xmlSchema.getTypeByName(tname);
+            } else {
+                stype = wsdlVisitor.getSchema().getTypeByName(tname);
+            }
+        }
+        holder.setSchemaType(stype);
     }
         
 }

Modified: incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/SequenceDeferredAction.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/SequenceDeferredAction.java?rev=608894&r1=608893&r2=608894&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/SequenceDeferredAction.java (original)
+++ incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/SequenceDeferredAction.java Fri Jan  4 07:47:28 2008
@@ -15,7 +15,7 @@
  * KIND, either express or implied. See the License for the
  * specific language governing permissions and limitations
  * under the License.
-*/
+ */
 
 package org.apache.yoko.tools.processors.idl;
 
@@ -28,7 +28,7 @@
 import org.apache.yoko.tools.common.ReferenceConstants;
 import org.apache.yoko.wsdl.CorbaTypeImpl;
 
-public class SequenceDeferredAction extends DeferredActionBase {
+public class SequenceDeferredAction implements SchemaDeferredAction {
 
     protected Anonsequence anonSequence;
     protected Sequence sequence;
@@ -36,38 +36,33 @@
     protected XmlSchema schema;
     protected XmlSchemaCollection schemas;    
     
-    public SequenceDeferredAction(Sequence sequenceType, Anonsequence anonSequenceType, 
-                                  XmlSchemaElement elem, Scope scope) {                           
-        super(scope);
+    public SequenceDeferredAction(Sequence sequenceType,
+                                  Anonsequence anonSequenceType,
+                                  XmlSchemaElement elem) {
         anonSequence = anonSequenceType;
         sequence = sequenceType;
         element = elem;        
     }
     
-    public SequenceDeferredAction(Anonsequence anonSequenceType, Scope scope) {                           
-        super(scope);
+    public SequenceDeferredAction(Anonsequence anonSequenceType) {
         anonSequence = anonSequenceType;         
     }
     
-    public SequenceDeferredAction(Sequence sequenceType, Scope scope) {                           
-        super(scope);
+    public SequenceDeferredAction(Sequence sequenceType) {
         sequence = sequenceType;         
     }
     
-    public SequenceDeferredAction(XmlSchemaElement elem, Scope scope) {                           
-        super(scope);
+    public SequenceDeferredAction(XmlSchemaElement elem) {
         element = elem;               
     }
     
     public SequenceDeferredAction(XmlSchemaCollection xmlSchemas,
-                                  XmlSchema xmlSchema,
-                                  Scope scope) {                           
-        super(scope);
+                                  XmlSchema xmlSchema) {
         schemas = xmlSchemas;
         schema = xmlSchema;                       
     }
     
-    public void doDeferredAction(XmlSchemaType stype, CorbaTypeImpl ctype) {
+    public void execute(XmlSchemaType stype, CorbaTypeImpl ctype) {
         if (anonSequence != null) {
             anonSequence.setElemtype(ctype.getQName());
             // This is needed for recursive types
@@ -93,6 +88,7 @@
     }
         
 }
+
 
 
 

Modified: incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/SequenceVisitor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/SequenceVisitor.java?rev=608894&r1=608893&r2=608894&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/SequenceVisitor.java (original)
+++ incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/SequenceVisitor.java Fri Jan  4 07:47:28 2008
@@ -15,18 +15,19 @@
  * KIND, either express or implied. See the License for the
  * specific language governing permissions and limitations
  * under the License.
-*/
+ */
 
 package org.apache.yoko.tools.processors.idl;
 
+import javax.wsdl.Definition;
 import javax.xml.namespace.QName;
 
 import antlr.collections.AST;
 
-//import org.apache.schemas.yoko.bindings.corba.Alias;
 import org.apache.schemas.yoko.bindings.corba.Anonsequence;
 import org.apache.schemas.yoko.bindings.corba.Sequence;
 
+import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.ws.commons.schema.XmlSchemaComplexType;
 import org.apache.ws.commons.schema.XmlSchemaElement;
 import org.apache.ws.commons.schema.XmlSchemaSequence;
@@ -43,9 +44,11 @@
     private AST identifierNode;
     
     public SequenceVisitor(Scope scope,
+                           Definition defn,
+                           XmlSchema schemaRef,
                            WSDLASTVisitor wsdlVisitor,
                            AST identifierNodeRef) {
-        super(scope, wsdlVisitor);
+        super(scope, defn, schemaRef, wsdlVisitor);
         identifierNode = identifierNodeRef;
     }
     
@@ -68,6 +71,8 @@
 
         
         SimpleTypeSpecVisitor visitor = new SimpleTypeSpecVisitor(new Scope(getScope(), identifierNode),
+                                                                  definition,
+                                                                  schema,
                                                                   wsdlVisitor,
                                                                   null);
         visitor.visit(simpleTypeSpecNode);
@@ -133,7 +138,7 @@
     private XmlSchemaType generateSchemaType(XmlSchemaType stype, Scope scopedName, 
                                              long bound, Scope fullyQualifiedName) {
         XmlSchemaComplexType ct = new XmlSchemaComplexType(schema);
-        ct.setName(scopedName.toString());
+        ct.setName(mapper.mapToQName(scopedName));
         XmlSchemaSequence sequence = new XmlSchemaSequence();
         XmlSchemaElement el = new XmlSchemaElement();
         el.setName(ELEMENT_NAME);
@@ -150,8 +155,8 @@
             }
         } else {
             SequenceDeferredAction elementAction = 
-                new SequenceDeferredAction(el, fullyQualifiedName);
-            wsdlVisitor.getDeferredActions().add(elementAction); 
+                new SequenceDeferredAction(el);
+            wsdlVisitor.getDeferredActions().add(fullyQualifiedName, elementAction); 
         }
         sequence.getItems().add(el);
         ct.setParticle(sequence);
@@ -177,8 +182,8 @@
             corbaSeq.setElemtype(ctype.getQName());
         } else {
             SequenceDeferredAction seqAction = 
-                new SequenceDeferredAction(corbaSeq, fullyQualifiedName);
-            wsdlVisitor.getDeferredActions().add(seqAction);
+                new SequenceDeferredAction(corbaSeq);
+            wsdlVisitor.getDeferredActions().add(fullyQualifiedName, seqAction);
         }
         corbaSeq.setRepositoryID(scopedName.toIDLRepositoryID());
 
@@ -201,8 +206,8 @@
         result.setElemname(new QName("", ELEMENT_NAME));
         if (schemaType == null || ctype == null) {
             SequenceDeferredAction anonSeqAction = 
-                new SequenceDeferredAction(result, fullyQualifiedName);
-            wsdlVisitor.getDeferredActions().add(anonSeqAction);
+                new SequenceDeferredAction(result);
+            wsdlVisitor.getDeferredActions().add(fullyQualifiedName, anonSeqAction);
         } else {
             result.setType(schemaType.getQName());
             result.setElemtype(ctype.getQName());        
@@ -210,14 +215,15 @@
 
         // Need to create an action if the type was forward declared.
         if (schemaType != null) {
-            if (schemas.getTypeByQName(schemaType.getQName()) == null) {
+            if (schemas.getTypeByQName(schemaType.getQName()) == null 
+                && schema.getTypeByName(schemaType.getQName()) == null) {
                 schema.getItems().add(schemaType);
                 schema.addType(schemaType);
             }
         } else {
             SequenceDeferredAction anonSeqAction = 
-                new SequenceDeferredAction(schemas, schema, fullyQualifiedName);
-            wsdlVisitor.getDeferredActions().add(anonSeqAction);
+                new SequenceDeferredAction(schemas, schema);
+            wsdlVisitor.getDeferredActions().add(fullyQualifiedName, anonSeqAction);
         }
         
         // add corbaType

Modified: incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/SimpleTypeSpecVisitor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/SimpleTypeSpecVisitor.java?rev=608894&r1=608893&r2=608894&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/SimpleTypeSpecVisitor.java (original)
+++ incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/SimpleTypeSpecVisitor.java Fri Jan  4 07:47:28 2008
@@ -15,20 +15,24 @@
  * KIND, either express or implied. See the License for the
  * specific language governing permissions and limitations
  * under the License.
-*/
+ */
 
 package org.apache.yoko.tools.processors.idl;
 
+import javax.wsdl.Definition;
 import antlr.collections.AST;
+import org.apache.ws.commons.schema.XmlSchema;
 
 public class SimpleTypeSpecVisitor extends VisitorBase {
 
     private AST identifierNode;
     
     public SimpleTypeSpecVisitor(Scope scope,
+                                 Definition defn,
+                                 XmlSchema schemaRef,
                                  WSDLASTVisitor wsdlVisitor,
                                  AST identifierNodeRef) {
-        super(scope, wsdlVisitor);
+        super(scope, defn, schemaRef, wsdlVisitor);
         identifierNode = identifierNodeRef;
     }
 
@@ -50,18 +54,20 @@
         
         if (PrimitiveTypesVisitor.accept(node)) {
             // simple_type_spec - base_type_spec
-            visitor = new PrimitiveTypesVisitor(getScope(), schemas);
+            visitor = new PrimitiveTypesVisitor(getScope(), definition, schema, schemas);
             
         } else if (TemplateTypeSpecVisitor.accept(node)) {
             // simple_type_spec - template_type_spec
-            visitor = new TemplateTypeSpecVisitor(getScope(), wsdlVisitor, identifierNode);
+            visitor = new TemplateTypeSpecVisitor(getScope(),
+                                                  definition,
+                                                  schema,
+                                                  wsdlVisitor,
+                                                  identifierNode);
 
-        } else if (ScopedNameVisitor.accept(getScope(), schemas, schema, 
-                                            typeMap, wsdlVisitor.getDefinition(),
-                                            node, wsdlVisitor)) {
+        } else if (ScopedNameVisitor.accept(getScope(), definition, schema, node, wsdlVisitor)) {
 
             // simple_type_spec - scoped_name
-            visitor = new ScopedNameVisitor(getScope(), wsdlVisitor);
+            visitor = new ScopedNameVisitor(getScope(), definition, schema, wsdlVisitor);
         
         }
         

Modified: incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/StringVisitor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/StringVisitor.java?rev=608894&r1=608893&r2=608894&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/StringVisitor.java (original)
+++ incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/StringVisitor.java Fri Jan  4 07:47:28 2008
@@ -15,10 +15,11 @@
  * KIND, either express or implied. See the License for the
  * specific language governing permissions and limitations
  * under the License.
-*/
+ */
 
 package org.apache.yoko.tools.processors.idl;
 
+import javax.wsdl.Definition;
 import javax.xml.namespace.QName;
 
 import antlr.collections.AST;
@@ -27,6 +28,7 @@
 import org.apache.schemas.yoko.bindings.corba.Anonstring;
 import org.apache.schemas.yoko.bindings.corba.Anonwstring;
 
+import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.ws.commons.schema.XmlSchemaMaxLengthFacet;
 import org.apache.ws.commons.schema.XmlSchemaSimpleType;
 import org.apache.ws.commons.schema.XmlSchemaSimpleTypeRestriction;
@@ -45,9 +47,11 @@
 
     
     public StringVisitor(Scope scope,
+                         Definition definition,
+                         XmlSchema schemaRef,
                          WSDLASTVisitor wsdlVisitor,
                          AST identifierNodeRef) {
-        super(scope, wsdlVisitor);
+        super(scope, definition, schemaRef, wsdlVisitor);
         stringNode = null;
         boundNode = null;
         identifierNode = identifierNodeRef;
@@ -166,10 +170,8 @@
         simpleType.setContent(restriction);
 
         setSchemaType(simpleType);
-        
-        
-        //String anonstringName = new String("_1_" + stringScopedName.toString());
-        Scope anonstringScopedName = new Scope(getScope(), "_1_" + stringScopedName.tail());
+                       
+        Scope anonstringScopedName = new Scope(getScope(), "_Anon1_" + stringScopedName.tail());
         String anonstringName = anonstringScopedName.toString();
         CorbaTypeImpl anon = null;
         if (stringNode.getType() == IDLTokenTypes.LITERAL_string) {
@@ -229,17 +231,6 @@
         corbaString.setType(Constants.XSD_STRING);
 
         setCorbaType(corbaString);
-    }
-    
-    private String getIdentifier(AST node) {
-        String result = null;
-        if (node != null) {
-            String identifierName = node.toString();
-            if (TypesUtils.isValidIdentifier(identifierName)) {
-                result = identifierName;
-            }
-        }
-        return result;
     }
     
 }

Modified: incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/StructDeferredAction.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/StructDeferredAction.java?rev=608894&r1=608893&r2=608894&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/StructDeferredAction.java (original)
+++ incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/StructDeferredAction.java Fri Jan  4 07:47:28 2008
@@ -15,7 +15,7 @@
  * KIND, either express or implied. See the License for the
  * specific language governing permissions and limitations
  * under the License.
-*/
+ */
 
 package org.apache.yoko.tools.processors.idl;
 
@@ -25,30 +25,26 @@
 import org.apache.yoko.tools.common.ReferenceConstants;
 import org.apache.yoko.wsdl.CorbaTypeImpl;
 
-public class StructDeferredAction extends DeferredActionBase {
+public class StructDeferredAction implements SchemaDeferredAction {
 
     protected MemberType member;
     protected XmlSchemaElement element;
     
     
-    public StructDeferredAction(MemberType memberType, XmlSchemaElement elem,
-                                  Scope scope) {                           
-        super(scope);
+    public StructDeferredAction(MemberType memberType, XmlSchemaElement elem) {
         member = memberType;
         element = elem;        
     }
     
-    public StructDeferredAction(MemberType memberType, Scope scope) {                           
-        super(scope);
+    public StructDeferredAction(MemberType memberType) {
         member = memberType;         
     }
     
-    public StructDeferredAction(XmlSchemaElement elem, Scope scope) {                           
-        super(scope);
+    public StructDeferredAction(XmlSchemaElement elem) {
         element = elem;               
     }
     
-    public void doDeferredAction(XmlSchemaType stype, CorbaTypeImpl ctype) {
+    public void execute(XmlSchemaType stype, CorbaTypeImpl ctype) {
         if (member != null) {
             member.setIdltype(ctype.getQName());
         }
@@ -61,6 +57,7 @@
     }
        
 }
+
 
 
 



Mime
View raw message