KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > samples > jpetstore > service > client > BeanMappingServicePostProcessor


1 package org.springframework.samples.jpetstore.service.client;
2
3 import javax.xml.namespace.QName JavaDoc;
4 import javax.xml.rpc.Service JavaDoc;
5 import javax.xml.rpc.encoding.TypeMapping JavaDoc;
6 import javax.xml.rpc.encoding.TypeMappingRegistry JavaDoc;
7
8 import org.apache.axis.encoding.ser.BeanDeserializerFactory;
9 import org.apache.axis.encoding.ser.BeanSerializerFactory;
10
11 import org.springframework.remoting.jaxrpc.JaxRpcServicePostProcessor;
12 import org.springframework.samples.jpetstore.domain.Item;
13 import org.springframework.samples.jpetstore.domain.LineItem;
14 import org.springframework.samples.jpetstore.domain.Order;
15 import org.springframework.samples.jpetstore.domain.Product;
16
17 /**
18  * Axis-specific JaxRpcServicePostProcessor that registers bean mappings
19  * for JPetStore's domain objects. The same mappings are also registered
20  * at the server, in Axis' "server-config.wsdd" file.
21  *
22  * <p>Note: Without such explicit bean mappings, a complex type like
23  * <code>org.springframework.samples.jpetstore.domain.Order</code>
24  * cannot be transferred via SOAP.
25  *
26  * @author Juergen Hoeller
27  * @since 1.1.4
28  * @see org.springframework.samples.jpetstore.domain.Order
29  * @see org.springframework.samples.jpetstore.domain.LineItem
30  * @see org.springframework.samples.jpetstore.domain.Item
31  * @see org.springframework.samples.jpetstore.domain.Product
32  * @see org.apache.axis.encoding.ser.BeanDeserializerFactory
33  * @see org.apache.axis.encoding.ser.BeanSerializerFactory
34  */

35 public class BeanMappingServicePostProcessor implements JaxRpcServicePostProcessor {
36
37     /**
38      * Default encoding style URI, as suggested by the JAX-RPC javadoc:
39      * "http://schemas.xmlsoap.org/soap/encoding/"
40      * @see javax.xml.rpc.encoding.TypeMappingRegistry#register
41      */

42     public static final String JavaDoc DEFAULT_ENCODING_STYLE_URI = "http://schemas.xmlsoap.org/soap/encoding/";
43
44     /**
45      * Default namespace to use for custom XML types.
46      * @see javax.xml.rpc.encoding.TypeMapping#register
47      */

48     public static final String JavaDoc DEFAULT_TYPE_NAMESPACE_URI = "urn:JPetStore";
49
50
51     private String JavaDoc encodingStyleUri = DEFAULT_ENCODING_STYLE_URI;
52
53     private String JavaDoc typeNamespaceUri = DEFAULT_TYPE_NAMESPACE_URI;
54
55
56     /**
57      * Set the encoding style URI to use for the type mapping.
58      * @see javax.xml.rpc.encoding.TypeMappingRegistry#register
59      */

60     public void setEncodingStyleUri(String JavaDoc encodingStyleUri) {
61         this.encodingStyleUri = encodingStyleUri;
62     }
63
64     /**
65      * Set the namespace to use for custom XML types.
66      * @see javax.xml.rpc.encoding.TypeMapping#register
67      */

68     public void setTypeNamespaceUri(String JavaDoc typeNamespaceUri) {
69         this.typeNamespaceUri = typeNamespaceUri;
70     }
71
72
73     public void postProcessJaxRpcService(Service JavaDoc service) {
74         TypeMappingRegistry JavaDoc registry = service.getTypeMappingRegistry();
75         TypeMapping JavaDoc mapping = registry.createTypeMapping();
76         registerBeanMapping(mapping, Order.class, "Order");
77         registerBeanMapping(mapping, LineItem.class, "LineItem");
78         registerBeanMapping(mapping, Item.class, "Item");
79         registerBeanMapping(mapping, Product.class, "Product");
80         registry.register(this.encodingStyleUri, mapping);
81     }
82
83     protected void registerBeanMapping(TypeMapping JavaDoc mapping, Class JavaDoc type, String JavaDoc name) {
84         QName JavaDoc xmlType = new QName JavaDoc(this.typeNamespaceUri, name);
85         mapping.register(type, xmlType,
86             new BeanSerializerFactory(type, xmlType),
87             new BeanDeserializerFactory(type, xmlType));
88     }
89
90 }
91
Popular Tags