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/09/27 20:04:26 UTC

svn commit: r292008 - in /incubator/woden/java: src/org/apache/woden/internal/BaseWSDLReader.java src/org/apache/woden/internal/ReaderFeatures.java test/org/apache/woden/internal/ReaderFeaturesTest.java test/org/apache/woden/tests/AllWodenTests.java

Author: lmandel
Date: Tue Sep 27 11:04:18 2005
New Revision: 292008

URL: http://svn.apache.org/viewcvs?rev=292008&view=rev
Log:
Added reader feature class and tests.
Updated base reader to use reader features class.

Added:
    incubator/woden/java/src/org/apache/woden/internal/ReaderFeatures.java
    incubator/woden/java/test/org/apache/woden/internal/ReaderFeaturesTest.java
Modified:
    incubator/woden/java/src/org/apache/woden/internal/BaseWSDLReader.java
    incubator/woden/java/test/org/apache/woden/tests/AllWodenTests.java

Modified: incubator/woden/java/src/org/apache/woden/internal/BaseWSDLReader.java
URL: http://svn.apache.org/viewcvs/incubator/woden/java/src/org/apache/woden/internal/BaseWSDLReader.java?rev=292008&r1=292007&r2=292008&view=diff
==============================================================================
--- incubator/woden/java/src/org/apache/woden/internal/BaseWSDLReader.java (original)
+++ incubator/woden/java/src/org/apache/woden/internal/BaseWSDLReader.java Tue Sep 27 11:04:18 2005
@@ -28,10 +28,13 @@
     private String fFactoryImplName = null;
     
     private ErrorReporter fErrorReporter;
+    
+    private ReaderFeatures features;
 
     //Override the default constructor to throw a WSDL exception
     protected BaseWSDLReader() throws WSDLException {
         fErrorReporter= new ErrorReporter(); 
+        features = new ReaderFeatures();
     }
     
     /**
@@ -153,14 +156,13 @@
             throw new IllegalArgumentException(
                     fErrorReporter.getFormattedMessage("WSDL005", null));
         }
-        else if(name.equals("xyz"))
+        try
         {
-            //TODO determine the required features (e.g. org.apache.woden.verbose) and
-            //create an if block for each one to set the value.
+        	features.setValue(name, value);
         }
-        else
+        catch(IllegalArgumentException e)
         {
-            //feature name is not recognized, so throw an exception
+        	// Feature name is not recognized, so throw an exception.
             Object[] args = new Object[] {name};
             throw new IllegalArgumentException(
                     fErrorReporter.getFormattedMessage("WSDL006", args));
@@ -183,18 +185,13 @@
                     fErrorReporter.getFormattedMessage("WSDL005", null));
         }
         
-        //Return the feature's value or throw an exception if the feature
-        //name is not recognized
-        
-        if(name.equals("xyz"))
+        try
         {
-            //TODO determine the required features (e.g. org.apache.woden.verbose) and
-            //create an if block for each one to get the value.
-            return true;
+        	return features.getValue(name);
         }
-        else
+        catch(IllegalArgumentException e)
         {
-            //feature name is not recognized, so throw an exception
+        	// Feature name is not recognized, so throw an exception.
             Object[] args = new Object[] {name};
             throw new IllegalArgumentException(
                     fErrorReporter.getFormattedMessage("WSDL006", args));

Added: incubator/woden/java/src/org/apache/woden/internal/ReaderFeatures.java
URL: http://svn.apache.org/viewcvs/incubator/woden/java/src/org/apache/woden/internal/ReaderFeatures.java?rev=292008&view=auto
==============================================================================
--- incubator/woden/java/src/org/apache/woden/internal/ReaderFeatures.java (added)
+++ incubator/woden/java/src/org/apache/woden/internal/ReaderFeatures.java Tue Sep 27 11:04:18 2005
@@ -0,0 +1,86 @@
+/**
+ * Copyright 2005 Apached Software Foundation 
+ *
+ * Licensed 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.woden.internal;
+
+import java.util.Hashtable;
+
+/**
+ * This class contains all supported Woden reader features and stores
+ * their values for individual parser configurations.
+ * 
+ * TODO: determine the required features (e.g. org.apache.woden.verbose) and
+ * create an ID for each value.
+ */
+public class ReaderFeatures 
+{
+	/**
+	 * The Woden validation ID. This ID allows the caller to enable or
+	 * disable validation. Defaults to disabled.
+	 */
+	public static String VALIDATION_FEATURE_ID = "http://apache.org/woden/features/validation";
+	
+	/**
+	 * This hashtable contains the values for the features.
+	 */
+	protected Hashtable values = new Hashtable();
+	
+	private Boolean on = new Boolean(true);
+	private Boolean off = new Boolean(false);
+	
+	public ReaderFeatures()
+	{
+	  values.put(VALIDATION_FEATURE_ID, off);
+	}
+	
+	/**
+	 * Get the value for the given feature. 
+	 * @param featureId The ID of the feature for which the value is requested.
+	 * @return true if the feature is enabled, false otherwise.
+	 * @throws IllegalArgumentException if the feature is not supported.
+	 */
+	public boolean getValue(String featureId) throws IllegalArgumentException
+	{
+	  Boolean value = (Boolean)values.get(featureId);
+	  if(value == null)
+	  {
+		throw new IllegalArgumentException("The feature " + featureId + " is not supported.");
+	  }
+	  return value.booleanValue();
+	}
+	
+	/**
+	 * Set the value of the given feature
+	 * @param featureId The ID of the feature to set.
+	 * @param value The value to set for the feature.
+	 * @throws IllegalArgumentException if the feature is not supported.
+	 */
+	public void setValue(String featureId, boolean value) throws IllegalArgumentException
+	{
+		// Check if the feature is supported.
+		if(!values.containsKey(featureId))
+		{
+			throw new IllegalArgumentException("The feature " + featureId + " is not supported.");
+		}
+		if(value)
+		{
+			values.put(featureId, on);
+		}
+		else
+		{
+			values.put(featureId, off);
+		}
+	}
+}

Added: incubator/woden/java/test/org/apache/woden/internal/ReaderFeaturesTest.java
URL: http://svn.apache.org/viewcvs/incubator/woden/java/test/org/apache/woden/internal/ReaderFeaturesTest.java?rev=292008&view=auto
==============================================================================
--- incubator/woden/java/test/org/apache/woden/internal/ReaderFeaturesTest.java (added)
+++ incubator/woden/java/test/org/apache/woden/internal/ReaderFeaturesTest.java Tue Sep 27 11:04:18 2005
@@ -0,0 +1,84 @@
+/**
+ * Copyright 2005 Apached Software Foundation 
+ *
+ * Licensed 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.woden.internal;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit tests for the ReaderFeatures class.
+ * 
+ * TODO: Add tests for all features.
+ */
+public class ReaderFeaturesTest extends TestCase {
+
+	private ReaderFeatures defaultFeatures = new ReaderFeatures();
+	private ReaderFeatures features = new ReaderFeatures();
+	
+	/**
+	 * Test that the validation feature is off by default.
+	 */
+	public void testValidationDefault()
+	{
+		assertFalse("The validation feature is not off by default.", defaultFeatures.getValue(ReaderFeatures.VALIDATION_FEATURE_ID));
+	}
+	
+	/**
+	 * Test that the getValue method throws an exception for invalid
+	 * features.
+	 */
+	public void testGetValueForInvalidFeature()
+	{
+		try
+		{
+			features.getValue("http://invalidfeatureid");
+			fail("An IllegalStateException was not thrown when getValue is called for an invalid feature ID.");
+		}
+		catch(IllegalArgumentException e)
+		{
+			// The successful case will reach here. Nothing to do at this point.
+		}
+	}
+	
+	/**
+	 * Test that the setValue method throws an exception for invalid
+	 * features.
+	 */
+	public void testSetValueForInvalidFeature()
+	{
+		try
+		{
+			features.setValue("http://invalidfeatureid", true);
+			fail("An IllegalStateException was not thrown when setValue is called for an invalid feature ID.");
+		}
+		catch(IllegalArgumentException e)
+		{
+			// The successful case will reach here. Nothing to do at this point.
+		}
+	}
+	
+	/**
+	 * Test that setting values to on or off works correctly.
+	 */
+	public void testSetValue()
+	{
+		features.setValue(ReaderFeatures.VALIDATION_FEATURE_ID, true);
+		assertTrue("The validation feature is not set to true.", features.getValue(ReaderFeatures.VALIDATION_FEATURE_ID));
+		
+		features.setValue(ReaderFeatures.VALIDATION_FEATURE_ID, false);
+		assertFalse("The validation feature is not set to false.", features.getValue(ReaderFeatures.VALIDATION_FEATURE_ID));
+	}
+
+}

Modified: incubator/woden/java/test/org/apache/woden/tests/AllWodenTests.java
URL: http://svn.apache.org/viewcvs/incubator/woden/java/test/org/apache/woden/tests/AllWodenTests.java?rev=292008&r1=292007&r2=292008&view=diff
==============================================================================
--- incubator/woden/java/test/org/apache/woden/tests/AllWodenTests.java (original)
+++ incubator/woden/java/test/org/apache/woden/tests/AllWodenTests.java Tue Sep 27 11:04:18 2005
@@ -5,6 +5,7 @@
 
 import org.apache.woden.WSDLFactoryTest;
 import org.apache.woden.WSDLReaderTest;
+import org.apache.woden.internal.ReaderFeaturesTest;
 import org.apache.woden.tests.wsdl20.W3CTestSuiteTest;
 
 public class AllWodenTests extends TestSuite 
@@ -28,6 +29,7 @@
 	addTest(WSDLFactoryTest.suite());
 	addTest(WSDLReaderTest.suite());
 	addTest(W3CTestSuiteTest.suite());
+	addTestSuite(ReaderFeaturesTest.class);
   }
 	
 }



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