KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > encoding > TypeMappingDelegate


1 /*
2  * Copyright 2001-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 org.apache.axis.encoding;
18
19 import org.apache.axis.utils.Messages;
20 import org.apache.axis.Constants;
21
22 import javax.xml.namespace.QName JavaDoc;
23 import javax.xml.rpc.JAXRPCException JavaDoc;
24
25 /**
26  * The TypeMapping delegate is used to simply delegate to
27  * the indicated type mapping. It is used by the TypeMappingRegistry
28  * to assist with chaining.
29  *
30  * @author Rich Scheuerle (scheu@us.ibm.com)
31  */

32 public class TypeMappingDelegate implements TypeMapping {
33     static final TypeMappingImpl placeholder = new TypeMappingImpl();
34
35     TypeMappingImpl delegate;
36     TypeMappingDelegate next;
37
38     /**
39      * Construct TypeMapping
40      */

41     TypeMappingDelegate(TypeMappingImpl delegate) {
42         if (delegate == null) {
43             throw new RuntimeException JavaDoc(Messages.getMessage("NullDelegate"));
44         }
45         this.delegate = delegate;
46     }
47
48
49     /********* JAX-RPC Compliant Method Definitions *****************/
50
51     // Delegate or throw an exception
52

53     public String JavaDoc[] getSupportedEncodings() {
54         return delegate.getSupportedEncodings();
55     }
56
57     public void setSupportedEncodings(String JavaDoc[] namespaceURIs) {
58         delegate.setSupportedEncodings(namespaceURIs);
59     }
60
61     /**
62      * always throws an exception
63      * @param javaType
64      * @param xmlType
65      * @param sf
66      * @param dsf
67      * @throws JAXRPCException
68      */

69     public void register(Class JavaDoc javaType, QName JavaDoc xmlType,
70                          javax.xml.rpc.encoding.SerializerFactory JavaDoc sf,
71                          javax.xml.rpc.encoding.DeserializerFactory JavaDoc dsf)
72         throws JAXRPCException JavaDoc {
73         delegate.register(javaType, xmlType, sf, dsf);
74     }
75     
76     public javax.xml.rpc.encoding.SerializerFactory JavaDoc
77         getSerializer(Class JavaDoc javaType, QName JavaDoc xmlType)
78         throws JAXRPCException JavaDoc
79     {
80         javax.xml.rpc.encoding.SerializerFactory JavaDoc sf = delegate.getSerializer(javaType, xmlType);
81
82         if (sf == null && next != null) {
83             sf = next.getSerializer(javaType, xmlType);
84         }
85
86         if (sf == null) {
87             sf = delegate.finalGetSerializer(javaType);
88         }
89
90         return sf;
91     }
92     public javax.xml.rpc.encoding.SerializerFactory JavaDoc
93         getSerializer(Class JavaDoc javaType)
94         throws JAXRPCException JavaDoc
95     {
96         return getSerializer(javaType, null);
97     }
98
99     public javax.xml.rpc.encoding.DeserializerFactory JavaDoc
100         getDeserializer(Class JavaDoc javaType, QName JavaDoc xmlType)
101         throws JAXRPCException JavaDoc {
102         return getDeserializer(javaType, xmlType, this);
103     }
104
105     public javax.xml.rpc.encoding.DeserializerFactory JavaDoc
106             getDeserializer(Class JavaDoc javaType, QName JavaDoc xmlType, TypeMappingDelegate start)
107             throws JAXRPCException JavaDoc {
108         javax.xml.rpc.encoding.DeserializerFactory JavaDoc df =
109                 delegate.getDeserializer(javaType, xmlType, start);
110         if (df == null && next != null) {
111             df = next.getDeserializer(javaType, xmlType, start);
112         }
113         if (df == null) {
114             df = delegate.finalGetDeserializer(javaType, xmlType, start);
115         }
116         return df;
117     }
118
119     public javax.xml.rpc.encoding.DeserializerFactory JavaDoc
120         getDeserializer(QName JavaDoc xmlType)
121         throws JAXRPCException JavaDoc {
122         return getDeserializer(null, xmlType);
123     }
124
125     public void removeSerializer(Class JavaDoc javaType, QName JavaDoc xmlType)
126         throws JAXRPCException JavaDoc {
127         delegate.removeSerializer(javaType, xmlType);
128     }
129
130     public void removeDeserializer(Class JavaDoc javaType, QName JavaDoc xmlType)
131         throws JAXRPCException JavaDoc {
132         delegate.removeDeserializer(javaType, xmlType);
133     }
134
135    public boolean isRegistered(Class JavaDoc javaType, QName JavaDoc xmlType) {
136        boolean result = delegate.isRegistered(javaType, xmlType);
137        if (result == false && next != null) {
138            return next.isRegistered(javaType, xmlType);
139        }
140        return result;
141    }
142
143     /********* End JAX-RPC Compliant Method Definitions *****************/
144      
145     /**
146      * Gets the QName for the type mapped to Class.
147      * @param javaType class or type
148      * @return xmlType qname or null
149      */

150     public QName JavaDoc getTypeQName(Class JavaDoc javaType) {
151         return delegate.getTypeQName(javaType, next);
152     }
153     
154     /**
155      * Gets the Class mapped to QName.
156      * @param xmlType qname or null
157      * @return javaType class for type or null for no mappingor delegate
158      */

159     public Class JavaDoc getClassForQName(QName JavaDoc xmlType) {
160         return getClassForQName(xmlType, null);
161     }
162
163     /**
164      * Gets the Class mapped to QName, preferring the passed Class if possible
165      * @param xmlType qname or null
166      * @param javaType a Java class
167      * @return javaType class for type or null for no mappingor delegate
168      */

169     public Class JavaDoc getClassForQName(QName JavaDoc xmlType, Class JavaDoc javaType) {
170         return delegate.getClassForQName(xmlType, javaType, next);
171     }
172
173     /**
174      * Get the QName for this Java class, but only return a specific
175      * mapping if there is one. In other words, don't do special array
176      * processing, etc.
177      *
178      * @param javaType
179      * @return
180      */

181     public QName JavaDoc getTypeQNameExact(Class JavaDoc javaType) {
182         QName JavaDoc result = delegate.getTypeQNameExact(javaType, next);
183
184         return result;
185     }
186
187     /**
188      * setDelegate sets the new Delegate TypeMapping
189      */

190     public void setNext(TypeMappingDelegate next) {
191         if (next == this) {
192             return; // Refuse to set up tight loops (throw exception?)
193
}
194         this.next = next;
195     }
196
197     /**
198      * getDelegate gets the new Delegate TypeMapping
199      */

200     public TypeMappingDelegate getNext() {
201         return next;
202     }
203
204     /**
205      * Returns an array of all the classes contained within this mapping
206      */

207     public Class JavaDoc[] getAllClasses() {
208         return delegate.getAllClasses(next);
209     }
210
211     /**
212      * Get the exact XML type QName which will be used when serializing a
213      * given Class to a given type QName. In other words, if we have:
214      *
215      * Class TypeQName
216      * ----------------------
217      * Base myNS:Base
218      * Child myNS:Child
219      *
220      * and call getXMLType(Child.class, BASE_QNAME), we should get
221      * CHILD_QNAME.
222      *
223      * @param javaType
224      * @param xmlType
225      * @return the type's QName
226      * @throws JAXRPCException
227      */

228     public QName JavaDoc getXMLType(Class JavaDoc javaType, QName JavaDoc xmlType, boolean encoded)
229             throws JAXRPCException JavaDoc {
230         QName JavaDoc result = delegate.getXMLType(javaType, xmlType, encoded);
231         if (result == null && next != null) {
232             return next.getXMLType(javaType, xmlType, encoded);
233         }
234         return result;
235     }
236
237     public void setDoAutoTypes(boolean doAutoTypes) {
238         delegate.setDoAutoTypes(doAutoTypes);
239     }
240 }
241
Popular Tags