Author: dkulp Date: Wed Dec 5 20:55:09 2012 New Revision: 1417643 URL: http://svn.apache.org/viewvc?rev=1417643&view=rev Log: Merged revisions 1417634 via git cherry-pick from https://svn.apache.org/repos/asf/cxf/branches/2.6.x-fixes
........ r1417634 | dkulp | 2012-12-05 15:34:36 -0500 (Wed, 05 Dec 2012) | 10 lines Merged revisions 1417633 via git cherry-pick from https://svn.apache.org/repos/asf/cxf/trunk ........ r1417633 | dkulp | 2012-12-05 15:31:56 -0500 (Wed, 05 Dec 2012) | 2 lines [CXF-3329] Fix issues with struct member name being same as struct/scope name ........ ........ Added: cxf/branches/2.5.x-fixes/tools/corba/src/test/resources/idl/CXF3329.idl Modified: cxf/branches/2.5.x-fixes/tools/corba/src/main/java/org/apache/cxf/tools/corba/processors/idl/ScopedNameVisitor.java cxf/branches/2.5.x-fixes/tools/corba/src/main/java/org/apache/cxf/tools/corba/processors/idl/StructVisitor.java cxf/branches/2.5.x-fixes/tools/corba/src/test/java/org/apache/cxf/tools/corba/IDLToWSDLTest.java Modified: cxf/branches/2.5.x-fixes/tools/corba/src/main/java/org/apache/cxf/tools/corba/processors/idl/ScopedNameVisitor.java URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/tools/corba/src/main/java/org/apache/cxf/tools/corba/processors/idl/ScopedNameVisitor.java?rev=1417643&r1=1417642&r2=1417643&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/tools/corba/src/main/java/org/apache/cxf/tools/corba/processors/idl/ScopedNameVisitor.java (original) +++ cxf/branches/2.5.x-fixes/tools/corba/src/main/java/org/apache/cxf/tools/corba/processors/idl/ScopedNameVisitor.java Wed Dec 5 20:55:09 2012 @@ -56,16 +56,27 @@ public class ScopedNameVisitor extends V public void setExceptionMode(boolean value) { exceptionMode = value; } - public static boolean accept(Scope scope, Definition defn, XmlSchema schemaRef, AST node, WSDLASTVisitor wsdlVisitor) { + return accept(scope, defn, schemaRef, node, wsdlVisitor, false); + } + + // when accepting a "name" (for example, name of a field in a struct), we may need + // to relax the strict checking for forward decls and schema types to not count for + // exact parent scope names + public static boolean accept(Scope scope, + Definition defn, + XmlSchema schemaRef, + AST node, + WSDLASTVisitor wsdlVisitor, + boolean asName) { boolean result = false; if (PrimitiveTypesVisitor.accept(node)) { result = true; - } else if (isforwardDeclared(scope, node, wsdlVisitor)) { + } else if (isforwardDeclared(scope, node, wsdlVisitor, asName)) { result = true; } else if (ObjectReferenceVisitor.accept(scope, schemaRef, @@ -73,7 +84,7 @@ public class ScopedNameVisitor extends V node, wsdlVisitor)) { result = true; - } else if (findSchemaType(scope, defn, schemaRef, node, wsdlVisitor, null)) { + } else if (findSchemaType(scope, defn, schemaRef, node, wsdlVisitor, null, asName)) { result = true; } return result; @@ -155,6 +166,9 @@ public class ScopedNameVisitor extends V } protected static boolean isforwardDeclared(Scope scope, AST node, WSDLASTVisitor wsdlVisitor) { + return isforwardDeclared(scope, node, wsdlVisitor, false); + } + protected static boolean isforwardDeclared(Scope scope, AST node, WSDLASTVisitor wsdlVisitor, boolean b) { boolean isForward = false; Scope currentScope = scope; @@ -173,6 +187,9 @@ public class ScopedNameVisitor extends V if (scopedNames.getScope(scopedName) != null) { isForward = true; } + if (b && currentScope.equals(new Scope(currentScope.getParent(), node))) { + break; + } currentScope = currentScope.getParent(); } } @@ -256,13 +273,21 @@ public class ScopedNameVisitor extends V return result; } - protected static boolean findSchemaType(Scope scope, Definition defn, XmlSchema schemaRef, AST node, WSDLASTVisitor wsdlVisitor, VisitorTypeHolder holder) { + return findSchemaType(scope, defn, schemaRef, node, wsdlVisitor, holder, false); + } + protected static boolean findSchemaType(Scope scope, + Definition defn, + XmlSchema schemaRef, + AST node, + WSDLASTVisitor wsdlVisitor, + VisitorTypeHolder holder, + boolean checkExact) { boolean result = false; Scope currentScope = scope; @@ -290,6 +315,10 @@ public class ScopedNameVisitor extends V node, wsdlVisitor, holder); } + if (checkExact && currentScope.equals(new Scope(currentScope.getParent(), node))) { + return false; + } + currentScope = currentScope.getParent(); } } Modified: cxf/branches/2.5.x-fixes/tools/corba/src/main/java/org/apache/cxf/tools/corba/processors/idl/StructVisitor.java URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/tools/corba/src/main/java/org/apache/cxf/tools/corba/processors/idl/StructVisitor.java?rev=1417643&r1=1417642&r2=1417643&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/tools/corba/src/main/java/org/apache/cxf/tools/corba/processors/idl/StructVisitor.java (original) +++ cxf/branches/2.5.x-fixes/tools/corba/src/main/java/org/apache/cxf/tools/corba/processors/idl/StructVisitor.java Wed Dec 5 20:55:09 2012 @@ -138,7 +138,7 @@ public class StructVisitor extends Visit // (hence the ScopedNameVisitor.accept() call). while (memberNode != null && memberNode.getType() == IDLTokenTypes.IDENT - && !ScopedNameVisitor.accept(structScope, definition, schema, memberNode, wsdlVisitor)) { + && !ScopedNameVisitor.accept(structScope, definition, schema, memberNode, wsdlVisitor, true)) { XmlSchemaType memberSchemaType = schemaType; CorbaTypeImpl memberCorbaType = corbaType; Modified: cxf/branches/2.5.x-fixes/tools/corba/src/test/java/org/apache/cxf/tools/corba/IDLToWSDLTest.java URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/tools/corba/src/test/java/org/apache/cxf/tools/corba/IDLToWSDLTest.java?rev=1417643&r1=1417642&r2=1417643&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/tools/corba/src/test/java/org/apache/cxf/tools/corba/IDLToWSDLTest.java (original) +++ cxf/branches/2.5.x-fixes/tools/corba/src/test/java/org/apache/cxf/tools/corba/IDLToWSDLTest.java Wed Dec 5 20:55:09 2012 @@ -422,4 +422,17 @@ public class IDLToWSDLTest extends ToolT } fail("Did not find foo element"); } + public void testCXF3329() throws Exception { + File input = new File(getClass().getResource("/idl/CXF3329.idl").toURI()); + String[] args = new String[] { + "-o", output.toString(), + input.toString() + }; + IDLToWSDL.run(args); + File fs = new File(output, "CXF3329.wsdl"); + assertTrue(fs.getName() + " was not created.", fs.exists()); + Document doc = StaxUtils.read(new FileInputStream(fs)); + String s = StaxUtils.toString(doc.getDocumentElement()); + assertTrue(s.contains("name=\"myStruct\"")); + } } Added: cxf/branches/2.5.x-fixes/tools/corba/src/test/resources/idl/CXF3329.idl URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/tools/corba/src/test/resources/idl/CXF3329.idl?rev=1417643&view=auto ============================================================================== --- cxf/branches/2.5.x-fixes/tools/corba/src/test/resources/idl/CXF3329.idl (added) +++ cxf/branches/2.5.x-fixes/tools/corba/src/test/resources/idl/CXF3329.idl Wed Dec 5 20:55:09 2012 @@ -0,0 +1,9 @@ +module myModule +{ + struct myStruct + { + long myStruct; + long otherField; + sequence<myStruct> parent; + }; +}; \ No newline at end of file
