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 jk...@apache.org on 2006/04/11 15:16:02 UTC
svn commit: r393213 - in /incubator/woden/java:
src/org/apache/woden/internal/ src/org/apache/woden/internal/xml/
src/org/apache/woden/xml/ test/org/apache/woden/tests/
test/org/apache/woden/xml/
Author: jkaputin
Date: Tue Apr 11 06:15:59 2006
New Revision: 393213
URL: http://svn.apache.org/viewcvs?rev=393213&view=rev
Log:
Added support for attribute types "xs:token" and
"union of xs:int, xs:token #any", needed for the
HTTP binding extensions. Also added test cases.
Added:
incubator/woden/java/src/org/apache/woden/internal/xml/IntOrTokenAnyAttrImpl.java
incubator/woden/java/src/org/apache/woden/internal/xml/TokenAttrImpl.java
incubator/woden/java/src/org/apache/woden/xml/IntOrTokenAttr.java
incubator/woden/java/src/org/apache/woden/xml/TokenAttr.java
incubator/woden/java/test/org/apache/woden/xml/IntOrTokenAttrTest.java
incubator/woden/java/test/org/apache/woden/xml/TokenAttrTest.java
Modified:
incubator/woden/java/src/org/apache/woden/internal/Messages.properties
incubator/woden/java/test/org/apache/woden/tests/AllWodenTests.java
Modified: incubator/woden/java/src/org/apache/woden/internal/Messages.properties
URL: http://svn.apache.org/viewcvs/incubator/woden/java/src/org/apache/woden/internal/Messages.properties?rev=393213&r1=393212&r2=393213&view=diff
==============================================================================
--- incubator/woden/java/src/org/apache/woden/internal/Messages.properties (original)
+++ incubator/woden/java/src/org/apache/woden/internal/Messages.properties Tue Apr 11 06:15:59 2006
@@ -65,6 +65,7 @@
WSDL509=Could not create a list of QNames from the string "{0}".
WSDL510=Could not create a QName from the string "{0}" within the string of QNames "{1}".
WSDL511=Boolean defaulted to 'false' due to invalid boolean string "{0}".
+WSDL512=Could not create an Integer from the string "{0}".
WSDL520=Extension element "{0}" in the context of "{1}" must not be in the WSDL namespace.
WSDL521=Could not parse an inline schema in the WSDL at URL "{0}".
Added: incubator/woden/java/src/org/apache/woden/internal/xml/IntOrTokenAnyAttrImpl.java
URL: http://svn.apache.org/viewcvs/incubator/woden/java/src/org/apache/woden/internal/xml/IntOrTokenAnyAttrImpl.java?rev=393213&view=auto
==============================================================================
--- incubator/woden/java/src/org/apache/woden/internal/xml/IntOrTokenAnyAttrImpl.java (added)
+++ incubator/woden/java/src/org/apache/woden/internal/xml/IntOrTokenAnyAttrImpl.java Tue Apr 11 06:15:59 2006
@@ -0,0 +1,118 @@
+/**
+ * Copyright 2006 Apache 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.xml;
+
+import org.apache.woden.ErrorReporter;
+import org.apache.woden.WSDLException;
+import org.apache.woden.internal.ErrorLocatorImpl;
+import org.apache.woden.xml.IntOrTokenAttr;
+import org.w3c.dom.Element;
+
+/**
+ * This class represents XML attribute information items of type
+ * "Union of xs:int, xs:token #any"
+ * (e.g. the whttp:code extension attribute of binding fault).
+ *
+ * @author jkaputin@apache.org
+ */
+public class IntOrTokenAnyAttrImpl extends XMLAttrImpl implements IntOrTokenAttr
+{
+
+ /* ************************************************************
+ * QNameOrTokenAttr interface declared methods
+ * ************************************************************/
+
+ /* (non-Javadoc)
+ * @see org.apache.woden.xml.IntOrTokenAttr#isInt()
+ */
+ public boolean isInt()
+ {
+ return fContent instanceof Integer;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.woden.xml.IntOrTokenAttr#isToken()
+ */
+ public boolean isToken()
+ {
+ if(!isInt() && isValid()) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.woden.xml.IntOrTokenAttr#getInt()
+ */
+ public Integer getInt()
+ {
+ if(isInt()) {
+ return (Integer)fContent;
+ } else {
+ return null;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.woden.xml.IntOrTokenAttr#getToken()
+ */
+ public String getToken()
+ {
+ if(!isInt() && isValid()) {
+ return (String)fContent;
+ } else {
+ return null;
+ }
+ }
+
+ /* ************************************************************
+ * Implementation of abstract method inherited from XmlAttrImpl
+ * ************************************************************/
+
+ /* (non-Javadoc)
+ * @see org.apache.woden.internal.xml.XMLAttrImpl#convert(org.w3c.dom.Element, java.lang.String)
+ *
+ * Convert a string of type "Union of xs:int, xs:token #any" to a
+ * java.lang.Integer or a String.
+ * A null argument will return a null value.
+ * Any conversion error will be reported and a null value will be returned.
+ */
+ protected Object convert(Element ownerEl, String attrValue) throws WSDLException
+ {
+ //First, check if the attribute contains the xs:token '#any'.
+ if("#any".equals(attrValue)) return attrValue;
+
+ //Second, assume the attribute contains a xs:int value.
+ Integer intVal = null;
+ try
+ {
+ intVal = new Integer(attrValue);
+ }
+ catch (NumberFormatException e)
+ {
+ setValid(false);
+ getErrorReporter().reportError(
+ new ErrorLocatorImpl(), //TODO line&col nos.
+ "WSDL512",
+ new Object[] {attrValue},
+ ErrorReporter.SEVERITY_ERROR,
+ e);
+ }
+ return intVal;
+ }
+
+}
Added: incubator/woden/java/src/org/apache/woden/internal/xml/TokenAttrImpl.java
URL: http://svn.apache.org/viewcvs/incubator/woden/java/src/org/apache/woden/internal/xml/TokenAttrImpl.java?rev=393213&view=auto
==============================================================================
--- incubator/woden/java/src/org/apache/woden/internal/xml/TokenAttrImpl.java (added)
+++ incubator/woden/java/src/org/apache/woden/internal/xml/TokenAttrImpl.java Tue Apr 11 06:15:59 2006
@@ -0,0 +1,83 @@
+/**
+ * Copyright 2006 Apache 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.xml;
+
+import javax.xml.namespace.QName;
+
+import org.apache.woden.ErrorReporter;
+import org.apache.woden.WSDLException;
+import org.apache.woden.internal.ErrorLocatorImpl;
+import org.apache.woden.xml.TokenAttr;
+import org.w3c.dom.Element;
+
+
+/**
+ * This class represents XML attribute information items of type xs:token.
+ *
+ * TODO when the class org.apache.woden.types.Token has been created, convert the
+ * xs:token to a Token instead of a String and modify the getToken method to return
+ * a Token instead of a String.
+ *
+ * @author jkaputin@apache.org
+ */
+public class TokenAttrImpl extends XMLAttrImpl implements TokenAttr
+{
+ public TokenAttrImpl() {}
+
+ /*
+ * TODO This ctor is not used for extension attributes, but may be useful if
+ * parsing of native WSDL attributes is changed to use the XMLAttr interface.
+ */
+ public TokenAttrImpl(Element ownerEl, QName attrType, String attrValue, ErrorReporter errRpt)
+ throws WSDLException
+ {
+ super(ownerEl, attrType, attrValue, errRpt);
+ }
+
+ /* ************************************************************
+ * TokenAttr interface declared methods
+ * ************************************************************/
+
+ public String getToken() {
+ return (String)getContent();
+ }
+
+ /* ************************************************************
+ * Non-API implementation methods
+ * ************************************************************/
+
+ /*
+ * Convert a string of type xs:token to a java.lang.String (for now, but see 'todo' above).
+ * A null argument will return a null value.
+ * Any conversion error will be reported and a null value will be returned.
+ */
+ protected Object convert(Element ownerEl, String attrValue) throws WSDLException
+ {
+ String str = attrValue;
+
+ if(str == null)
+ {
+ setValid(false);
+ getErrorReporter().reportError(
+ new ErrorLocatorImpl(), //TODO line&col nos.
+ "WSDL508",
+ new Object[] {attrValue},
+ ErrorReporter.SEVERITY_ERROR);
+ }
+ return str;
+ }
+
+}
Added: incubator/woden/java/src/org/apache/woden/xml/IntOrTokenAttr.java
URL: http://svn.apache.org/viewcvs/incubator/woden/java/src/org/apache/woden/xml/IntOrTokenAttr.java?rev=393213&view=auto
==============================================================================
--- incubator/woden/java/src/org/apache/woden/xml/IntOrTokenAttr.java (added)
+++ incubator/woden/java/src/org/apache/woden/xml/IntOrTokenAttr.java Tue Apr 11 06:15:59 2006
@@ -0,0 +1,50 @@
+/**
+ * Copyright 2006 Apache 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.xml;
+
+
+/**
+ * This interface represents XML attribute information items of type
+ * "Union of xs:int, xs:token"
+ * (e.g. the whttp:code extension attribute of binding fault).
+ * <p>
+ * The <code>isInt</code> and <code>isToken</code> methods determine whether
+ * to call the <code>getInt</code> or <code>getToken</code> methods.
+ * If the implementor object is initialized with an int,
+ * <code>isInt</code> will return 'true', <code>isToken</code> will return
+ * 'false', <code>getInt</code> will return the int value and <code>getToken</code>
+ * will return null. If it is initialized with an xs:token, <code>isInt</code>
+ * will return 'false', <code>isToken</code> will return 'true', <code>getInt</code>
+ * will return null and <code>getToken</code> will return the token string.
+ * <p>
+ * If the implementor object is initialized with a null value (i.e. because
+ * of an attribute value conversion error or because the attribute value
+ * was empty in the WSDL), the <code>getContents</code>, <code>getInt</code>
+ * and <code>getToken</code> methods will return null and <code>isInt</code>,
+ * <code>isToken</code> and <code>isValid</code> will return false.
+ *
+ * @author jkaputin@apache.org
+ */
+public interface IntOrTokenAttr extends XMLAttr
+{
+ public boolean isInt();
+
+ public boolean isToken();
+
+ public Integer getInt();
+
+ public String getToken();
+}
Added: incubator/woden/java/src/org/apache/woden/xml/TokenAttr.java
URL: http://svn.apache.org/viewcvs/incubator/woden/java/src/org/apache/woden/xml/TokenAttr.java?rev=393213&view=auto
==============================================================================
--- incubator/woden/java/src/org/apache/woden/xml/TokenAttr.java (added)
+++ incubator/woden/java/src/org/apache/woden/xml/TokenAttr.java Tue Apr 11 06:15:59 2006
@@ -0,0 +1,32 @@
+/**
+ * Copyright 2006 Apache 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.xml;
+
+
+/**
+ * This interface represents XML attribute information items of type xs:token.
+ * If the object is initialized with a null value, the getContents() and getToken()
+ * methods will return null and isValid() will return false.
+ *
+ * TODO create org.apache.woden.types.Token based on the same class in org.apache.axis.types
+ * and modify the getToken method here to return Token instead of String.
+ *
+ * @author jkaputin@apache.org
+ */
+public interface TokenAttr extends XMLAttr
+{
+ public String getToken();
+}
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=393213&r1=393212&r2=393213&view=diff
==============================================================================
--- incubator/woden/java/test/org/apache/woden/tests/AllWodenTests.java (original)
+++ incubator/woden/java/test/org/apache/woden/tests/AllWodenTests.java Tue Apr 11 06:15:59 2006
@@ -32,6 +32,8 @@
import org.apache.woden.wsdl20.extensions.soap.SOAPBindingOperationExtensionsTest;
import org.apache.woden.wsdl20.xml.EndpointElementTest;
import org.apache.woden.wsdl20.xml.ServiceElementTest;
+import org.apache.woden.xml.IntOrTokenAttrTest;
+import org.apache.woden.xml.TokenAttrTest;
public class AllWodenTests extends TestSuite
{
@@ -76,6 +78,8 @@
addTest(WSDLComponentValidatorTest.suite());
addTest(ServiceElementTest.suite());
addTest(EndpointElementTest.suite());
+ addTest(IntOrTokenAttrTest.suite());
+ addTest(TokenAttrTest.suite());
addTest(SOAPBindingExtensionsTest.suite());
addTest(SOAPBindingFaultExtensionsTest.suite());
addTest(SOAPBindingOperationExtensionsTest.suite());
Added: incubator/woden/java/test/org/apache/woden/xml/IntOrTokenAttrTest.java
URL: http://svn.apache.org/viewcvs/incubator/woden/java/test/org/apache/woden/xml/IntOrTokenAttrTest.java?rev=393213&view=auto
==============================================================================
--- incubator/woden/java/test/org/apache/woden/xml/IntOrTokenAttrTest.java (added)
+++ incubator/woden/java/test/org/apache/woden/xml/IntOrTokenAttrTest.java Tue Apr 11 06:15:59 2006
@@ -0,0 +1,137 @@
+/**
+ * Copyright 2006 Apache 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.xml;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.woden.internal.xml.IntOrTokenAnyAttrImpl;
+import org.w3c.dom.Element;
+
+/**
+ * Functional verification test of IntOrTokenAttr.
+ * Checks that the expected API behaviour is supported by the implementation.
+ *
+ * @author jkaputin@apache.org
+ */
+public class IntOrTokenAttrTest extends TestCase
+{
+ private Element el = null; //Element arg not used to initialize this attr
+ private QName qn = new QName("http://wsdl/http","code","whttp");
+ private IntOrTokenAttr attr = null;
+
+ public static Test suite()
+ {
+
+ return new TestSuite(IntOrTokenAttrTest.class);
+ }
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ attr = new IntOrTokenAnyAttrImpl();
+ }
+
+ /*
+ * @see TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ attr = null;
+ }
+
+ public void testAttributeType() throws Exception
+ {
+ String attrVal = "#any";
+ attr.init(el, qn, attrVal);
+ String expectedQN = qn.toString();
+ String actualQN = attr.getAttributeType().toString();
+ assertEquals("Expected attribute type qname '" + expectedQN + "' but actual qname was '" + actualQN + "'.",
+ expectedQN,
+ actualQN );
+ }
+
+ public void testValidToken() throws Exception
+ {
+ String attrVal = "#any";
+ attr.init(el, qn, attrVal);
+
+ assertTrue("isValid() should return true", attr.isValid());
+ assertTrue("getContent() should return instance of 'String' but actual object type was '" + attr.getContent().getClass().getName() + "'.",
+ attr.getContent() instanceof String);
+ assertEquals("Expected toExternalForm() to return '" + attrVal + "' but actual value was '" + attr.toExternalForm() + "'.",
+ attrVal,
+ attr.toExternalForm() );
+
+ assertTrue("isToken() should return true", attr.isToken());
+ assertEquals("Expected getToken() to return the string '#any', but actual string was '" + attr.getToken() + "'.",
+ "#any",
+ attr.getToken() );
+ assertFalse("isInt() should return false", attr.isInt());
+ assertNull("getInt() should return null", attr.getInt());
+ }
+
+ public void testValidInt() throws Exception
+ {
+ String attrVal = "123";
+ attr.init(el, qn, attrVal);
+
+ assertTrue("isValid() should return true", attr.isValid());
+ assertTrue("getContent() should return instance of 'Integer' but actual object type was '" + attr.getContent().getClass().getName() + "'.",
+ attr.getContent() instanceof Integer);
+ assertEquals("Expected toExternalForm() to return '" + attrVal + "' but actual value was '" + attr.toExternalForm() + "'.",
+ attrVal,
+ attr.toExternalForm() );
+
+ assertTrue("isInt() should return true", attr.isInt());
+ assertEquals("Expected getInt() to return 123, but actual value was '" + attr.getInt() + "'.",
+ new Integer("123"),
+ attr.getInt() );
+ assertFalse("isToken() should return false", attr.isToken());
+ assertNull("getToken() should return null", attr.getToken());
+ }
+
+ public void testInvalidValue() throws Exception
+ {
+ String attrVal = "#rubbish";
+ attr.init(el, qn, attrVal);
+
+ assertFalse("isValid() should return false", attr.isValid());
+ assertFalse("isInt() should return false", attr.isInt());
+ assertFalse("isToken() should return false", attr.isToken());
+ assertNull("getInt() should return null", attr.getInt());
+ assertNull("getToken() should return null", attr.getToken());
+ }
+
+ public void testNullValue() throws Exception
+ {
+ String attrVal = null;
+ attr.init(el, qn, attrVal);
+
+ assertFalse("isValid() should return false", attr.isValid());
+ assertFalse("isInt() should return false", attr.isInt());
+ assertFalse("isToken() should return false", attr.isToken());
+ assertNull("getInt() should return null", attr.getInt());
+ assertNull("getToken() should return null", attr.getToken());
+ }
+}
Added: incubator/woden/java/test/org/apache/woden/xml/TokenAttrTest.java
URL: http://svn.apache.org/viewcvs/incubator/woden/java/test/org/apache/woden/xml/TokenAttrTest.java?rev=393213&view=auto
==============================================================================
--- incubator/woden/java/test/org/apache/woden/xml/TokenAttrTest.java (added)
+++ incubator/woden/java/test/org/apache/woden/xml/TokenAttrTest.java Tue Apr 11 06:15:59 2006
@@ -0,0 +1,96 @@
+/**
+ * Copyright 2006 Apache 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.xml;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.woden.internal.xml.TokenAttrImpl;
+import org.w3c.dom.Element;
+
+/**
+ * Functional verification test of TokenAttr.
+ * Checks that the expected API behaviour is supported by the implementation.
+ *
+ * @author jkaputin@apache.org
+ */
+public class TokenAttrTest extends TestCase
+{
+ private Element el = null; //Element arg not used to initialize this attr
+ private QName qn = new QName("http://wsdl/http","authenticationType","whttp");;
+ private TokenAttr attr = null;
+
+ public static Test suite()
+ {
+ return new TestSuite(TokenAttrTest.class);
+ }
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ attr = new TokenAttrImpl();
+ }
+
+ /*
+ * @see TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ attr = null;
+ }
+
+ public void testAttributeType() throws Exception
+ {
+ String attrVal = "#any";
+ attr.init(el, qn, attrVal);
+ String expectedQN = qn.toString();
+ String actualQN = attr.getAttributeType().toString();
+ assertEquals("Expected attribute type qname '" + expectedQN + "' but actual qname was '" + actualQN + "'.",
+ expectedQN,
+ actualQN );
+ }
+
+ public void testValidToken() throws Exception
+ {
+ String attrVal = "#any";
+ attr.init(el, qn, attrVal);
+ assertTrue("isValid() should return true", attr.isValid());
+
+ assertNotNull("getToken() should not return null", attr.getToken());
+ assertEquals("Expected attribute value '#any' from getToken(), but actual value was '" + attr.getToken() + "'.",
+ "#any",
+ attr.getToken() );
+ assertTrue("Expected attribute value object to be a 'String' but actual object type was '" + attr.getContent().getClass().getName() + "'.",
+ attr.getContent() instanceof String);
+ assertTrue("Expected external form '#any' but actual was '" + attr.toExternalForm() + "'.",
+ "#any".equals(attr.toExternalForm()) );
+ }
+
+ public void testNullValue() throws Exception
+ {
+ String attrVal = null;
+ attr.init(el, qn, attrVal);
+ assertNull("Attribute value is not null", attr.getToken());
+ assertFalse("Attribute value should not be valid", attr.isValid());
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: woden-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: woden-dev-help@ws.apache.org