cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r608894 [9/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/StructVisitor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/StructVisitor.java?rev=608894&r1=608893&r2=608894&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/StructVisitor.java (original)
+++ incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/StructVisitor.java Fri Jan  4 07:47:28 2008
@@ -15,13 +15,14 @@
  * 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.Iterator;
 import java.util.List;
 
+import javax.wsdl.Definition;
 import javax.xml.namespace.QName;
 
 import antlr.collections.AST;
@@ -29,6 +30,7 @@
 import org.apache.schemas.yoko.bindings.corba.MemberType;
 import org.apache.schemas.yoko.bindings.corba.Struct;
 
+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;
@@ -40,8 +42,10 @@
 public class StructVisitor extends VisitorBase {
     
     public StructVisitor(Scope scope,
+                         Definition defn,
+                         XmlSchema schemaRef,
                          WSDLASTVisitor wsdlVisitor) {
-        super(scope, wsdlVisitor);
+        super(scope, defn, schemaRef, wsdlVisitor);
     }
 
     public static boolean accept(AST node) {
@@ -51,8 +55,6 @@
         return false;
     }
     
-//  Check if its a forward declaration
-    
     public void visit(AST node) {
         // <struct_type> ::= "struct" <identifier> "{" <member_list> "}"
         // <member_list> ::= <member>+
@@ -68,12 +70,11 @@
     }
         
     public void visitDeclaredStruct(AST identifierNode) {
-       
         Scope structScope = new Scope(getScope(), identifierNode);        
 
         // xmlschema:struct
         XmlSchemaComplexType complexType = new XmlSchemaComplexType(schema);
-        complexType.setName(structScope.toString());
+        complexType.setName(mapper.mapToQName(structScope));
         XmlSchemaSequence sequence = new XmlSchemaSequence();
         complexType.setParticle(sequence);
         
@@ -91,7 +92,6 @@
         if (recursiveAdd) {
             removeRecursiveScopedName(identifierNode);
         }
-
         // add schemaType
         schema.getItems().add(complexType);
         schema.addType(complexType);
@@ -122,7 +122,9 @@
             CorbaTypeImpl corbaType = null;
             Scope fqName = null;
             try {
-                TypesVisitor visitor = new TypesVisitor(structScope, 
+                TypesVisitor visitor = new TypesVisitor(structScope,
+                                                        definition,
+                                                        schema,
                                                         wsdlVisitor,
                                                         null);
                 visitor.visit(memberTypeNode);                
@@ -133,30 +135,47 @@
                 throw new RuntimeException(ex);
             }
 
-            // needed for anonymous arrays in structs 
-            if (ArrayVisitor.accept(memberNode)) {
-                Scope anonScope = new Scope(structScope,
-                                            TypesUtils.getCorbaTypeNameNode(memberTypeNode));
-                ArrayVisitor arrayVisitor = new ArrayVisitor(anonScope,
-                                                             wsdlVisitor,
-                                                             schemaType,
-                                                             corbaType,
-                                                             null,
-                                                             fqName);
-                arrayVisitor.visit(memberNode);
-                schemaType = arrayVisitor.getSchemaType();
-                corbaType = arrayVisitor.getCorbaType();
-                fqName = arrayVisitor.getFullyQualifiedName();
+            // Handle multiple struct member declarators
+            // <declarators> :== <declarator> { "," <declarator> }*
+            //
+            // A multiple declarator must be an identifier (i.e. of type IDENT)
+            // and cannot be a previous declared (or forward declared) type
+            // (hence the ScopedNameVisitor.accept() call).
+            while (memberNode != null
+                   && memberNode.getType() == IDLTokenTypes.IDENT
+                   && !ScopedNameVisitor.accept(structScope, definition, schema, memberNode, wsdlVisitor)) {
+
+                XmlSchemaType memberSchemaType = schemaType;
+                CorbaTypeImpl memberCorbaType = corbaType;
+                // needed for anonymous arrays in structs 
+                if (ArrayVisitor.accept(memberNode)) {
+                    Scope anonScope = new Scope(structScope,
+                                                TypesUtils.getCorbaTypeNameNode(memberTypeNode));
+                    ArrayVisitor arrayVisitor = new ArrayVisitor(anonScope,
+                                                                 definition,
+                                                                 schema,
+                                                                 wsdlVisitor,
+                                                                 null,
+                                                                 fqName);
+                    arrayVisitor.setSchemaType(schemaType);
+                    arrayVisitor.setCorbaType(corbaType);
+                    arrayVisitor.visit(memberNode);
+                    memberSchemaType = arrayVisitor.getSchemaType();
+                    memberCorbaType = arrayVisitor.getCorbaType();
+                    fqName = arrayVisitor.getFullyQualifiedName();
+                }
+
+                XmlSchemaElement member = 
+                    createXmlSchemaElement(memberNode, memberSchemaType, fqName);
+                sequence.getItems().add(member);           
+                MemberType memberType = 
+                    createMemberType(memberNode, memberCorbaType, fqName);            
+                struct.getMember().add(memberType);
+                
+                memberNode = memberNode.getNextSibling();
             }
             
-            XmlSchemaElement member = 
-                createXmlSchemaElement(memberNode, schemaType, fqName);
-            sequence.getItems().add(member);           
-            MemberType memberType = 
-                createMemberType(memberNode, corbaType, fqName);            
-            struct.getMember().add(memberType);
-
-            memberTypeNode = memberNode.getNextSibling();
+            memberTypeNode = memberNode;
         }
     }
     
@@ -175,7 +194,7 @@
             }
         } else {
             wsdlVisitor.getDeferredActions().
-                add(new StructDeferredAction(member, fqName));                
+                add(fqName, new StructDeferredAction(member));
         }
         return member;
     }
@@ -191,7 +210,7 @@
             memberType.setIdltype(corbaType.getQName());
         } else {
             wsdlVisitor.getDeferredActions().
-                add(new StructDeferredAction(memberType, fqName)); 
+                add(fqName, new StructDeferredAction(memberType)); 
         }
         return memberType;
     }
@@ -210,14 +229,14 @@
     private void processForwardStructActions(Scope structScope) {
         if (wsdlVisitor.getDeferredActions() != null) {
             DeferredActionCollection deferredActions = wsdlVisitor.getDeferredActions();
-            List list = deferredActions.getActionsList(structScope);
-            if (!list.isEmpty()) {
+            List list = deferredActions.getActions(structScope);
+            if ((list != null) && !list.isEmpty()) {
                 XmlSchemaType stype = getSchemaType();
                 CorbaTypeImpl ctype = getCorbaType();
                 Iterator iterator = list.iterator();                    
                 while (iterator.hasNext()) {
-                    DeferredAction action = (DeferredAction)iterator.next();
-                    action.doDeferredAction(stype, ctype);                       
+                    SchemaDeferredAction action = (SchemaDeferredAction)iterator.next();
+                    action.execute(stype, ctype);                       
                 }
                 iterator = list.iterator();                    
                 while (iterator.hasNext()) {

Modified: incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/TemplateTypeSpecVisitor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/TemplateTypeSpecVisitor.java?rev=608894&r1=608893&r2=608894&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/TemplateTypeSpecVisitor.java (original)
+++ incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/TemplateTypeSpecVisitor.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 TemplateTypeSpecVisitor extends VisitorBase {
     
     private AST identifierNode;
     
     public TemplateTypeSpecVisitor(Scope scope,
+                                   Definition defn,
+                                   XmlSchema schemaRef,
                                    WSDLASTVisitor wsdlVisitor,
                                    AST identifierNodeRef) {
-        super(scope, wsdlVisitor);
+        super(scope, defn, schemaRef, wsdlVisitor);
         identifierNode = identifierNodeRef;
     }
 
@@ -51,14 +55,14 @@
         
         if (SequenceVisitor.accept(node)) {
             // <sequence_type>
-            visitor = new SequenceVisitor(getScope(), wsdlVisitor, identifierNode);
+            visitor = new SequenceVisitor(getScope(), definition, schema, wsdlVisitor, identifierNode);
         } else if (StringVisitor.accept(node)) {
             // <string_type>
             // <wstring_type>
-            visitor = new StringVisitor(getScope(), wsdlVisitor, identifierNode);
+            visitor = new StringVisitor(getScope(), definition, schema, wsdlVisitor, identifierNode);
         } else if (FixedVisitor.accept(node)) {
             // <fixed_pt_type>
-            visitor = new FixedVisitor(getScope(), wsdlVisitor, identifierNode);
+            visitor = new FixedVisitor(getScope(), definition, schema, wsdlVisitor, identifierNode);
         }
 
         visitor.visit(node);

Modified: incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/TypeDclVisitor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/TypeDclVisitor.java?rev=608894&r1=608893&r2=608894&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/TypeDclVisitor.java (original)
+++ incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/TypeDclVisitor.java Fri Jan  4 07:47:28 2008
@@ -15,19 +15,23 @@
  * 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 TypeDclVisitor extends VisitorBase {
     
     public TypeDclVisitor(Scope scope,
+                          Definition defn,
+                          XmlSchema schemaRef,
                           WSDLASTVisitor wsdlVisitor) {
-        super(scope, wsdlVisitor);
+        super(scope, defn, schemaRef, wsdlVisitor);
     }
-    
+
     public static boolean accept(AST node) {
         boolean result =
             TypedefVisitor.accept(node)
@@ -49,16 +53,16 @@
         
         if (TypedefVisitor.accept(node)) {
             // "typedef" <type_declarator>
-            visitor = new TypedefVisitor(getScope(), wsdlVisitor);
+            visitor = new TypedefVisitor(getScope(), definition, schema, wsdlVisitor);
         } else if (StructVisitor.accept(node)) {
             // <struct_type>
-            visitor = new StructVisitor(getScope(), wsdlVisitor);
+            visitor = new StructVisitor(getScope(), definition, schema, wsdlVisitor);
         } else if (UnionVisitor.accept(node)) {
             // <union_type>
-            visitor = new UnionVisitor(getScope(), wsdlVisitor);
+            visitor = new UnionVisitor(getScope(), definition, schema, wsdlVisitor);
         } else if (EnumVisitor.accept(node)) {
             // <enum_type>
-            visitor = new EnumVisitor(getScope(), wsdlVisitor);
+            visitor = new EnumVisitor(getScope(), definition, schema, wsdlVisitor);
         } else if (node.getType() == IDLTokenTypes.LITERAL_native) {
             // "native" <simple_declarator>
             //

Modified: incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/TypedefDeferredAction.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/TypedefDeferredAction.java?rev=608894&r1=608893&r2=608894&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/TypedefDeferredAction.java (original)
+++ incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/TypedefDeferredAction.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;
 
@@ -23,16 +23,15 @@
 import org.apache.ws.commons.schema.XmlSchemaType;
 import org.apache.yoko.wsdl.CorbaTypeImpl;
 
-public class TypedefDeferredAction extends DeferredActionBase {
+public class TypedefDeferredAction implements SchemaDeferredAction {
 
     protected Alias alias;    
     
-    public TypedefDeferredAction(Alias aliasType, Scope scope) {                           
-        super(scope);
+    public TypedefDeferredAction(Alias aliasType) {                         
         alias = aliasType;                
     }                   
     
-    public void doDeferredAction(XmlSchemaType stype, CorbaTypeImpl ctype) {  
+    public void execute(XmlSchemaType stype, CorbaTypeImpl ctype) {  
         if (alias != null) {
             alias.setBasetype(ctype.getQName());            
             alias.setType(stype.getQName());
@@ -40,6 +39,7 @@
     }
        
 }
+
 
 
 

Modified: incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/TypedefVisitor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/TypedefVisitor.java?rev=608894&r1=608893&r2=608894&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/TypedefVisitor.java (original)
+++ incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/TypedefVisitor.java Fri Jan  4 07:47:28 2008
@@ -15,16 +15,18 @@
  * 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.ws.commons.schema.XmlSchema;
 import org.apache.ws.commons.schema.XmlSchemaType;
 import org.apache.ws.commons.schema.constants.Constants;
 
@@ -34,8 +36,10 @@
 public class TypedefVisitor extends VisitorBase {
     
     public TypedefVisitor(Scope scope,
+                          Definition defn,
+                          XmlSchema schemaRef,
                           WSDLASTVisitor wsdlVisitor) {
-        super(scope, wsdlVisitor);
+        super(scope, defn, schemaRef, wsdlVisitor);
     }
     
     public static boolean accept(AST node) {
@@ -51,7 +55,11 @@
 
         AST typeDeclaratorNode = typedefNode.getFirstChild();
         AST identifierNode = TypesUtils.getCorbaTypeNameNode(typeDeclaratorNode);
-        TypesVisitor typesVisitor = new TypesVisitor(getScope(), wsdlVisitor, identifierNode);
+        TypesVisitor typesVisitor = new TypesVisitor(getScope(),
+                                                     definition,
+                                                     schema,
+                                                     wsdlVisitor,
+                                                     identifierNode);
         typesVisitor.visit(typeDeclaratorNode);
 
         XmlSchemaType schemaType = typesVisitor.getSchemaType();
@@ -64,6 +72,8 @@
             // Handle cases "typedef sequence"
             //              "typedef fixed"
             DeclaratorVisitor declaratorVisitor = new DeclaratorVisitor(typedefScope,
+                                                                        definition,
+                                                                        schema,
                                                                         wsdlVisitor,
                                                                         schemaType,
                                                                         corbaType,
@@ -77,6 +87,8 @@
             if (StringVisitor.isBounded(typeDeclaratorNode)
                 && !wsdlVisitor.getBoundedStringOverride()) {
                 DeclaratorVisitor declaratorVisitor = new DeclaratorVisitor(typedefScope,
+                                                                            definition,
+                                                                            schema,
                                                                             wsdlVisitor,
                                                                             schemaType,
                                                                             corbaType,
@@ -90,11 +102,13 @@
                 while (identifierNode != null) {
                     if (ArrayVisitor.accept(identifierNode)) {
                         ArrayVisitor arrayVisitor = new ArrayVisitor(getScope(),
+                                                                     definition,
+                                                                     schema,
                                                                      wsdlVisitor,
-                                                                     schemaType,
-                                                                     corbaType,
                                                                      identifierNode,
-                                                                     fullyQualifiedName); 
+                                                                     fullyQualifiedName);
+                        arrayVisitor.setSchemaType(schemaType);
+                        arrayVisitor.setCorbaType(corbaType);
                         arrayVisitor.visit(identifierNode);
 
                     } else {
@@ -119,6 +133,8 @@
                 corbaType = getCorbaType();
             }
             DeclaratorVisitor declaratorVisitor = new DeclaratorVisitor(typedefScope,
+                                                                        definition,
+                                                                        schema,
                                                                         wsdlVisitor,
                                                                         schemaType,
                                                                         corbaType,
@@ -146,7 +162,7 @@
             alias.setBasetype(corbaType.getQName());
         } else {
             wsdlVisitor.getDeferredActions().
-                add(new TypedefDeferredAction(alias, fqName));
+                add(fqName, new TypedefDeferredAction(alias));
             scopedNames.add(scopedName);         
         }
         alias.setRepositoryID(scopedName.toIDLRepositoryID());
@@ -162,8 +178,7 @@
                                      Scope fqName) {
         
         Scope typedefScope = new Scope(getScope(), identifierNode);
-        Scope scopedName = new Scope(getScope(), identifierNode);
-                
+        
         Alias corbaString = new Alias();
         if (typeDeclaratorNode.getType() == IDLTokenTypes.LITERAL_string) {
             corbaString.setBasetype(CorbaConstants.NT_CORBA_STRING);

Modified: incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/TypesUtils.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/TypesUtils.java?rev=608894&r1=608893&r2=608894&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/TypesUtils.java (original)
+++ incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/TypesUtils.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;
 
@@ -85,7 +85,7 @@
             id++;
             StringBuffer name = new StringBuffer();
             name.append("_");
-            name.append(id.toString());
+            name.append("Anon" + id.toString());
             name.append("_");
             name.append(scope.tail());
             scopedName = new Scope(scope.getParent(), name.toString());

Modified: incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/TypesVisitor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/TypesVisitor.java?rev=608894&r1=608893&r2=608894&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/TypesVisitor.java (original)
+++ incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/TypesVisitor.java Fri Jan  4 07:47:28 2008
@@ -15,14 +15,17 @@
  * 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.schemas.yoko.bindings.corba.ArgType;
 
+import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.ws.commons.schema.XmlSchemaObject;
 
 public class TypesVisitor extends VisitorBase {
@@ -37,9 +40,11 @@
 
     // identifierNode null if anonymous type
     public TypesVisitor(Scope scope,
+                        Definition defn,
+                        XmlSchema schemaRef,
                         WSDLASTVisitor wsdlVisitor,
                         AST identifierNodeRef) {
-        super(scope, wsdlVisitor);
+        super(scope, defn, schemaRef, wsdlVisitor);
         identifierNode = identifierNodeRef;
     }
 
@@ -52,10 +57,10 @@
         
         if (ConstrTypeSpecVisitor.accept(node)) {
             // type_spec - constr_type_spec
-            visitor = new ConstrTypeSpecVisitor(getScope(), wsdlVisitor, identifierNode);
+            visitor = new ConstrTypeSpecVisitor(getScope(), definition, schema, wsdlVisitor, identifierNode);
         } else if (SimpleTypeSpecVisitor.accept(node)) {
             // type_spec - simple_type_spec
-            visitor = new SimpleTypeSpecVisitor(getScope(), wsdlVisitor, identifierNode);
+            visitor = new SimpleTypeSpecVisitor(getScope(), definition, schema, wsdlVisitor, identifierNode);
         } else if (visitor == null) {
             // REVISIT: !!!!!
             // This is ugly. It should be done in the SimpleTypeSpecVisitor.accept(node) method.
@@ -69,7 +74,7 @@
             // To work around that redesign and get things working now, I am assuming that if visitor
             // is null at this point, then it has to be a scoped_name.
             // REVISIT!!!
-            visitor = new ScopedNameVisitor(getScope(), wsdlVisitor);
+            visitor = new ScopedNameVisitor(getScope(), definition, schema, wsdlVisitor);
         }
         visitor.visit(node);
 

Modified: incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/TypesVisitorBase.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/TypesVisitorBase.java?rev=608894&r1=608893&r2=608894&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/TypesVisitorBase.java (original)
+++ incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/TypesVisitorBase.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;
 

Modified: incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/UnionDeferredAction.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/UnionDeferredAction.java?rev=608894&r1=608893&r2=608894&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/UnionDeferredAction.java (original)
+++ incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/UnionDeferredAction.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;
 
@@ -26,37 +26,32 @@
 import org.apache.yoko.tools.common.ReferenceConstants;
 import org.apache.yoko.wsdl.CorbaTypeImpl;
 
-public class UnionDeferredAction extends DeferredActionBase {
+public class UnionDeferredAction implements SchemaDeferredAction {
 
     protected Union union;
     protected Unionbranch unionBranch;
     protected XmlSchemaElement element;
     
     
-    public UnionDeferredAction(Union unionType, Unionbranch unionBranchType, XmlSchemaElement elem,
-                                  Scope scope) {                           
-        super(scope);
+    public UnionDeferredAction(Union unionType, Unionbranch unionBranchType, XmlSchemaElement elem) {
         union = unionType;
         unionBranch = unionBranchType;
         element = elem;        
     }
     
-    public UnionDeferredAction(Union unionType, Scope scope) {                           
-        super(scope);
+    public UnionDeferredAction(Union unionType) {
         union = unionType;         
     }
     
-    public UnionDeferredAction(Unionbranch unionBranchType, Scope scope) {                           
-        super(scope);
+    public UnionDeferredAction(Unionbranch unionBranchType) {
         unionBranch = unionBranchType;         
     }
     
-    public UnionDeferredAction(XmlSchemaElement elem, Scope scope) {                           
-        super(scope);
+    public UnionDeferredAction(XmlSchemaElement elem) {
         element = elem;               
     }
     
-    public void doDeferredAction(XmlSchemaType stype, CorbaTypeImpl ctype) {
+    public void execute(XmlSchemaType stype, CorbaTypeImpl ctype) {
         if (unionBranch != null) {
             unionBranch.setIdltype(ctype.getQName());
         }
@@ -69,6 +64,7 @@
     }
         
 }
+
 
 
 

Modified: incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/UnionVisitor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/UnionVisitor.java?rev=608894&r1=608893&r2=608894&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/UnionVisitor.java (original)
+++ incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/UnionVisitor.java Fri Jan  4 07:47:28 2008
@@ -15,13 +15,14 @@
  * 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.Iterator;
 import java.util.List;
 
+import javax.wsdl.Definition;
 import javax.xml.namespace.QName;
 
 import antlr.collections.AST;
@@ -30,6 +31,7 @@
 import org.apache.schemas.yoko.bindings.corba.Union;
 import org.apache.schemas.yoko.bindings.corba.Unionbranch;
 
+import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.ws.commons.schema.XmlSchemaChoice;
 import org.apache.ws.commons.schema.XmlSchemaComplexType;
 import org.apache.ws.commons.schema.XmlSchemaElement;
@@ -41,8 +43,10 @@
 public class UnionVisitor extends VisitorBase {
 
     public UnionVisitor(Scope scope,
+                        Definition defn,
+                        XmlSchema schemaRef,
                         WSDLASTVisitor wsdlVisitor) {
-        super(scope, wsdlVisitor);
+        super(scope, defn, schemaRef, wsdlVisitor);
     }
     
     public static boolean accept(AST node) {
@@ -83,15 +87,14 @@
         AST caseNode = discriminatorNode.getNextSibling();
         // xmlschema:union
         XmlSchemaComplexType unionSchemaComplexType = new XmlSchemaComplexType(schema);
-        unionSchemaComplexType.setName(unionScope.toString());
+        unionSchemaComplexType.setName(mapper.mapToQName(unionScope));
         
         // REVISIT
         // TEMPORARILY 
         // using TypesVisitor to visit <const_type>
         // it should be visited by a SwitchTypeSpecVisitor
-        TypesVisitor visitor = new TypesVisitor(getScope(), wsdlVisitor, null);
+        TypesVisitor visitor = new TypesVisitor(getScope(), definition, schema, wsdlVisitor, null);
         visitor.visit(discriminatorNode);
-        XmlSchemaType stype = visitor.getSchemaType();
         CorbaTypeImpl ctype = visitor.getCorbaType();
         Scope fullyQualifiedName = visitor.getFullyQualifiedName();
         
@@ -111,8 +114,8 @@
         } else {
             // Discriminator type is forward declared.
             UnionDeferredAction unionDiscriminatorAction = 
-                new UnionDeferredAction(corbaUnion, fullyQualifiedName);
-            wsdlVisitor.getDeferredActions().add(unionDiscriminatorAction);
+                new UnionDeferredAction(corbaUnion);
+            wsdlVisitor.getDeferredActions().add(fullyQualifiedName, unionDiscriminatorAction);
         }
        
         boolean recursiveAdd = addRecursiveScopedName(identifierNode);
@@ -178,6 +181,8 @@
             
 
             TypesVisitor visitor = new TypesVisitor(scope,
+                                                    definition,
+                                                    schema,
                                                     wsdlVisitor,
                                                     null);
             visitor.visit(typeNode);
@@ -190,11 +195,13 @@
             if (ArrayVisitor.accept(nameNode)) {
                 Scope anonScope = new Scope(scope, TypesUtils.getCorbaTypeNameNode(nameNode));
                 ArrayVisitor arrayVisitor = new ArrayVisitor(anonScope,
+                                                             definition,
+                                                             schema,
                                                              wsdlVisitor,
-                                                             stype,
-                                                             ctype,
                                                              null,
                                                              fullyQualifiedName);
+                arrayVisitor.setSchemaType(stype);
+                arrayVisitor.setCorbaType(ctype);
                 arrayVisitor.visit(nameNode);
                 stype = arrayVisitor.getSchemaType();
                 ctype = arrayVisitor.getCorbaType();
@@ -211,8 +218,8 @@
                 }
             } else {
                 UnionDeferredAction elementAction = 
-                    new UnionDeferredAction(element, fullyQualifiedName);
-                wsdlVisitor.getDeferredActions().add(elementAction); 
+                    new UnionDeferredAction(element);
+                wsdlVisitor.getDeferredActions().add(fullyQualifiedName, elementAction); 
             }
             choice.getItems().add(element);
             
@@ -224,8 +231,8 @@
             } else {
                 // its type is forward declared.
                 UnionDeferredAction unionBranchAction = 
-                    new UnionDeferredAction(unionBranch, fullyQualifiedName);
-                wsdlVisitor.getDeferredActions().add(unionBranchAction); 
+                    new UnionDeferredAction(unionBranch);
+                wsdlVisitor.getDeferredActions().add(fullyQualifiedName, unionBranchAction); 
             }
             corbaUnion.getUnionbranch().add(unionBranch);
             
@@ -267,14 +274,14 @@
     private void processForwardUnionActions(Scope unionScope) {
         if (wsdlVisitor.getDeferredActions() != null) {
             DeferredActionCollection deferredActions = wsdlVisitor.getDeferredActions();
-            List list = deferredActions.getActionsList(unionScope);
-            if (!list.isEmpty()) {
+            List list = deferredActions.getActions(unionScope);
+            if ((list != null) && !list.isEmpty()) {
                 XmlSchemaType stype = getSchemaType();
                 CorbaTypeImpl ctype = getCorbaType();
                 Iterator iterator = list.iterator();                    
                 while (iterator.hasNext()) {
-                    DeferredAction action = (DeferredAction)iterator.next();
-                    action.doDeferredAction(stype, ctype);                       
+                    SchemaDeferredAction action = (SchemaDeferredAction)iterator.next();
+                    action.execute(stype, ctype);                       
                 }
                 iterator = list.iterator();                    
                 while (iterator.hasNext()) {

Modified: incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/Visitor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/Visitor.java?rev=608894&r1=608893&r2=608894&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/Visitor.java (original)
+++ incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/Visitor.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;
 

Modified: incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/VisitorBase.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/VisitorBase.java?rev=608894&r1=608893&r2=608894&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/VisitorBase.java (original)
+++ incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/VisitorBase.java Fri Jan  4 07:47:28 2008
@@ -15,10 +15,12 @@
  * 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.schemas.yoko.bindings.corba.TypeMappingType;
@@ -31,31 +33,40 @@
 
     protected static ScopeNameCollection scopedNames;
     protected WSDLASTVisitor wsdlVisitor;
-    protected XmlSchema schema;
     protected XmlSchemaCollection schemas;
     protected TypeMappingType typeMap;
-    
-
+    protected ModuleToNSMapper mapper;
+    protected WSDLSchemaManager manager;
     protected DeferredActionCollection deferredActions;
+    protected XmlSchema schema;
+    protected Definition definition;
+    
     private XmlSchemaType schemaType;
     private CorbaTypeImpl corbaType;
     private Scope fullyQualifiedName;
+
     private Scope scope;
-    
+
     public VisitorBase(Scope scopeRef,
+                       Definition defn,
+                       XmlSchema schemaRef,
                        WSDLASTVisitor wsdlASTVisitor) {
         wsdlVisitor = wsdlASTVisitor;
         schemas = wsdlVisitor.getSchemas();
         scopedNames = wsdlVisitor.getScopedNames();
         deferredActions = wsdlVisitor.getDeferredActions();
-        schema = wsdlVisitor.getSchema();
         typeMap = wsdlVisitor.getTypeMap();
         
-        scope = scopeRef; 
-        fullyQualifiedName = null;
-        
+        manager = wsdlVisitor.getManager();
+        mapper = wsdlVisitor.getModuleToNSMapper();
+
+        scope = scopeRef;
+
+        fullyQualifiedName = null;        
         schemaType = null;
         corbaType = null;
+        definition = defn;
+        schema = schemaRef;
     }
 
     public abstract void visit(AST node);
@@ -80,7 +91,7 @@
         return scope;
     }
     
-    public static ScopeNameCollection  getScopedNames() {
+    public static ScopeNameCollection getScopedNames() {
         return scopedNames;
     }
     

Modified: incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/VisitorTypeHolder.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/VisitorTypeHolder.java?rev=608894&r1=608893&r2=608894&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/VisitorTypeHolder.java (original)
+++ incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/VisitorTypeHolder.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;
 

Modified: incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/WSDLASTVisitor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/WSDLASTVisitor.java?rev=608894&r1=608893&r2=608894&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/WSDLASTVisitor.java (original)
+++ incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/WSDLASTVisitor.java Fri Jan  4 07:47:28 2008
@@ -15,67 +15,55 @@
  * 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.io.File;
 import java.io.Writer;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.TreeMap;
 
 import javax.wsdl.Binding;
-import javax.wsdl.BindingOperation;
 import javax.wsdl.Definition;
 import javax.wsdl.Import;
 import javax.wsdl.Message;
-import javax.wsdl.Port;
 import javax.wsdl.PortType;
 import javax.wsdl.Service;
 import javax.wsdl.Types;
 import javax.wsdl.WSDLException;
 import javax.wsdl.extensions.ExtensibilityElement;
-import javax.wsdl.extensions.ExtensionRegistry;
-import javax.wsdl.extensions.schema.Schema;
-import javax.wsdl.extensions.schema.SchemaImport;
-import javax.wsdl.factory.WSDLFactory;
 import javax.xml.bind.JAXBException;
-import javax.xml.namespace.QName;
 
 import antlr.ASTVisitor;
 import antlr.collections.AST;
 
 import org.apache.cxf.tools.common.ToolException;
-import org.apache.cxf.wsdl.JAXBExtensionHelper;
-import org.apache.cxf.wsdl.WSDLConstants;
-import org.apache.schemas.yoko.bindings.corba.AddressType;
-import org.apache.schemas.yoko.bindings.corba.BindingType;
-import org.apache.schemas.yoko.bindings.corba.OperationType;
 import org.apache.schemas.yoko.bindings.corba.TypeMappingType;
 import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.ws.commons.schema.XmlSchemaCollection;
-import org.apache.ws.commons.schema.XmlSchemaSerializer;
+import org.apache.ws.commons.schema.XmlSchemaForm;
 import org.apache.ws.commons.schema.XmlSchemaType;
 import org.apache.ws.commons.schema.constants.Constants;
-import org.apache.ws.commons.schema.utils.NamespaceMap;
 import org.apache.yoko.tools.common.ToolCorbaConstants;
 import org.apache.yoko.tools.common.WSDLUtils;
 import org.apache.yoko.wsdl.CorbaConstants;
 
 public class WSDLASTVisitor implements ASTVisitor {
-    
-    
+
     Definition definition;    
     XmlSchema schema;
-    XmlSchemaCollection schemas;    
+    XmlSchemaCollection schemas;
+    
     TypeMappingType typeMap;
     ScopeNameCollection scopedNames;
     ScopeNameCollection recursionList;
     DeferredActionCollection deferredActions;
     String targetNamespace;
     private boolean declaredWSAImport;
+    private boolean supportPolymorphicFactories;
 
     private XmlSchemaType sequenceOctetType;
     private boolean boundedStringOverride;
@@ -83,43 +71,58 @@
     private String outputDir;
     private String importSchemaFilename; 
     private boolean schemaGenerated;
-    
+    private ModuleToNSMapper moduleToNSMapper;    
+    private WSDLSchemaManager manager;
+    private Map treeMap;
+
     public WSDLASTVisitor(String tns, String schemans, String corbatypemaptns)
         throws WSDLException, JAXBException {
         
-        definition = createWsdlDefinition(tns);
+        manager = new WSDLSchemaManager();
+
+        definition = manager.createWSDLDefinition(tns);
         
+        treeMap = new TreeMap();
+
         targetNamespace = tns;
         schemas = new XmlSchemaCollection();
         scopedNames = new ScopeNameCollection();
-        deferredActions = new DeferredActionCollection();       
-        schema = createSchema(schemans);
+        deferredActions = new DeferredActionCollection();
+
+        if (schemans == null) {
+            schemans = tns;
+        }
+        schema = manager.createXmlSchemaForDefinition(definition, schemans, schemas);
         declaredWSAImport = false;
         
         addAnyType();
         
-        createCorbaTypeMap(corbatypemaptns);
+        typeMap = manager.createCorbaTypeMap(definition, corbatypemaptns);
         
         // idl:sequence<octet> maps to xsd:base64Binary by default
         sequenceOctetType = schemas.getTypeByQName(Constants.XSD_BASE64);
         
         // treat bounded corba:string/corba:wstring as unbounded if set to true
         setBoundedStringOverride(false);
+
+        moduleToNSMapper = new ModuleToNSMapper();
     }
 
     public void visit(AST node) {
         // <specification> ::= <definition>+
 
         while (node != null) {
-            DefinitionVisitor definitionVisitor = new DefinitionVisitor(new Scope(),
+            Scope rootScope = new Scope();
+            DefinitionVisitor definitionVisitor = new DefinitionVisitor(rootScope,
+                                                                        definition,
+                                                                        schema,
                                                                         this);
             definitionVisitor.visit(node);
-
             node = node.getNextSibling();
         }
         
         try {           
-            attachSchema();            
+            manager.attachSchemaToWSDL(definition, schema, isSchemaGenerated());            
         } catch (Exception ex) {
             throw new RuntimeException(ex);
         }
@@ -136,7 +139,23 @@
     public void updateSchemaNamespace(String name) throws Exception  {
         schema.setTargetNamespace(name);                   
     }
-           
+    
+    public void setQualified(boolean qualified) throws Exception  {
+        if (qualified) {
+            XmlSchemaForm form = new XmlSchemaForm("qualified");            
+            schema.setAttributeFormDefault(form);
+            schema.setElementFormDefault(form);
+        }                          
+    }
+    
+    public void setSupportPolymorphicFactories(boolean support) throws Exception  {               
+        supportPolymorphicFactories = support;                      
+    }
+      
+    public boolean getSupportPolymorphicFactories() {
+        return supportPolymorphicFactories;
+    }
+    
     public void setIdlFile(String idl) {
         idlFile = idl;
     }
@@ -145,6 +164,10 @@
         return idlFile;
     }
     
+    public Map getTreeMap() {
+        return treeMap;
+    }
+    
     public void setOutputDir(String outDir) {
         outputDir = outDir;
     }
@@ -157,6 +180,10 @@
         return definition;
     }
 
+    public WSDLSchemaManager getManager() {
+        return manager;
+    }
+
     public XmlSchema getSchema() {
         return schema;
     }
@@ -243,12 +270,22 @@
     }
     
     public boolean writeSchemaDefinition(Definition definit, Writer writer) throws Exception  {
-        Definition def = createWsdlDefinition(targetNamespace + "-types");
+        Definition def = manager.createWSDLDefinition(targetNamespace + "-types");
         def.createTypes();        
         def.setTypes(definit.getTypes());                       
         WSDLUtils.writeSchema(def, writer);
         return true;
     }
+
+    public boolean writeSchema(XmlSchema schemaRef, Writer writer) throws Exception  {
+        //REVISIT, it should be easier to  write out the schema directly, but currently,
+        //the XmlSchemaSerializer throws a NullPointerException, when setting up namespaces!!!
+        //schemaRef.write(writer);
+        Definition defn = manager.createWSDLDefinition(schemaRef.getTargetNamespace());
+        manager.attachSchemaToWSDL(defn, schemaRef, true);
+        writeSchemaDefinition(defn, writer);
+        return true;
+    }
     
     // REVISIT - When CXF corrects the wsdlValidator - will switch back on the 
     // validation of the generated wsdls.
@@ -270,69 +307,58 @@
         // write out logical file -L and physical in default
         if (logicalFile != null && physicalFile == null) {
             writeDefinition(logicalDef, logicalWriter);            
-            //validateWsdl(logicalFile);
-            physicalDef = addWsdlImport(physicalDef, logicalFile);
+            manager.addWSDLDefinitionImport(physicalDef,
+                                            logicalDef,
+                                            "logicaltns",
+                                            logicalFile);
             writeDefinition(physicalDef, writer);
-            //validateWsdl(physicalFile);            
         } else if (logicalFile != null && physicalFile != null) {
             // write both logical -L and physical files -P           
             writeDefinition(logicalDef, logicalWriter);
-            //validateWsdl(logicalFile);
-            physicalDef = addWsdlImport(physicalDef, logicalFile);
+            manager.addWSDLDefinitionImport(physicalDef,
+                                            logicalDef,
+                                            "logicaltns",
+                                            logicalFile);
             writeDefinition(physicalDef, physicalWriter);            
-            //validateWsdl(physicalFile);
         } else if (logicalFile == null && physicalFile != null) {
             // write pyhsical file -P and logical in default
             writeDefinition(logicalDef, writer);            
-            //validateWsdl(getIdlFile());
-            physicalDef = addWsdlImport(physicalDef, getIdlFile());            
+            manager.addWSDLDefinitionImport(physicalDef,
+                                            logicalDef,
+                                            "logicaltns",
+                                            getIdlFile());            
             writeDefinition(physicalDef, physicalWriter);            
-            //validateWsdl(physicalFile);
         } else if ((logicalFile == null && physicalFile == null)
             && (schemaFilename != null || importSchemaFilename != null)) {           
             // write out the schema file -T and default of logical
             // and physical together.
             writeDefinition(physicalDef, writer);               
-            //validateWsdl(getIdlFile());   
         } else if (logicalFile == null && physicalFile == null
             && schemaFilename == null) {
-            // write out the default file
             writeDefinition(definition, writer);            
-            //validateWsdl(getIdlFile());
         }        
       
         return true;
-    }
-    
-    // Writes import into either a logical, physical or schema file.
-    private Definition addWsdlImport(Definition def, String filename) {
-        Import importDef = def.createImport();
-        File file = new File(filename);        
-        importDef.setLocationURI(file.toURI().toString());
-        importDef.setNamespaceURI(definition.getTargetNamespace());
-        def.addImport(importDef);
-        return def;
-    } 
+    }    
     
     // Gets the logical definition for a file - an import will be added for the 
     // schema types if -T is used and a separate schema file generated.
     // if -n is used an import will be added for the schema types and no types generated.
     private Definition getLogicalDefinition(String schemaFilename, Writer schemaWriter) 
         throws WSDLException, JAXBException, Exception {        
-        Definition def = createWsdlDefinition(targetNamespace);
+        Definition def = manager.createWSDLDefinition(targetNamespace);
 
         // checks for -T option.
         if (schemaFilename != null) {
             writeSchemaDefinition(definition, schemaWriter);            
-            def = addSchemaImport(def, schemaFilename);
+            manager.addWSDLSchemaImport(def, schema.getTargetNamespace(), schemaFilename);
         } else {
             // checks for -n option
             if (importSchemaFilename == null) {                
                 Types types = definition.getTypes();
                 def.setTypes(types);
-            } else {
-                
-                def = addSchemaImport(def, importSchemaFilename);
+            } else {                
+                manager.addWSDLSchemaImport(def, schema.getTargetNamespace(), importSchemaFilename);
             }
         }            
         
@@ -379,7 +405,7 @@
         if (schemaOnly) {
             def = logicalDef;
         } else {
-            def = createWsdlDefinition(targetNamespace);
+            def = manager.createWSDLDefinition(targetNamespace);
         }
                 
         Iterator iter = definition.getNamespaces().values().iterator();       
@@ -408,146 +434,8 @@
         def.setExtensionRegistry(definition.getExtensionRegistry());
                 
         return def;
-    }         
-
-    private boolean validateWsdl(String wsdlFilename) throws Exception {                   
-        //String[] args = new String[] {wsdlFilename};
-        //WSDLValidator.main(args);
-        // REVISIT - When CXF publishes an api for the wsdlvalidator we can then
-        // switch to it and delete the files if there is an error.
-        // String separator = System.getProperty("file.separator");   
-        /* File file = new File(outDir + separator + wsdlFilename);
-            if (file.exists()) {
-                file.delete();
-            }  
-        }*/
-        // REVISIT - Once the validator is cleaned up in cxf 
-        // will switch uncomment this back in 
-        /*File file = new File(wsdlFilename);
-        URL wsdlURL = file.toURL();        
-
-        try {
-            ToolContext context = new ToolContext(); 
-            context.put(ToolConstants.CFG_WSDLURL, wsdlURL.toString()); 
-            WSDL11Validator wsdlValidator = new WSDL11Validator(null, context);
-            return wsdlValidator.isValid();
-        } catch (ToolException e) {
-         // failed, handle exception here
-        }*/
-
-        return true;
-    }
-        
-    private Definition createWsdlDefinition(String tns) throws WSDLException, JAXBException {
-        WSDLFactory wsdlFactory = WSDLFactory.newInstance();
-        Definition wsdlDefinition = wsdlFactory.newDefinition();        
-        wsdlDefinition.setTargetNamespace(tns);
-
-        // REVISIT when get a new deploy of cxf
-        //wsdlDefinition.addNamespace(WSDLConstants.WSDL_PREFIX, WSDLConstants.WSDL11_NAMESPACE);
-        wsdlDefinition.addNamespace("wsdl", "http://schemas.xmlsoap.org/wsdl/");
-        wsdlDefinition.addNamespace(WSDLConstants.NP_SCHEMA_XSD, WSDLConstants.NU_SCHEMA_XSD);
-        wsdlDefinition.addNamespace(WSDLConstants.SOAP11_PREFIX, WSDLConstants.SOAP11_NAMESPACE);
-       // wsdlDefinition.addNamespace(WSDLConstants.TNS_PREFIX, tns);
-        wsdlDefinition.addNamespace("tns", tns);
-        wsdlDefinition.addNamespace(CorbaConstants.NP_WSDL_CORBA, CorbaConstants.NU_WSDL_CORBA);
-        addCorbaExtensions(wsdlDefinition.getExtensionRegistry());
-        return wsdlDefinition;
-    }
-    
-    private XmlSchema createSchema(String schemans) {
-        // if no XmlSchema target namespace was specified, default to the 
-        // definition target namespace
-        if (schemans ==  null) {
-            schemans = definition.getTargetNamespace();
-        }
-        XmlSchema xmlSchema = new XmlSchema(schemans, schemas);        
-        return xmlSchema;
-    }
-    
-    private void createCorbaTypeMap(String corbatypemaptns) throws WSDLException { 
-        typeMap = (TypeMappingType)
-            definition.getExtensionRegistry().createExtension(Definition.class,
-                                                              CorbaConstants.NE_CORBA_TYPEMAPPING);
-        if (corbatypemaptns == null) {
-            typeMap.setTargetNamespace(definition.getTargetNamespace()
-                + "/"
-                + CorbaConstants.NS_CORBA_TYPEMAP);
-        } else {
-            typeMap.setTargetNamespace(corbatypemaptns);
-        }
-        definition.addExtensibilityElement(typeMap);
-    }
-
-    private void addCorbaExtensions(ExtensionRegistry extReg) throws JAXBException {
-        try {                      
-            JAXBExtensionHelper.addExtensions(extReg, Binding.class, BindingType.class);
-            JAXBExtensionHelper.addExtensions(extReg, BindingOperation.class, OperationType.class);
-            JAXBExtensionHelper.addExtensions(extReg, Definition.class, TypeMappingType.class);
-            JAXBExtensionHelper.addExtensions(extReg, Port.class, AddressType.class);
-
-            extReg.mapExtensionTypes(Binding.class, CorbaConstants.NE_CORBA_BINDING, BindingType.class);
-            extReg.mapExtensionTypes(BindingOperation.class, CorbaConstants.NE_CORBA_OPERATION,
-                                     org.apache.schemas.yoko.bindings.corba.OperationType.class);
-            extReg.mapExtensionTypes(Definition.class, CorbaConstants.NE_CORBA_TYPEMAPPING,
-                                     TypeMappingType.class);
-            extReg.mapExtensionTypes(Port.class, CorbaConstants.NE_CORBA_ADDRESS,
-                                     org.apache.schemas.yoko.bindings.corba.AddressType.class);
-        } catch (javax.xml.bind.JAXBException ex) {
-            throw new JAXBException(ex.getMessage());
-        }
-    }    
-
-    private void attachSchema() throws Exception {
-        Types types = definition.createTypes();
-        Schema wsdlSchema = (Schema) 
-            definition.getExtensionRegistry().createExtension(Types.class,
-                                                              new QName(Constants.URI_2001_SCHEMA_XSD,
-                                                                        "schema"));
-
-        // See if a NamespaceMap has already been added to the schema (this can be the case with object 
-        // references.  If so, simply add the XSD URI to the map.  Otherwise, create a new one.
-        NamespaceMap nsMap = null;
-        try {
-            nsMap = (NamespaceMap)schema.getNamespaceContext();
-        } catch (ClassCastException ex) {
-            // Consume.  This will mean that the context has not been set.
-        }
-        if (nsMap == null) {
-            nsMap = new NamespaceMap();
-            nsMap.add("xs", Constants.URI_2001_SCHEMA_XSD);
-            schema.setNamespaceContext(nsMap);
-        } else {
-            nsMap.add("xs", Constants.URI_2001_SCHEMA_XSD);
-        }
-        if (isSchemaGenerated()) {
-            nsMap.add("tns", schema.getTargetNamespace());
-        }
-        org.w3c.dom.Element el = XmlSchemaSerializer.serializeSchema(schema, true)[0].getDocumentElement();
-        wsdlSchema.setElement(el);
-                
-        types.addExtensibilityElement(wsdlSchema);
-
-        definition.setTypes(types);
     }
     
-    private Definition addSchemaImport(Definition def, String schemaFilename) throws Exception {
-                        
-        Types types = def.createTypes();
-        Schema wsdlSchema = (Schema) 
-            def.getExtensionRegistry().createExtension(Types.class,
-                                                   new QName(Constants.URI_2001_SCHEMA_XSD,
-                                                   "schema"));
-        
-        SchemaImport schemaimport =  wsdlSchema.createImport();
-        schemaimport.setNamespaceURI(schema.getTargetNamespace());
-        schemaimport.setSchemaLocationURI(schemaFilename);
-        wsdlSchema.addImport(schemaimport);               
-        types.addExtensibilityElement(wsdlSchema);
-        def.setTypes(types);
-        return def;
-    }
-
     private void addAnyType() {
         XmlSchema[] schemaList = schemas.getXmlSchemas();
         if (schemaList != null) {
@@ -568,6 +456,19 @@
     
     public void setDeclaredWSAImport(boolean declaredImport) {
         declaredWSAImport = declaredImport;        
-    }        
+    }
+
+    public void setModuleToNSMapping(Map<String, String> map) {
+        moduleToNSMapper.setDefaultMapping(false);
+        moduleToNSMapper.setUserMapping(map);
+    }
+
+    public ModuleToNSMapper getModuleToNSMapper() {
+        return moduleToNSMapper;
+    }
+
+    public void setExcludedModules(Map<String, List> modules) {
+        moduleToNSMapper.setExcludedModuleMap(modules);
+    }
 
 }

Added: incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/WSDLSchemaManager.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/WSDLSchemaManager.java?rev=608894&view=auto
==============================================================================
--- incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/WSDLSchemaManager.java (added)
+++ incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/idl/WSDLSchemaManager.java Fri Jan  4 07:47:28 2008
@@ -0,0 +1,386 @@
+/**
+ * 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 java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+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.Import;
+import javax.wsdl.Port;
+import javax.wsdl.Types;
+import javax.wsdl.WSDLException;
+import javax.wsdl.extensions.ExtensionRegistry;
+import javax.wsdl.extensions.schema.Schema;
+import javax.wsdl.extensions.schema.SchemaImport;
+import javax.wsdl.factory.WSDLFactory;
+import javax.xml.bind.JAXBException;
+import javax.xml.namespace.QName;
+
+import org.apache.cxf.wsdl.JAXBExtensionHelper;
+import org.apache.cxf.wsdl.WSDLConstants;
+import org.apache.schemas.yoko.bindings.corba.AddressType;
+import org.apache.schemas.yoko.bindings.corba.BindingType;
+import org.apache.schemas.yoko.bindings.corba.OperationType;
+import org.apache.schemas.yoko.bindings.corba.TypeMappingType;
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.ws.commons.schema.XmlSchemaImport;
+import org.apache.ws.commons.schema.XmlSchemaObject;
+import org.apache.ws.commons.schema.XmlSchemaObjectCollection;
+import org.apache.ws.commons.schema.constants.Constants;
+import org.apache.ws.commons.schema.utils.NamespaceMap;
+
+import org.apache.yoko.wsdl.CorbaConstants;
+
+public class WSDLSchemaManager {
+
+    Map<String, Definition> defns;
+    Map<String, XmlSchema> schemas;
+
+    Map<File, Definition> importedDefns;
+    Map<File, XmlSchema> importedSchemas;
+    Map<String, XmlSchema> defnSchemas;
+
+    boolean ignoreImports;
+
+    class DeferredSchemaAttachment {
+        Definition defn;
+        XmlSchema schema;
+        boolean isGenerated;
+    }
+    
+    List<DeferredSchemaAttachment> deferredAttachments;
+    
+    public WSDLSchemaManager() {
+        defns = new HashMap<String, Definition>();
+        schemas = new HashMap<String, XmlSchema>();
+        importedDefns = new HashMap<File, Definition>();
+        importedSchemas = new HashMap<File, XmlSchema>();     
+        defnSchemas = new HashMap<String, XmlSchema>();
+        
+        deferredAttachments = new ArrayList<DeferredSchemaAttachment>();
+    }
+
+    public Definition createWSDLDefinition(String tns) throws WSDLException, JAXBException {
+        WSDLFactory wsdlFactory = WSDLFactory.newInstance();
+        Definition wsdlDefinition = wsdlFactory.newDefinition();        
+        wsdlDefinition.setTargetNamespace(tns);
+        wsdlDefinition.addNamespace("wsdl", "http://schemas.xmlsoap.org/wsdl/");
+        wsdlDefinition.addNamespace(WSDLConstants.NP_SCHEMA_XSD, WSDLConstants.NS_SCHEMA_XSD);
+        wsdlDefinition.addNamespace(WSDLConstants.SOAP11_PREFIX, WSDLConstants.NS_SOAP11);
+        wsdlDefinition.addNamespace("tns", tns);
+        wsdlDefinition.addNamespace(CorbaConstants.NP_WSDL_CORBA, CorbaConstants.NU_WSDL_CORBA);
+        addCorbaExtensions(wsdlDefinition.getExtensionRegistry());
+        defns.put(tns, wsdlDefinition);
+        return wsdlDefinition;
+    }
+
+    public void setIgnoreImports(boolean flag) {
+        ignoreImports = flag;
+    }
+
+    public Definition getWSDLDefinition(String ns) {
+        return defns.get(ns);
+    }
+
+    public XmlSchema getXmlSchema(String ns) {
+        return schemas.get(ns);
+    }
+
+    public XmlSchema createXmlSchema(String schemans, XmlSchemaCollection schemaCol) {
+        XmlSchema xmlSchema = new XmlSchema(schemans, schemaCol);
+        schemas.put(schemans, xmlSchema);
+        return xmlSchema;
+    }
+    
+    public XmlSchema createXmlSchemaForDefinition(Definition defn,
+                                                  String schemans,
+                                                  XmlSchemaCollection schemaCol) {
+        XmlSchema xmlSchema = createXmlSchema(schemans, schemaCol);
+        defnSchemas.put(schemans, xmlSchema);
+        return xmlSchema;
+    }
+
+    public boolean isXmlSchemaInDefinition(String schemans) {
+        return defnSchemas.containsKey(schemans);
+    }
+
+    public void addWSDLDefinitionNamespace(Definition defn, String prefix, String ns) {
+        if (!defn.getNamespaces().values().contains(ns)) {
+            defn.addNamespace(prefix, ns);
+        }
+    }
+    
+    public void addWSDLDefinitionImport(Definition rootDefn,
+                                        Definition defn,
+                                        String prefix,
+                                        String fileName) {
+        if (!fileName.endsWith(".wsdl")) {
+            fileName = fileName + ".wsdl";
+        }
+        File file = new File(fileName);
+        addWSDLDefinitionImport(rootDefn, defn, prefix, file);
+    }
+
+    public void addWSDLDefinitionImport(Definition rootDefn,
+                                        Definition defn,
+                                        String prefix,
+                                        File file) {
+        if (rootDefn.getImports().get(defn.getTargetNamespace()) == null 
+            && !file.getName().equals(".wsdl")) {
+            // Only import if not already done to prevent multiple imports of the same file 
+            // in the WSDL.  Also watch out for empty fileNames, which by this point in the
+            // code would show up as ".wsdl".
+            Import importDefn = rootDefn.createImport();
+            if (!ignoreImports) {
+                importDefn.setLocationURI(file.toURI().toString());
+            }
+            importDefn.setNamespaceURI(defn.getTargetNamespace());
+            rootDefn.addImport(importDefn);
+        }
+        if (!rootDefn.getNamespaces().values().contains(defn.getTargetNamespace())) {
+            rootDefn.addNamespace(prefix, defn.getTargetNamespace());
+        }
+        if (!importedDefns.containsKey(file)) {
+            importedDefns.put(file, defn);
+        }
+
+    }
+
+    public void addXmlSchemaImport(XmlSchema rootSchema, XmlSchema schema, String fileName) {
+        // We need the file name whether already included or not.
+        if (!fileName.endsWith(".xsd")) {
+            fileName = fileName + ".xsd";
+        }
+        File file = new File(fileName);
+        addXmlSchemaImport(rootSchema, schema, file);
+    }
+
+    public void addXmlSchemaImport(XmlSchema rootSchema, XmlSchema schema, File file) {
+        // Make sure we haven't already imported the schema.
+        String importNamespace = schema.getTargetNamespace();
+        boolean included = false;
+        for (Iterator i = rootSchema.getIncludes().getIterator(); i.hasNext();) {
+            Object o = i.next();
+            if (o instanceof XmlSchemaImport) {
+                XmlSchemaImport imp = (XmlSchemaImport)o;
+                if (imp.getNamespace().equals(importNamespace)) {
+                    included = true;
+                    break;
+                }
+            }
+        }
+
+        if (!included) {
+            XmlSchemaImport importSchema = new XmlSchemaImport();
+            if (!ignoreImports) {
+                importSchema.setSchemaLocation(file.toURI().toString());
+            }
+            importSchema.setNamespace(schema.getTargetNamespace());
+            rootSchema.getItems().add(importSchema);
+            rootSchema.getIncludes().add(importSchema);
+        }
+        if (!importedSchemas.containsKey(file)) {
+            importedSchemas.put(file, schema);
+        }
+    }
+
+    public void addWSDLSchemaImport(Definition def, String tns, String schemaFileName) throws Exception {
+        if (!schemaFileName.endsWith(".xsd")) {
+            schemaFileName = schemaFileName + ".xsd";
+        }
+
+        File file = new File(schemaFileName);
+        addWSDLSchemaImport(def, tns, file);
+    }
+
+    public void addWSDLSchemaImport(Definition def, String tns, File file) throws Exception {
+        //REVISIT, check if the wsdl schema already exists.
+        Types types = def.getTypes();
+        if (types == null) {
+            types = def.createTypes();
+            def.setTypes(types);            
+        }
+        Schema wsdlSchema = (Schema) 
+            def.getExtensionRegistry().createExtension(Types.class,
+                                                       new QName(Constants.URI_2001_SCHEMA_XSD,
+                                                                 "schema"));
+
+        addWSDLSchemaImport(wsdlSchema, tns, file);
+        types.addExtensibilityElement(wsdlSchema);
+    }
+
+    private void addWSDLSchemaImport(Schema wsdlSchema, String tns, File file) {
+        if (!wsdlSchema.getImports().containsKey(tns)) {
+            SchemaImport schemaimport =  wsdlSchema.createImport();
+            schemaimport.setNamespaceURI(tns);
+            if (file != null) {
+                if (!ignoreImports) {
+                    schemaimport.setSchemaLocationURI(file.toURI().toString());
+                }
+            }
+            wsdlSchema.addImport(schemaimport);
+        }
+    }
+
+    private void addCorbaExtensions(ExtensionRegistry extReg) throws JAXBException {
+        try {                      
+            JAXBExtensionHelper.addExtensions(extReg, Binding.class, BindingType.class);
+            JAXBExtensionHelper.addExtensions(extReg, BindingOperation.class, OperationType.class);
+            JAXBExtensionHelper.addExtensions(extReg, Definition.class, TypeMappingType.class);
+            JAXBExtensionHelper.addExtensions(extReg, Port.class, AddressType.class);
+
+            extReg.mapExtensionTypes(Binding.class, CorbaConstants.NE_CORBA_BINDING, BindingType.class);
+            extReg.mapExtensionTypes(BindingOperation.class, CorbaConstants.NE_CORBA_OPERATION,
+                                     org.apache.schemas.yoko.bindings.corba.OperationType.class);
+            extReg.mapExtensionTypes(Definition.class, CorbaConstants.NE_CORBA_TYPEMAPPING,
+                                     TypeMappingType.class);
+            extReg.mapExtensionTypes(Port.class, CorbaConstants.NE_CORBA_ADDRESS,
+                                     org.apache.schemas.yoko.bindings.corba.AddressType.class);
+        } catch (javax.xml.bind.JAXBException ex) {
+            throw new JAXBException(ex.getMessage());
+        }
+    }
+    
+    public void deferAttachSchemaToWSDL(Definition definition, XmlSchema schema, 
+                                        boolean isSchemaGenerated) throws Exception {
+        DeferredSchemaAttachment attachment = new DeferredSchemaAttachment();
+        attachment.defn = definition;
+        attachment.schema = schema;
+        attachment.isGenerated = isSchemaGenerated;
+        deferredAttachments.add(attachment);
+    }
+    
+    public void attachDeferredSchemasToWSDL() throws Exception {
+        for (Iterator<DeferredSchemaAttachment> iter = deferredAttachments.iterator(); iter.hasNext();) {
+            DeferredSchemaAttachment attachment = iter.next();
+            attachSchemaToWSDL(attachment.defn, attachment.schema, attachment.isGenerated);
+        }
+    }
+
+    public void attachSchemaToWSDL(Definition definition, XmlSchema schema, boolean isSchemaGenerated)
+        throws Exception {
+        Types types = definition.getTypes();
+        if (types == null) {
+            types = definition.createTypes();
+            definition.setTypes(types);
+        }
+        Schema wsdlSchema = (Schema) 
+            definition.getExtensionRegistry().createExtension(Types.class,
+                                                              new QName(Constants.URI_2001_SCHEMA_XSD,
+                                                                        "schema"));
+
+        // See if a NamespaceMap has already been added to the schema (this can be the case with object 
+        // references.  If so, simply add the XSD URI to the map.  Otherwise, create a new one.
+        NamespaceMap nsMap = null;
+        try {
+            nsMap = (NamespaceMap)schema.getNamespaceContext();
+        } catch (ClassCastException ex) {
+            // Consume.  This will mean that the context has not been set.
+        }
+        if (nsMap == null) {
+            nsMap = new NamespaceMap();
+            nsMap.add("xs", Constants.URI_2001_SCHEMA_XSD);
+            schema.setNamespaceContext(nsMap);
+        } else {
+            nsMap.add("xs", Constants.URI_2001_SCHEMA_XSD);
+        }
+        if (isSchemaGenerated) {
+            nsMap.add("tns", schema.getTargetNamespace());
+        }
+        org.w3c.dom.Element el = schema.getAllSchemas()[0].getDocumentElement();
+        wsdlSchema.setElement(el);
+        
+        XmlSchemaObjectCollection imports = schema.getIncludes();
+        for (java.util.Iterator<XmlSchemaObject> it = imports.getIterator(); it.hasNext();) {
+            XmlSchemaImport xmlSchemaImport = (XmlSchemaImport) it.next();
+            SchemaImport schemaimport =  wsdlSchema.createImport();
+            schemaimport.setNamespaceURI(xmlSchemaImport.getNamespace());
+            if (xmlSchemaImport.getSchemaLocation() != null) {
+                if (!ignoreImports) {
+                    schemaimport.setSchemaLocationURI(xmlSchemaImport.getSchemaLocation());
+                }
+            }
+            wsdlSchema.addImport(schemaimport);  
+        }
+        types.addExtensibilityElement(wsdlSchema);
+    }
+
+    public TypeMappingType createCorbaTypeMap(Definition definition, String corbatypemaptns)
+        throws WSDLException { 
+        TypeMappingType typeMap = (TypeMappingType)
+            definition.getExtensionRegistry().createExtension(Definition.class,
+                                                              CorbaConstants.NE_CORBA_TYPEMAPPING);
+        if (corbatypemaptns == null) {
+            typeMap.setTargetNamespace(definition.getTargetNamespace()
+                + "/"
+                + CorbaConstants.NS_CORBA_TYPEMAP);
+        } else {
+            typeMap.setTargetNamespace(corbatypemaptns);
+        }
+        definition.addExtensibilityElement(typeMap);
+        return typeMap;
+    }
+
+    public Map<String, Definition> getWSDLDefinitions() {
+        return defns;
+    }
+
+    public Map<String, XmlSchema> getXmlSchemas() {
+        return schemas;
+    }
+
+    public Map<File, Definition> getImportedWSDLDefinitions() {
+        return importedDefns;
+    }
+
+    public Map<File, XmlSchema> getImportedXmlSchemas() {
+        return importedSchemas;
+    }
+
+    public File getImportedWSDLDefinitionFile(String ns) {
+        for (Iterator<File> it = importedDefns.keySet().iterator(); it.hasNext();) {
+            File file = it.next();
+            Definition defn = importedDefns.get(file);
+            if (defn.getTargetNamespace().equals(ns)) {
+                return file;
+            }
+        }
+        return null;
+    }
+
+    public File getImportedXmlSchemaFile(String ns) {
+        for (Iterator<File> it = importedSchemas.keySet().iterator(); it.hasNext();) {
+            File file = it.next();
+            XmlSchema schema = importedSchemas.get(file);
+            if (schema.getTargetNamespace().equals(ns)) {
+                return file;
+            }
+        }
+        return null;
+    }
+}

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

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

Modified: incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLParameter.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLParameter.java?rev=608894&r1=608893&r2=608894&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLParameter.java (original)
+++ incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLParameter.java Fri Jan  4 07:47:28 2008
@@ -40,6 +40,7 @@
 import org.apache.ws.commons.schema.XmlSchemaAppInfo;
 import org.apache.ws.commons.schema.XmlSchemaComplexType;
 import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.apache.ws.commons.schema.XmlSchemaExternal;
 import org.apache.ws.commons.schema.XmlSchemaImport;
 import org.apache.ws.commons.schema.XmlSchemaObject;
 import org.apache.ws.commons.schema.XmlSchemaObjectCollection;
@@ -416,36 +417,51 @@
 
         Iterator i = xmlSchemaList.iterator();
         while (i.hasNext()) {
-            XmlSchema xmlSchemaType = (XmlSchema) i.next();
-
+            XmlSchema xmlSchema = (XmlSchema) i.next();
             if (part.getTypeName() != null) {
-                schemaType = xmlSchemaType
-                    .getTypeByName(part.getTypeName());
+                schemaType = findSchemaType(xmlSchema, part.getTypeName());                
+                if (schemaType != null) {
+                    return schemaType;
+                }
+            }
+        }
+            
+        return schemaType;
+    }
 
-                // Endpoint reference types will give a null schemaType
-                // here, so we need to
-                // go through the list of imports to find the definition for
-                // an Endpoint
-                // reference type.
+    // This willl search the current schemas and any included 
+    // schemas for the schema type.
+    private static XmlSchemaType findSchemaType(XmlSchema xmlSchema, QName typeName) {
+                          
+        XmlSchemaType schemaType = xmlSchema.getTypeByName(typeName);
+
+        // Endpoint reference types will give a null schemaType
+        // here, so we need to
+        // go through the list of imports to find the definition for
+        // an Endpoint
+        // reference type.
                 
-                if (schemaType == null
-                    && xmlSchemaType.getIncludes().getCount() > 0) {
-                    XmlSchemaObjectCollection includes = xmlSchemaType
-                        .getIncludes();
-                    Iterator includeIter = includes.getIterator();
-                    while (includeIter.hasNext()) {
-                        Object obj = includeIter.next();
-                        if (!(obj instanceof XmlSchemaImport)) {
-                            continue;
-                        }
+        if (schemaType == null
+            && xmlSchema.getIncludes().getCount() > 0) {
+            XmlSchemaObjectCollection includes = xmlSchema.getIncludes();
+            Iterator includeIter = includes.getIterator();
+            while (includeIter.hasNext()) {
+                Object obj = includeIter.next();
+                if (obj instanceof XmlSchemaExternal) {
+                    XmlSchemaExternal extSchema = (XmlSchemaExternal) obj;
+                    if (extSchema instanceof XmlSchemaImport) {
                         XmlSchemaImport xmlImport = (XmlSchemaImport) obj;
-                        if (xmlImport.getNamespace().equals(part.getTypeName().getNamespaceURI())) {
+                        if (xmlImport.getNamespace().equals(typeName.getNamespaceURI())) {
                             XmlSchema importSchema = xmlImport.getSchema();
-                            schemaType = importSchema.getTypeByName(part.getTypeName());
+                            schemaType = importSchema.getTypeByName(typeName);
                         }
-                    }
-                }
-                
+                    } else {
+                        schemaType = findSchemaType(extSchema.getSchema(), typeName);
+                        if (schemaType != null) {
+                            return schemaType;
+                        }
+                    }                    
+                }                                
             }
             if (schemaType != null) {
                 return schemaType;
@@ -459,25 +475,49 @@
         throws Exception {
         XmlSchemaElement schemaElement = null;
 
-        Iterator i = xmlSchemaList.iterator();
+        Iterator i = xmlSchemaList.iterator();        
         while (i.hasNext()) {
-            XmlSchema xmlSchemaType = (XmlSchema) i.next();
+            XmlSchema xmlSchema = (XmlSchema) i.next();
             if (part.getElementName() != null) {
-                schemaElement = xmlSchemaType.getElementByName(part
-                        .getElementName());
-                if (schemaElement == null) {
-                    QName elName = part.getElementName();
-                    String prefix = definition.getPrefix(elName
-                            .getNamespaceURI());
-                    QName name = new QName(elName.getNamespaceURI(), prefix
-                            + ":" + elName.getLocalPart(), prefix);
-                    schemaElement = xmlSchemaType.getElementByName(name);
-                }
-                if (schemaElement != null) {
+                schemaElement = findElement(xmlSchema, part.getElementName()); 
+                if (schemaElement !=  null) {
                     return schemaElement;
                 }
             }
         }
+        return schemaElement;
+    }
+    
+    // Will check if the schema includes other schemas.
+    private static XmlSchemaElement findElement(XmlSchema xmlSchema, QName elName) {
+        XmlSchemaElement schemaElement = null;
+        
+        schemaElement = xmlSchema.getElementByName(elName);
+        if (schemaElement == null) {           
+            String prefix = definition.getPrefix(elName.getNamespaceURI());
+            QName name = new QName(elName.getNamespaceURI(), prefix
+                                   + ":" + elName.getLocalPart(), prefix);
+            schemaElement = xmlSchema.getElementByName(name);
+        }
+        if (schemaElement != null) {
+            return schemaElement;
+        } else {            
+            if (xmlSchema.getIncludes() != null) {
+                Iterator schemas = xmlSchema.getIncludes().getIterator();
+                while (schemas.hasNext()) {
+                    Object obj = schemas.next();
+                    if (obj instanceof XmlSchemaExternal) {
+                        XmlSchemaExternal extSchema = (XmlSchemaExternal) obj;
+                        if (!(extSchema instanceof XmlSchemaImport)) {
+                            schemaElement = findElement(extSchema.getSchema(), elName);
+                            if (schemaElement != null) {
+                                return schemaElement;
+                            }
+                        }
+                    }
+                }                
+            }
+        }      
         return schemaElement;
     }
 

Modified: incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLToCorbaBinding.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLToCorbaBinding.java?rev=608894&r1=608893&r2=608894&view=diff
==============================================================================
--- incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLToCorbaBinding.java (original)
+++ incubator/cxf/trunk/tools/corba/src/main/java/org/apache/yoko/tools/processors/wsdl/WSDLToCorbaBinding.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.wsdl;
 
@@ -68,6 +68,7 @@
 import org.apache.ws.commons.schema.XmlSchemaComplexType;
 import org.apache.ws.commons.schema.XmlSchemaElement;
 import org.apache.ws.commons.schema.XmlSchemaExternal;
+//import org.apache.ws.commons.schema.XmlSchemaImport;
 import org.apache.ws.commons.schema.XmlSchemaObjectTable;
 import org.apache.ws.commons.schema.XmlSchemaType;
 import org.apache.yoko.wsdl.CorbaConstants;
@@ -116,6 +117,28 @@
     public WSDLToCorbaHelper getHelper() {
         return helper;
     }
+    
+    private void createXmlSchemaList(List<XmlSchema> list) {                
+        List<XmlSchema> schemaList = new ArrayList<XmlSchema>();        
+        Iterator s = list.iterator();
+            
+        while (s.hasNext()) {
+            XmlSchema xmlSchemaTypes = (XmlSchema)s.next();
+            schemaList.add(xmlSchemaTypes);
+                
+            Iterator schemas = xmlSchemaTypes.getIncludes().getIterator();
+            while (schemas.hasNext()) {
+                Object obj = schemas.next();                               
+                if (obj instanceof XmlSchemaExternal) {
+                    XmlSchemaExternal extSchema = (XmlSchemaExternal) obj;                    
+                    schemaList.add(extSchema.getSchema());
+                }
+            }
+        }
+        
+        setXMLSchemaList(schemaList);
+        
+    }
 
     public Definition generateCORBABinding() throws Exception {
         try {
@@ -149,7 +172,7 @@
         typeProcessor.process();
         
         setXMLSchema(typeProcessor.getXmlSchemaType());
-        setXMLSchemaList(typeProcessor.getXmlSchemaTypes());
+        createXmlSchemaList(typeProcessor.getXmlSchemaTypes());
         List<PortType> intfs = null;
 
         if (interfaceNames.size() > 0) {
@@ -501,8 +524,9 @@
         addCorbaTypes(definition);
     }
     
-    private void addCorbaTypes(Definition definition) throws Exception {        
-        Iterator s = xmlSchemaList.iterator();
+    private void addCorbaTypes(Definition definition) throws Exception {   
+        List<XmlSchema> xmlSchemaLst = xmlSchemaList;
+        Iterator s = xmlSchemaLst.iterator();
             
         while (s.hasNext()) {
             XmlSchema xmlSchemaTypes = (XmlSchema)s.next();
@@ -511,16 +535,24 @@
             while (schemas.hasNext()) {
                 Object obj = schemas.next();
                 if (obj instanceof XmlSchemaExternal) {
-                    XmlSchemaExternal extSchema = (XmlSchemaExternal) obj;
+                    XmlSchemaExternal extSchema = (XmlSchemaExternal) obj;                 
                     addCorbaTypes(extSchema.getSchema());
+                    // REVISIT: This was preventing certain types from being added to the corba
+                    // typemap even when they are referenced from other parts of the wsdl.
+                    //
+                    // Should this add the corba types if it IS an instance of the XmlSchemaImport 
+                    // (and not an XmlSchemaInclude or XmlSchemaRedefine)?
+                    //if (!(extSchema instanceof XmlSchemaImport)) {
+                    //    addCorbaTypes(extSchema.getSchema());
+                    //}
                 }
             }
                 
             addCorbaTypes(xmlSchemaTypes);
 
         }
-    }          
-
+    }              
+    
     private void addCorbaTypes(XmlSchema xmlSchemaTypes) throws Exception {
         XmlSchemaObjectTable objs = xmlSchemaTypes.getSchemaTypes(); 
         Iterator i = objs.getValues();



Mime
View raw message