You are viewing a plain text version of this content. The canonical link for it is here.
Posted to woden-dev@ws.apache.org by lm...@apache.org on 2006/01/18 20:36:04 UTC

svn commit: r370227 - in /incubator/woden/java: src/org/apache/woden/internal/wsdl20/validation/WSDLDocumentValidator.java test/org/apache/woden/internal/wsdl20/validation/WSDLDocumentValidatorTest.java

Author: lmandel
Date: Wed Jan 18 11:35:58 2006
New Revision: 370227

URL: http://svn.apache.org/viewcvs?rev=370227&view=rev
Log:
Fixed NPE for schema 0016, 0018, and 0018b methods when a schema cannot be read or doesn't define a target namespace.
Added tests for NPE fixes.
Merged Schema-0018 and Schema-0018b into one method.

Modified:
    incubator/woden/java/src/org/apache/woden/internal/wsdl20/validation/WSDLDocumentValidator.java
    incubator/woden/java/test/org/apache/woden/internal/wsdl20/validation/WSDLDocumentValidatorTest.java

Modified: incubator/woden/java/src/org/apache/woden/internal/wsdl20/validation/WSDLDocumentValidator.java
URL: http://svn.apache.org/viewcvs/incubator/woden/java/src/org/apache/woden/internal/wsdl20/validation/WSDLDocumentValidator.java?rev=370227&r1=370226&r2=370227&view=diff
==============================================================================
--- incubator/woden/java/src/org/apache/woden/internal/wsdl20/validation/WSDLDocumentValidator.java (original)
+++ incubator/woden/java/src/org/apache/woden/internal/wsdl20/validation/WSDLDocumentValidator.java Wed Jan 18 11:35:58 2006
@@ -128,8 +128,6 @@
 	InlinedSchema[] inlinedSchemas = types.getInlinedSchemas();
 	if(!testAssertionSchema0018(inlinedSchemas, errorReporter))
 	  isValid = false;
-	if(!testAssertionSchema0018b(inlinedSchemas, errorReporter))
-		  isValid = false;
 	int numInlinedSchemas = inlinedSchemas.length;
 	for(int i = 0; i < numInlinedSchemas; i++)
 	{
@@ -347,16 +345,20 @@
 	for(int i = 0; i < numInlineSchemas; i++)
 	{
 	  InlinedSchema iSchema = schema[i];
-	  String ns = iSchema.getSchemaDefinition().getTargetNamespace();
+	  URI iSchemaNs = iSchema.getNamespace();
+	  // If the namespace isn't defined this assertion doesn't apply.
+	  if(iSchemaNs == null)
+		continue;
+	  String ns = iSchemaNs.toString();
 	  
 	  if(schemas.containsKey(ns))
 	  {
 		List schemaList = (List)schemas.get(ns);
 		XmlSchemaObjectTable elements = iSchema.getSchemaDefinition().getElements();
-		Iterator names = elements.getNames();
-		while(names.hasNext())
+		Iterator elementNames = elements.getNames();
+		while(elementNames.hasNext())
 		{
-		  QName elementName = (QName)names.next();
+		  QName elementName = (QName)elementNames.next();
 		  Iterator otherInlineSchemas = schemaList.iterator();
 		  while(otherInlineSchemas.hasNext())
 		  {
@@ -369,50 +371,12 @@
 		  }
 		
 		}
-		  //Check if another element has been defined.
-		  //check if another type has been defined.
-		  //add to the existing list of schemas
-		schemaList.add(iSchema);
-	  }
-	  else
-	  {
-		List schemaList = new ArrayList();
-		schemaList.add(iSchema);
-		schemas.put(ns, schemaList);
-	  }
-		 
-	}
-	return isValid;
-  }
-  
-  /**
-   * Test assertion Schema-0018b. Inlined XML Schemas must not define
-   * a type that has already been defined by another inline schema
-   * with the same target namespace.
-   * 
-   * @param schema An array containing all the inline schemas in the order in which they are defined.
-   * @param errorReporter The error reporter.
-   * @return True if the assertion passes, false otherwise.
-   * @throws WSDLException
-   */
-  protected boolean testAssertionSchema0018b(InlinedSchema[] schema, ErrorReporter errorReporter) throws WSDLException
-  {
-	boolean isValid = true;
-	int numInlineSchemas = schema.length;
-	Hashtable schemas = new Hashtable();
-	for(int i = 0; i < numInlineSchemas; i++)
-	{
-	  InlinedSchema iSchema = schema[i];
-	  String ns = iSchema.getSchemaDefinition().getTargetNamespace();
-		  
-	  if(schemas.containsKey(ns))
-	  {
-	    List schemaList = (List)schemas.get(ns);
+		
 		XmlSchemaObjectTable types = iSchema.getSchemaDefinition().getSchemaTypes();
-		Iterator names = types.getNames();
-		while(names.hasNext())
+		Iterator typeNames = types.getNames();
+		while(typeNames.hasNext())
 		{
-		  QName typeName = (QName)names.next();
+		  QName typeName = (QName)typeNames.next();
 		  Iterator otherInlineSchemas = schemaList.iterator();
 		  while(otherInlineSchemas.hasNext())
 		  {
@@ -425,10 +389,10 @@
 		  }
 			
 		}
-		//Check if another element has been defined.
-		//check if another type has been defined.
-		//add to the existing list of schemas
-	    schemaList.add(iSchema);
+		  //Check if another element has been defined.
+		  //check if another type has been defined.
+		  //add to the existing list of schemas
+		schemaList.add(iSchema);
 	  }
 	  else
 	  {
@@ -436,7 +400,7 @@
 		schemaList.add(iSchema);
 		schemas.put(ns, schemaList);
 	  }
-			 
+		 
 	}
 	return isValid;
   }
@@ -545,7 +509,12 @@
       // TODO: This linear search should be improved for performance.
       for(int i = 0; i < numSchemas; i++)
       {
-    	if(schemas[i].getNamespace().toString().equals(namespace))
+    	URI schemaNs = schemas[i].getNamespace();
+    	// If the schema namespace is null continue to the next one. This is not the
+    	// schema we're looking for.
+    	if(schemaNs == null)
+    	  continue;
+    	if(schemaNs.toString().equals(namespace))
     	{
           schemaNotFound = false;
     	  break;

Modified: incubator/woden/java/test/org/apache/woden/internal/wsdl20/validation/WSDLDocumentValidatorTest.java
URL: http://svn.apache.org/viewcvs/incubator/woden/java/test/org/apache/woden/internal/wsdl20/validation/WSDLDocumentValidatorTest.java?rev=370227&r1=370226&r2=370227&view=diff
==============================================================================
--- incubator/woden/java/test/org/apache/woden/internal/wsdl20/validation/WSDLDocumentValidatorTest.java (original)
+++ incubator/woden/java/test/org/apache/woden/internal/wsdl20/validation/WSDLDocumentValidatorTest.java Wed Jan 18 11:35:58 2006
@@ -680,6 +680,82 @@
 	  fail("There was a problem running the test assertion method " + e);
     }
 	
+	// Test that an inline schema that can not be read (that's null) does not produce an error.
+	handler.reset();
+	try
+	{
+	  InlinedSchema[] inlinedSchemas = new InlinedSchema[1];
+	  inlinedSchemas[0]= new InlinedSchemaImpl();
+	
+	  inlinedSchemas[0].setNamespace(new URI("http://www.sample.org"));
+
+	  if(!val.testAssertionSchema0018(inlinedSchemas, reporter))
+	  {
+		fail("There was an error reported for an inline schema list that contains a schema that couldn't be read (is null).");
+	  }
+	}
+	catch(URISyntaxException e)
+	{
+	  fail("There was a problem setting the namespace of the imported schema: " + e);
+	}
+	catch(WSDLException e)
+	{
+	  fail("There was a problem running the test assertion method " + e);
+    }
+	
+	//	 Test that only one inline schema does not produce an error.
+	handler.reset();
+	try
+	{
+	  InlinedSchema[] inlinedSchemas = new InlinedSchema[1];
+	  inlinedSchemas[0]= new InlinedSchemaImpl();
+	
+	  inlinedSchemas[0].setNamespace(new URI("http://www.sample.org"));
+	  
+	  // Create DOM representation of schema, have XmlSchema parse it.
+	  DOMParser builder = new DOMParser();
+	  Reader reader = new StringReader(schemaString);
+      XMLInputSource is = new XMLInputSource(null,null,null,reader,null);
+      builder.parse(is);
+      Document schemaDoc1 = builder.getDocument();
+      XmlSchemaCollection xsc = new XmlSchemaCollection();
+      XmlSchema xs1 = xsc.read(schemaDoc1.getDocumentElement());
+	  inlinedSchemas[0].setSchemaDefinition(xs1);
+	  if(!val.testAssertionSchema0018(inlinedSchemas, reporter))
+	  {
+		fail("There was an error reported for an inline schema list that contains only one inline schema.");
+	  }
+	}
+	catch(URISyntaxException e)
+	{
+	  fail("There was a problem setting the namespace of the imported schema: " + e);
+	}
+	catch(IOException e)
+	{
+	  fail("There was a problem parsing the test inline schema document");
+	}
+	catch(WSDLException e)
+	{
+	  fail("There was a problem running the test assertion method " + e);
+    }
+	
+	// Test that an inline schema with no defined target namespace doesn't produce an error.
+	handler.reset();
+	try
+	{
+	  InlinedSchema[] inlinedSchemas = new InlinedSchema[1];
+	  inlinedSchemas[0]= new InlinedSchemaImpl();
+	
+	  if(!val.testAssertionSchema0018(inlinedSchemas, reporter))
+	  {
+		fail("There was an error reported for an inline schema that contains a null namespace.");
+	  }
+	}
+	catch(WSDLException e)
+	{
+	  fail("There was a problem running the test assertion method " + e);
+    }
+	
   }
   
   /**
@@ -707,7 +783,7 @@
 	try
 	{
       InlinedSchema[] emptySchemaList = new InlinedSchema[0];
-      if(!val.testAssertionSchema0018b(emptySchemaList, reporter))
+      if(!val.testAssertionSchema0018(emptySchemaList, reporter))
 	  {
         fail("The testAssertionSchema0018b method returned false for an empty inline schema list.");
 	  }
@@ -745,7 +821,7 @@
       XmlSchema xs2 = xsc.read(schemaDoc2.getDocumentElement());
 	  inlinedSchemas[0].setSchemaDefinition(xs1);
 	  inlinedSchemas[1].setSchemaDefinition(xs2);
-	  if(val.testAssertionSchema0018b(inlinedSchemas, reporter))
+	  if(val.testAssertionSchema0018(inlinedSchemas, reporter))
 	  {
 		fail("There was no error reported for an inline schema that declares the same type as another inline schema with the same namespace.");
 	  }
@@ -791,7 +867,7 @@
       XmlSchema xs2 = xsc.read(schemaDoc2.getDocumentElement());
 	  inlinedSchemas[0].setSchemaDefinition(xs1);
 	  inlinedSchemas[1].setSchemaDefinition(xs2);
-	  if(!val.testAssertionSchema0018b(inlinedSchemas, reporter))
+	  if(!val.testAssertionSchema0018(inlinedSchemas, reporter))
 	  {
 		fail("There was an error reported for an inline schema that declares the same element as another inline schema but has a different target namespace.");
 	  }
@@ -827,7 +903,7 @@
       XmlSchemaCollection xsc = new XmlSchemaCollection();
       XmlSchema xs1 = xsc.read(schemaDoc1.getDocumentElement());
 	  inlinedSchemas[0].setSchemaDefinition(xs1);
-	  if(!val.testAssertionSchema0018b(inlinedSchemas, reporter))
+	  if(!val.testAssertionSchema0018(inlinedSchemas, reporter))
 	  {
 		fail("There was an error reported for an inline schema list that contains only one inline schema.");
 	  }
@@ -844,6 +920,46 @@
 	{
 	  fail("There was a problem running the test assertion method " + e);
     }
+	
+	// Test that an inline schema that can not be read (that's null) does not produce an error.
+	handler.reset();
+	try
+	{
+	  InlinedSchema[] inlinedSchemas = new InlinedSchema[1];
+	  inlinedSchemas[0]= new InlinedSchemaImpl();
+	
+	  inlinedSchemas[0].setNamespace(new URI("http://www.sample.org"));
+
+	  if(!val.testAssertionSchema0018(inlinedSchemas, reporter))
+	  {
+		fail("There was an error reported for an inline schema list that contains a schema that couldn't be read (is null).");
+	  }
+	}
+	catch(URISyntaxException e)
+	{
+	  fail("There was a problem setting the namespace of the imported schema: " + e);
+	}
+	catch(WSDLException e)
+	{
+	  fail("There was a problem running the test assertion method " + e);
+    }
+	
+	// Test that an inline schema with no defined target namespace doesn't produce an error.
+	handler.reset();
+	try
+	{
+	  InlinedSchema[] inlinedSchemas = new InlinedSchema[1];
+	  inlinedSchemas[0]= new InlinedSchemaImpl();
+	
+	  if(!val.testAssertionSchema0018(inlinedSchemas, reporter))
+	  {
+		fail("There was an error reported for an inline schema that contains a null namespace.");
+	  }
+	}
+	catch(WSDLException e)
+	{
+	  fail("There was a problem running the test assertion method " + e);
+    }
   }
   
   /**
@@ -1329,6 +1445,32 @@
     {
 	  fail("There was a problem running the test assertion method " + e);
 	}
+	
+	// Test that a reference to an inline schema that does not define a 
+	// target namespace (the targetNamespace is null) does not return an
+	// error.
+	handler.reset();
+    try
+	{
+      DescriptionElement descElem = new DescriptionImpl();
+      TypesElement typesImported = descElem.createTypesElement();
+      InlinedSchema inlinedSchema = new InlinedSchemaImpl();
+      typesImported.addSchema(inlinedSchema);
+      InlinedSchema inlinedSchema2 = new InlinedSchemaImpl();
+      inlinedSchema2.setNamespace(schemaNS);
+      typesImported.addSchema(inlinedSchema2);
+      descElem.setTypesElement(typesImported);
+      
+	  if(!val.testAssertionSchema0016(descElem, "http://www.sample.org", reporter))
+	  {
+	    fail("The testAssertionSchema0016 method returned false for a namespace that has been imported.");
+	  }
+	}
+	catch(WSDLException e)
+    {
+	  fail("There was a problem running the test assertion method " + e);
+	}
+	
   }
   
   /**



---------------------------------------------------------------------
To unsubscribe, e-mail: woden-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: woden-dev-help@ws.apache.org