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 2005/12/06 22:08:03 UTC

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

Author: lmandel
Date: Tue Dec  6 13:07:53 2005
New Revision: 354553

URL: http://svn.apache.org/viewcvs?rev=354553&view=rev
Log:
Updates for NPE.

Modified:
    incubator/woden/java/src/org/apache/woden/internal/wsdl20/TypesImpl.java
    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/TypesImpl.java
URL: http://svn.apache.org/viewcvs/incubator/woden/java/src/org/apache/woden/internal/wsdl20/TypesImpl.java?rev=354553&r1=354552&r2=354553&view=diff
==============================================================================
--- incubator/woden/java/src/org/apache/woden/internal/wsdl20/TypesImpl.java (original)
+++ incubator/woden/java/src/org/apache/woden/internal/wsdl20/TypesImpl.java Tue Dec  6 13:07:53 2005
@@ -180,6 +180,10 @@
      */
     public XmlSchemaElement getElementDeclaration(QName qname)
     {
+    	// Can't resolve the element if the QName is null.
+    	if(qname == null)
+    	  return null;
+    	
         XmlSchemaElement xmlSchemaElement = null;
         List schemas = getReferenceableSchemaDefs(qname.getNamespaceURI());
         if(schemas != null) 

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=354553&r1=354552&r2=354553&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 Tue Dec  6 13:07:53 2005
@@ -37,6 +37,8 @@
 import org.apache.woden.wsdl20.xml.InterfaceMessageReferenceElement;
 import org.apache.woden.wsdl20.xml.InterfaceOperationElement;
 import org.apache.woden.wsdl20.xml.TypesElement;
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaElement;
 import org.apache.ws.commons.schema.XmlSchemaObjectTable;
 
 /**
@@ -102,6 +104,11 @@
   protected boolean validateTypes(TypesElement types, ErrorReporter errorReporter) throws WSDLException
   {
 	boolean isValid = true;
+	
+	// If there is no types element all types assertions are true.
+	if(types == null)
+	  return true;
+	
 	// Test imported schema assertions.
 	ImportedSchema[] importedSchemas = types.getImportedSchemas();
 	int numImportedSchemas = importedSchemas.length;
@@ -180,8 +187,16 @@
 	      InterfaceMessageReferenceElement messageReference = messageReferences[k];
 	      if(!testAssertionSchema0020(descElement, messageReference, errorReporter))
 	        isValid = false;
-	      if(!testAssertionSchema0016(descElement, messageReference.getElementName().getNamespaceURI(), errorReporter))
-	    	isValid = false;
+	      
+	      // Only call the namespace assertion if the referenced element name is not null.
+	      QName elementName = messageReference.getElementName();
+	      if(elementName != null)
+	      {
+	    	if(!testAssertionSchema0016(descElement, elementName.getNamespaceURI(), errorReporter))
+	  	      isValid = false;
+	    	
+	      }
+	      
 		}
 		
 //		FaultReferenceElement[] faultReferences = interfaceOperation.getFaultReferenceElements();
@@ -250,7 +265,14 @@
    */
   protected boolean testAssertionSchema0017(ImportedSchema schema, ErrorReporter errorReporter) throws WSDLException
   {
-	String targetNS = schema.getSchemaDefinition().getTargetNamespace();
+	XmlSchema schemaDef = schema.getSchemaDefinition();
+	// The assertion is true if the schema definition is not available.
+	// Problems locating the schema will be reported elseware and are
+	// not part of this assertion.
+	if(schemaDef == null)
+	  return true;
+	
+	String targetNS = schemaDef.getTargetNamespace();
 	if(targetNS == null || targetNS.equals(""))
 	{
 	  errorReporter.reportError(new ErrorLocatorImpl(), "Schema-0017", new Object[]{schema.getSchemaLocation()}, ErrorReporter.SEVERITY_ERROR);
@@ -270,7 +292,14 @@
    */
   protected boolean testAssertionSchema0052(ImportedSchema schema, ErrorReporter errorReporter) throws WSDLException
   {
-	String importedSchemaTargetNS = schema.getSchemaDefinition().getTargetNamespace();
+	XmlSchema schemaDef = schema.getSchemaDefinition();
+    // The assertion is true if the schema definition is not available.
+	// Problems locating the schema will be reported elseware and are
+	// not part of this assertion.
+	if(schemaDef == null)
+	  return true;
+	
+	String importedSchemaTargetNS = schemaDef.getTargetNamespace();
 	String specifiedTargetNS = schema.getNamespace().toString();
 	if(specifiedTargetNS != null && !specifiedTargetNS.equals(importedSchemaTargetNS))
 	{
@@ -450,7 +479,9 @@
    */
   protected boolean testAssertionSchema0020(DescriptionElement descElement, InterfaceMessageReferenceElement messageReference, ErrorReporter errorReporter) throws WSDLException
   {
-    if(messageReference.getElement() == null)
+	XmlSchemaElement element = messageReference.getElement();
+	String contentModel = messageReference.getMessageContentModel();
+    if(element == null && (contentModel == null || !contentModel.equals(Constants.NMTOKEN_NONE)))
     {
       QName elementName = messageReference.getElementName();
       if(descElement.toComponent().getTypeDefinition(elementName) != null)
@@ -499,7 +530,8 @@
    */
   protected boolean testAssertionSchema0016(DescriptionElement descElement, String namespace, ErrorReporter errorReporter) throws WSDLException
   {
-    if(!namespace.equals(Constants.TYPE_XSD_2001))
+	// If the namespace is null it can't be checked.
+    if(namespace != null && !namespace.equals(Constants.TYPE_XSD_2001))
     {
       TypesElement types = descElement.getTypesElement();
       if(types == null)

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=354553&r1=354552&r2=354553&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 Tue Dec  6 13:07:53 2005
@@ -35,7 +35,9 @@
 import org.apache.woden.internal.schema.InlinedSchemaImpl;
 import org.apache.woden.internal.wsdl20.Constants;
 import org.apache.woden.internal.wsdl20.DescriptionImpl;
+import org.apache.woden.internal.wsdl20.ElementDeclarationImpl;
 import org.apache.woden.internal.wsdl20.InterfaceImpl;
+import org.apache.woden.internal.wsdl20.InterfaceMessageReferenceImpl;
 import org.apache.woden.schema.ImportedSchema;
 import org.apache.woden.schema.InlinedSchema;
 import org.apache.woden.wsdl20.xml.DescriptionElement;
@@ -155,6 +157,28 @@
    */
   public void testTestAssertionSchema0052()
   {
+    // Test that no error is reported for an imported schema that has
+	// a null schema. This error should be caught elseware.
+	handler.reset();
+	try
+	{
+	  ImportedSchemaImpl importedSchema = new ImportedSchemaImpl();
+	  importedSchema.setNamespace(new URI("http://www.sample.org"));
+	
+	  if(!val.testAssertionSchema0052(importedSchema, reporter))
+	  {
+		fail("The testAssertionSchema0052 method returned false for a null schema.");
+	  }
+	}
+	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 no error is reported for an imported schema that has
 	// the same target namespace as the imported element.
 	handler.reset();
@@ -290,16 +314,36 @@
    */
   public void testTestAssertionSchema0017()
   {
+    // Test that no error is reported for an imported schema that has
+	// a null schema. This error should be caught elseware.
+	handler.reset();
+	try
+	{
+	  ImportedSchemaImpl importedSchema = new ImportedSchemaImpl();
+	  importedSchema.setNamespace(new URI("http://www.sample.org"));
+	
+	  if(!val.testAssertionSchema0017(importedSchema, reporter))
+	  {
+		fail("The testAssertionSchema0017 method returned false for a null schema.");
+	  }
+	}
+	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 no error is reported for an imported schema that has
 	// defined a target namespace.
 	handler.reset();
 	try
 	{
 	  ImportedSchemaImpl importedSchema = new ImportedSchemaImpl();
-	
 	  importedSchema.setNamespace(new URI("http://www.sample.org"));
 	
-	
 	  XmlSchema schema = new XmlSchema("http://www.sample.org", null);
 	  importedSchema.setSchemaDefinition(schema);
 	  if(!val.testAssertionSchema0017(importedSchema, reporter))
@@ -939,6 +983,31 @@
 	{
 	  fail("An error occurred while creating the sample types section.");
 	}
+	
+    // Test that true is returned when the element content is #none
+	handler.reset();
+	try
+	{
+	  DescriptionElement descElem = new DescriptionImpl();
+	  descElem.setTypesElement(types);
+	  InterfaceElement interfaceElem = descElem.createInterfaceElement();
+	  InterfaceOperationElement interfaceOperation = descElem.createInterfaceOperationElement();
+	  InterfaceMessageReferenceImpl messageRef = new InterfaceMessageReferenceImpl();
+	  messageRef.setMessageContentModel(Constants.NMTOKEN_NONE);
+	  messageRef.setElementDeclaration(new ElementDeclarationImpl());
+	  interfaceOperation.addMessageReferenceElement(messageRef);
+	  interfaceElem.addInterfaceOperationElement(interfaceOperation);
+	  descElem.addInterfaceElement(interfaceElem);
+	      
+      if(!val.testAssertionSchema0020(descElem, messageRef, reporter))
+      {
+		fail("The testAssertionSchema0020 method returned false for an message reference that has an element set to #none.");
+	  }
+    }
+	catch(WSDLException e)
+	{
+	  fail("There was a problem running the test assertion method " + e);
+    }
     
 	// Test that an interface message reference with a reference to an element
 	// does not return an error.
@@ -1166,7 +1235,24 @@
 	{
 	  fail("An error occurred while creating the sample types section.");
 	}
-    
+
+    // Test that a null namespace returns true.
+	handler.reset();
+    try
+	{
+      DescriptionElement descElem = new DescriptionImpl();
+      descElem.setTypesElement(types);
+      
+	  if(!val.testAssertionSchema0016(descElem, null, reporter))
+	  {
+	    fail("The testAssertionSchema0016 method returned false for a null namespace.");
+	  }
+	}
+	catch(WSDLException e)
+    {
+	  fail("There was a problem running the test assertion method " + e);
+	}
+	
 	// Test that a reference to a namespace that is defined inline
 	// does not return an error.
 	handler.reset();
@@ -1241,6 +1327,25 @@
 	catch(WSDLException e)
     {
 	  fail("There was a problem running the test assertion method " + e);
+	}
+  }
+  
+  /**
+   * Test the validateTypes method.
+   */
+  public void testValidateTypes()
+  {
+	// Test that the method returns true when the type is null.
+	try
+	{
+	  if(!val.validateTypes(null, reporter))
+	  {
+		fail("The validateTypes method returned false for a null types element.");
+	  }
+	}
+	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