KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > encoding > TestGlobalTypeMappings


1 /*
2  * Copyright 2002-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package test.encoding;
18
19 import org.apache.axis.client.Call;
20 import org.apache.axis.encoding.TypeMapping;
21 import org.apache.axis.encoding.ser.BeanDeserializerFactory;
22 import org.apache.axis.encoding.ser.BeanSerializerFactory;
23 import org.apache.axis.constants.Style;
24 import test.GenericLocalTest;
25
26 import javax.xml.namespace.QName JavaDoc;
27 import javax.xml.rpc.ParameterMode JavaDoc;
28
29 /**
30  * Confirm that global type mappings work in both RPC and Document
31  * contexts.
32  *
33  * @author Glen Daniels (gdaniels@apache.org)
34  */

35 public class TestGlobalTypeMappings extends GenericLocalTest {
36     private QName JavaDoc TYPE_QNAME = new QName JavaDoc("ns", "dataType");
37
38     public TestGlobalTypeMappings() {
39         super("service");
40     }
41
42     public TestGlobalTypeMappings(String JavaDoc s) {
43         super(s);
44     }
45
46     protected void setUp() throws Exception JavaDoc {
47         super.setUp(false); // don't deploy here
48
TypeMapping tm = (TypeMapping)config.getTypeMappingRegistry().
49                 getDefaultTypeMapping();
50         tm.register(Data.class, TYPE_QNAME,
51                     new BeanSerializerFactory(Data.class, TYPE_QNAME),
52                     new BeanDeserializerFactory(Data.class, TYPE_QNAME));
53     }
54
55     public void testDocLit() throws Exception JavaDoc {
56         deploy("service", this.getClass(), Style.WRAPPED);
57         Call call = getCall();
58         call.setOperationStyle("wrapped");
59         call.setOperationUse("literal");
60         call.setEncodingStyle("");
61         call.registerTypeMapping(Data.class, TYPE_QNAME,
62                     new BeanSerializerFactory(Data.class, TYPE_QNAME),
63                     new BeanDeserializerFactory(Data.class, TYPE_QNAME));
64         call.setReturnClass(Data.class);
65         call.addParameter("arg0", TYPE_QNAME, ParameterMode.IN);
66         Data data = new Data();
67         data.stringMember = "doc lit test";
68         data.floatMember = new Float JavaDoc(451.0F);
69         call.invoke("echoData", new Object JavaDoc [] { data });
70     }
71
72     /**
73      * Our service method. We'll deploy this several ways.
74      *
75      * @param data
76      * @return
77      */

78     public Data echoData(Data data) {
79         return data;
80     }
81 }
82
Popular Tags