KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > wsif > base > PrivateCompositeExtensionRegistry


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2002 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "WSIF" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation and was
52  * originally based on software copyright (c) 2001, 2002, International
53  * Business Machines, Inc., http://www.apache.org. For more
54  * information on the Apache Software Foundation, please see
55  * <http://www.apache.org/>.
56  */

57
58 package org.apache.wsif.base;
59
60 import java.util.Enumeration;
61 import java.util.Vector;
62
63 import javax.wsdl.WSDLException;
64 import javax.wsdl.extensions.ExtensibilityElement;
65 import javax.wsdl.extensions.ExtensionDeserializer;
66 import javax.wsdl.extensions.ExtensionRegistry;
67 import javax.wsdl.extensions.ExtensionSerializer;
68 import javax.wsdl.extensions.UnknownExtensionDeserializer;
69 import javax.wsdl.extensions.UnknownExtensionSerializer;
70 import javax.xml.namespace.QName;
71
72 import org.apache.wsif.logging.Trc;
73 import org.apache.wsif.wsdl.extensions.ejb.EJBBindingSerializer;
74 import org.apache.wsif.wsdl.extensions.format.FormatBindingSerializer;
75 import org.apache.wsif.wsdl.extensions.java.JavaBindingSerializer;
76
77 import com.ibm.wsdl.extensions.PopulatedExtensionRegistry;
78
79 /**
80  * This is utility class that allows to aggregate multiple
81  * extensions registries into one. By default all standard WSDL4J
82  * extensions are made available.
83  *
84  * @author Alekander Slominski
85  * @author Sanjiva Weerawarana
86  * @author Owen Burroughs <owenb@apache.org>
87  * @author Ant Elder <antelder@apache.org>
88  * @author Jeremy Hughes <hughesj@apache.org>
89  * @author Mark Whitlock <whitlock@apache.org>
90  */

91
92 class PrivateCompositeExtensionRegistry extends ExtensionRegistry {
93     private static final long serialVersionUID = 1L;
94     private Vector extRegs = new Vector();
95
96     PrivateCompositeExtensionRegistry() {
97         Trc.entry(this);
98
99         // Add (de)serializers for Java, EJB and Format extensions to the
100
// PopulatedExetensionRegistry and add the registry to our list
101
PopulatedExtensionRegistry per = new PopulatedExtensionRegistry();
102         JavaBindingSerializer javaBindingSerializer = new JavaBindingSerializer();
103         javaBindingSerializer.registerSerializer(per);
104         FormatBindingSerializer formatSerializer = new FormatBindingSerializer();
105         formatSerializer.registerSerializer(per);
106         EJBBindingSerializer ejbBindingSerializer = new EJBBindingSerializer();
107         ejbBindingSerializer.registerSerializer(per);
108         extRegs.add(per);
109         Trc.exit();
110     }
111
112     public void addExtensionRegistry(ExtensionRegistry reg) {
113         Trc.entry(this, reg);
114         extRegs.add(reg);
115         Trc.exit();
116     }
117
118     public void registerSerializer(
119         Class parentType,
120         Class extensionType,
121         ExtensionSerializer es) {
122         throw new RuntimeException(
123             getClass() + " does not allow to register serializers");
124     }
125
126     public void registerDeserializer(
127         Class parentType,
128         QName elementType,
129         ExtensionDeserializer ed) {
130         throw new RuntimeException(
131             getClass() + " does not allow to register deserializers");
132     }
133
134     public ExtensionSerializer querySerializer(
135         Class parentType,
136         QName extensionType)
137         throws WSDLException {
138         Trc.entry(this, parentType, extensionType);
139
140         ExtensionSerializer ser;
141         Enumeration enum = extRegs.elements();
142         while (enum.hasMoreElements()) {
143             ExtensionRegistry reg = (ExtensionRegistry) enum.nextElement();
144             try {
145                 ser = reg.querySerializer(parentType, extensionType);
146                 // Check that we're not looking at the default serializer
147
ExtensionSerializer def = reg.getDefaultSerializer();
148                 if (ser != null && !(ser.equals(def))) {
149                     Trc.exit(ser);
150                     return ser;
151                 }
152             } catch (WSDLException ex) {
153                 Trc.exception(ex);
154                 throw ex;
155             }
156         }
157         ser = new UnknownExtensionSerializer();
158         Trc.exit();
159         return ser;
160     }
161
162     public ExtensionDeserializer queryDeserializer(
163         Class parentType,
164         QName elementType)
165         throws WSDLException {
166         Trc.entry(this, parentType, elementType);
167
168         ExtensionDeserializer deser;
169         Enumeration enum = extRegs.elements();
170         while (enum.hasMoreElements()) {
171             ExtensionRegistry reg = (ExtensionRegistry) enum.nextElement();
172             try {
173                 deser = reg.queryDeserializer(parentType, elementType);
174                 // Check that we're not looking at the default deserializer
175
ExtensionDeserializer def = reg.getDefaultDeserializer();
176                 if (deser != null && !(deser.equals(def))) {
177                     Trc.exit(deser);
178                     return deser;
179                 }
180             } catch (WSDLException ex) {
181                 Trc.exception(ex);
182                 throw ex;
183             }
184         }
185         deser = new UnknownExtensionDeserializer();
186         Trc.exit(deser);
187         return deser;
188     }
189
190     public ExtensibilityElement createExtension(
191         Class parentType,
192         QName elementType)
193         throws WSDLException {
194         Trc.entry(this, parentType, elementType);
195
196         ExtensibilityElement ee;
197         Enumeration enum = extRegs.elements();
198         while (enum.hasMoreElements()) {
199             ExtensionRegistry reg = (ExtensionRegistry) enum.nextElement();
200             try {
201                 ee = reg.createExtension(parentType, elementType);
202                 Trc.exit(ee);
203                 return ee;
204             } catch (WSDLException ignored) {
205                 Trc.ignoredException(ignored);
206             }
207         }
208         ee = super.createExtension(parentType, elementType);
209         Trc.exit(ee);
210         return ee;
211     }
212
213 }
214
Popular Tags