You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by aj...@apache.org on 2005/02/11 05:17:35 UTC
svn commit: r153344 - in webservices/axis/trunk/java/dev/scratch/prototype2:
maven.xml src/test/org/apache/axis/testUtils/SimpleTypeEncoder.java
src/test/org/apache/axis/testUtils/SimpleTypeEncodingUtils.java
Author: ajith
Date: Thu Feb 10 20:17:33 2005
New Revision: 153344
URL: http://svn.apache.org/viewcvs?view=rev&rev=153344
Log:
Modified the build and the encoders and decoders to complete the samples
Modified:
webservices/axis/trunk/java/dev/scratch/prototype2/maven.xml
webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/testUtils/SimpleTypeEncoder.java
webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/testUtils/SimpleTypeEncodingUtils.java
Modified: webservices/axis/trunk/java/dev/scratch/prototype2/maven.xml
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/dev/scratch/prototype2/maven.xml?view=diff&r1=153343&r2=153344
==============================================================================
--- webservices/axis/trunk/java/dev/scratch/prototype2/maven.xml (original)
+++ webservices/axis/trunk/java/dev/scratch/prototype2/maven.xml Thu Feb 10 20:17:33 2005
@@ -46,5 +46,6 @@
<goal name="samples">
<ant:ant antfile="build.xml" inheritall="true" inheritrefs="true" dir="src/samples/encoding/sample1"/>
+ <ant:ant antfile="build.xml" inheritall="true" inheritrefs="true" dir="src/samples/encoding/sample2"/>
</goal>
</project>
Modified: webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/testUtils/SimpleTypeEncoder.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/testUtils/SimpleTypeEncoder.java?view=diff&r1=153343&r2=153344
==============================================================================
--- webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/testUtils/SimpleTypeEncoder.java (original)
+++ webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/testUtils/SimpleTypeEncoder.java Thu Feb 10 20:17:33 2005
@@ -1,18 +1,18 @@
/*
- * Copyright 2003,2004 The 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.
- */
+* Copyright 2003,2004 The 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.axis.testUtils;
import javax.xml.stream.XMLStreamReader;
@@ -27,21 +27,19 @@
public class SimpleTypeEncoder implements Encoder{
private Object obj = null;
public SimpleTypeEncoder(Object obj){
- this.obj = obj;
+ this.obj = obj;
}
-
-
+
+
public void serialize(ContentHandler cHandler) throws OMException {
try {
- if(obj instanceof String){
- char[] str = ((String)obj).toCharArray();
- cHandler.characters(str,0,str.length);
- }else if(obj instanceof Integer){
- char[] str = obj.toString().toCharArray();
+ char[] str=null;
+ if(obj.getClass() == String.class){
+ str = ((String)obj).toCharArray();
cHandler.characters(str,0,str.length);
- }else if(obj instanceof String[]){
+ }else if(obj.getClass() == String[].class){
String[] strs = (String[])obj;
- char[] str = null;
+ str = null;
for (int i = 0; i < strs.length; i++) {
cHandler.startElement(OMConstants.ARRAY_ITEM_NSURI,
OMConstants.ARRAY_ITEM_LOCALNAME,
@@ -51,6 +49,35 @@
cHandler.characters(str,0,str.length);
cHandler.endElement(OMConstants.ARRAY_ITEM_NSURI,OMConstants.ARRAY_ITEM_LOCALNAME, OMConstants.ARRAY_ITEM_QNAME );
}
+ }else if(obj.getClass() == Integer.class){
+ str = obj.toString().toCharArray();
+ cHandler.characters(str,0,str.length);
+ }else if(obj.getClass() == int[].class){
+ int[] intArray = (int[])obj;
+ for (int i = 0; i < intArray.length; i++) {
+ cHandler.startElement(OMConstants.ARRAY_ITEM_NSURI,
+ OMConstants.ARRAY_ITEM_LOCALNAME,
+ OMConstants.ARRAY_ITEM_QNAME ,
+ null);
+ str = String.valueOf(intArray[i]).toCharArray();
+ cHandler.characters(str,0,str.length);
+ cHandler.endElement(OMConstants.ARRAY_ITEM_NSURI,OMConstants.ARRAY_ITEM_LOCALNAME, OMConstants.ARRAY_ITEM_QNAME );
+ }
+
+ }else if(obj.getClass() == Double.class){
+ str = obj.toString().toCharArray();
+ cHandler.characters(str,0,str.length);
+ }else if(obj.getClass() == double[].class){
+ double[] doubleArray = (double[])obj;
+ for (int i = 0; i < doubleArray.length; i++) {
+ cHandler.startElement(OMConstants.ARRAY_ITEM_NSURI,
+ OMConstants.ARRAY_ITEM_LOCALNAME,
+ OMConstants.ARRAY_ITEM_QNAME ,
+ null);
+ str = String.valueOf(doubleArray[i]).toCharArray();
+ cHandler.characters(str,0,str.length);
+ cHandler.endElement(OMConstants.ARRAY_ITEM_NSURI,OMConstants.ARRAY_ITEM_LOCALNAME, OMConstants.ARRAY_ITEM_QNAME );
+ }
}else{
throw new OMException("Unsupported type");
@@ -62,15 +89,15 @@
}
/* (non-Javadoc)
- * @see org.apache.axis.encoding.Encoder#deSerialize(javax.xml.stream.XMLStreamReader)
- */
+ * @see org.apache.axis.encoding.Encoder#deSerialize(javax.xml.stream.XMLStreamReader)
+ */
public Object deSerialize(XMLStreamReader xpp) throws AxisFault {
throw new UnsupportedOperationException();
}
/* (non-Javadoc)
- * @see org.apache.axis.encoding.Encoder#setObject(java.lang.Object)
- */
+ * @see org.apache.axis.encoding.Encoder#setObject(java.lang.Object)
+ */
public void setObject(Object obj) {
this.obj =obj;
}
Modified: webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/testUtils/SimpleTypeEncodingUtils.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/testUtils/SimpleTypeEncodingUtils.java?view=diff&r1=153343&r2=153344
==============================================================================
--- webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/testUtils/SimpleTypeEncodingUtils.java (original)
+++ webservices/axis/trunk/java/dev/scratch/prototype2/src/test/org/apache/axis/testUtils/SimpleTypeEncodingUtils.java Thu Feb 10 20:17:33 2005
@@ -108,6 +108,81 @@
}
return Integer.parseInt(val);
}
+
+ public static double deserializeDouble(XMLStreamReader xpp) throws AxisFault {
+ String val = deserializeString(xpp);
+ if (val == null) {
+ throw new AxisFault("Number format exception value is null");
+ }
+ return Double.parseDouble(val);
+ }
+
+ public static int[] deserializeIntArray(XMLStreamReader xpp)
+ throws AxisFault {
+ ArrayList ints = new ArrayList();
+
+ try {
+ int event = xpp.next();
+
+ while (true) {
+ if (XMLStreamConstants.START_ELEMENT == event) {
+ String stringValue = deserializeString(xpp);
+ if (stringValue==null){
+ throw new AxisFault("Wrong type of argument");
+ }
+ ints.add(stringValue);
+ } else if (XMLStreamConstants.END_ELEMENT == event) {
+ break;
+ } else if (XMLStreamConstants.END_DOCUMENT == event) {
+ throw new AxisFault("premature end of file");
+ }
+ event = xpp.next();
+ }
+ int intCount = ints.size();
+ int[] intVals = new int[intCount];
+ for (int i = 0; i < intCount; i++) {
+ intVals[i] = Integer.parseInt(ints.get(i).toString());
+ }
+ return intVals;
+ } catch (XMLStreamException e) {
+ throw AxisFault.makeFault(e);
+ }
+
+ }
+
+ public static double[] deserializeDoubleArray(XMLStreamReader xpp)
+ throws AxisFault {
+ ArrayList doubles = new ArrayList();
+
+ try {
+ int event = xpp.next();
+
+ while (true) {
+ if (XMLStreamConstants.START_ELEMENT == event) {
+ String stringValue = deserializeString(xpp);
+ if (stringValue==null){
+ throw new AxisFault("Wrong type of argument");
+ }
+ doubles.add(stringValue);
+ } else if (XMLStreamConstants.END_ELEMENT == event) {
+ break;
+ } else if (XMLStreamConstants.END_DOCUMENT == event) {
+ throw new AxisFault("premature end of file");
+ }
+ event = xpp.next();
+ }
+ int doubleCount = doubles.size();
+ double[] doubleVals = new double[doubleCount];
+ for (int i = 0; i < doubleCount; i++) {
+ doubleVals[i] = Double.parseDouble(doubles.get(i).toString());
+ }
+ return doubleVals;
+ } catch (XMLStreamException e) {
+ throw AxisFault.makeFault(e);
+ }
+
+ }
+
public static void serialize(
XMLStreamWriter out,
QName elementName,