KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > customization > model > impl > JAXWSElementFactoryProvider


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 /*
20  * JAXWSElementFactoryProvider.java
21  *
22  * Created on February 22, 2006, 9:40 PM
23  *
24  * To change this template, choose Tools | Template Manager
25  * and open the template in the editor.
26  */

27
28 package org.netbeans.modules.websvc.customization.model.impl;
29
30 import java.util.ArrayList JavaDoc;
31 import java.util.Collection JavaDoc;
32 import java.util.Collections JavaDoc;
33 import java.util.Set JavaDoc;
34 import javax.xml.namespace.QName JavaDoc;
35 import org.netbeans.modules.websvc.customization.model.BindingCustomization;
36 import org.netbeans.modules.websvc.customization.model.BindingOperationCustomization;
37 import org.netbeans.modules.websvc.customization.model.DefinitionsCustomization;
38 import org.netbeans.modules.websvc.customization.model.EnableAsyncMapping;
39 import org.netbeans.modules.websvc.customization.model.EnableMIMEContent;
40 import org.netbeans.modules.websvc.customization.model.EnableWrapperStyle;
41 import org.netbeans.modules.websvc.customization.model.JavaClass;
42 import org.netbeans.modules.websvc.customization.model.JavaDoc;
43 import org.netbeans.modules.websvc.customization.model.JavaException;
44 import org.netbeans.modules.websvc.customization.model.JavaMethod;
45 import org.netbeans.modules.websvc.customization.model.JavaPackage;
46 import org.netbeans.modules.websvc.customization.model.JavaParameter;
47 import org.netbeans.modules.websvc.customization.model.PortCustomization;
48 import org.netbeans.modules.websvc.customization.model.PortTypeCustomization;
49 import org.netbeans.modules.websvc.customization.model.PortTypeOperationCustomization;
50 import org.netbeans.modules.websvc.customization.model.PortTypeOperationFaultCustomization;
51 import org.netbeans.modules.websvc.customization.model.Provider;
52 import org.netbeans.modules.websvc.customization.model.ServiceCustomization;
53 import org.netbeans.modules.xml.wsdl.model.Binding;
54 import org.netbeans.modules.xml.wsdl.model.BindingOperation;
55 import org.netbeans.modules.xml.wsdl.model.Definitions;
56 import org.netbeans.modules.xml.wsdl.model.Fault;
57 import org.netbeans.modules.xml.wsdl.model.Operation;
58 import org.netbeans.modules.xml.wsdl.model.Port;
59 import org.netbeans.modules.xml.wsdl.model.PortType;
60 import org.netbeans.modules.xml.wsdl.model.Service;
61 import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
62 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
63 import org.netbeans.modules.xml.wsdl.model.spi.ElementFactory;
64 import org.w3c.dom.Element JavaDoc;
65
66 /**
67  *
68  * @author Roderico Cruz
69  */

70 public class JAXWSElementFactoryProvider {
71     
72     private Collection JavaDoc<ElementFactory> factories;
73     /** Creates a new instance of JAXWSElementFactoryProvider */
74     public JAXWSElementFactoryProvider() {
75     }
76     
77     public Set JavaDoc<QName JavaDoc> getElementQNames() {
78         return JAXWSQName.getQNames();
79     }
80     
81     public Collection JavaDoc<ElementFactory> getElementFactories() {
82         if(factories == null){
83             factories = new ArrayList JavaDoc<ElementFactory>();
84             factories.add(new BindingsFactory());
85             factories.add(new EnableAsyncMappingFactory());
86             factories.add(new EnableWrapperStyleFactory());
87             factories.add(new JavaClassFactory());
88             factories.add(new JavaDocFactory());
89             factories.add(new EnableMIMEContentFactory());
90             factories.add(new JavaExceptionFactory());
91             factories.add(new JavaMethodFactory());
92             factories.add(new JavaPackageFactory());
93             factories.add(new JavaParameterFactory());
94             factories.add(new ProviderFactory());
95         }
96         return factories;
97     }
98     
99     public static class BindingsFactory extends ElementFactory {
100         public Set JavaDoc<QName JavaDoc> getElementQNames() {
101             return Collections.singleton(JAXWSQName.BINDINGS.getQName());
102         }
103         public <C extends WSDLComponent> C create(WSDLComponent context, Class JavaDoc<C> type) {
104             WSDLModel model = context.getModel();
105             if(context instanceof Definitions){
106                 checkType(DefinitionsCustomization.class, type);
107                 return type.cast(new DefinitionsCustomizationImpl(model));
108             } else if(context instanceof PortType){
109                 checkType(PortTypeCustomization.class, type);
110                 return type.cast(new PortTypeCustomizationImpl(model));
111             } else if(context instanceof Operation){
112                 checkType(PortTypeOperationCustomization.class, type);
113                 return type.cast(new PortTypeOperationCustomizationImpl(model));
114             } else if (context instanceof BindingOperation){
115                 checkType(BindingOperationCustomization.class, type);
116                 return type.cast(new BindingOperationCustomizationImpl(model));
117             } else if (context instanceof Fault){
118                 checkType(PortTypeOperationFaultCustomization.class, type);
119                 return type.cast(new PortTypeOperationFaultCustomizationImpl(model));
120             } else if(context instanceof Binding){
121                 checkType(BindingCustomization.class, type);
122                 return type.cast(new BindingCustomizationImpl(model));
123             } else if (context instanceof Service){
124                 checkType(ServiceCustomization.class, type);
125                 return type.cast(new ServiceCustomizationImpl(model));
126             } else if (context instanceof Port){
127                 checkType(PortCustomization.class, type);
128                 return type.cast(new PortCustomizationImpl(model));
129             }
130             return null;
131         }
132         
133         public WSDLComponent create(WSDLComponent context, Element JavaDoc element) {
134             WSDLModel model = context.getModel();
135             if(context instanceof Definitions){
136                 return new DefinitionsCustomizationImpl(model, element);
137             } else if(context instanceof PortType){
138                 return new PortTypeCustomizationImpl(model, element);
139             } else if(context instanceof Operation){
140                 return new PortTypeOperationCustomizationImpl(model, element);
141             } else if (context instanceof BindingOperation){
142                 return new BindingOperationCustomizationImpl(model, element);
143             } else if (context instanceof Fault){
144                 return new PortTypeOperationFaultCustomizationImpl(model, element);
145             } else if(context instanceof Binding){
146                 return new BindingCustomizationImpl(model, element);
147             } else if (context instanceof Service){
148                 return new ServiceCustomizationImpl(model, element);
149             } else if (context instanceof Port){
150                 return new PortCustomizationImpl(model, element);
151             }
152             return null;
153         }
154     }
155     
156     public static class JavaExceptionFactory extends ElementFactory {
157         public Set JavaDoc<QName JavaDoc> getElementQNames() {
158             return Collections.singleton(JAXWSQName.JAVAEXCEPTION.getQName());
159         }
160         public <C extends WSDLComponent> C create(WSDLComponent context, Class JavaDoc<C> type) {
161             checkType(JavaException.class, type);
162             return type.cast(new JavaExceptionImpl(context.getModel()));
163             
164         }
165         public WSDLComponent create(WSDLComponent context, Element JavaDoc element) {
166             return new JavaExceptionImpl(context.getModel(), element);
167         }
168     }
169     public static class EnableAsyncMappingFactory extends ElementFactory {
170         public Set JavaDoc<QName JavaDoc> getElementQNames() {
171             return Collections.singleton(JAXWSQName.ENABLEASYNCMAPPING.getQName());
172         }
173         public <C extends WSDLComponent> C create(WSDLComponent context, Class JavaDoc<C> type) {
174             checkType(EnableAsyncMapping.class, type);
175             return type.cast(new EnableAsyncMappingImpl(context.getModel()));
176         }
177         public WSDLComponent create(WSDLComponent context, Element JavaDoc element) {
178             return new EnableAsyncMappingImpl(context.getModel(), element);
179         }
180     }
181     
182     public static class EnableWrapperStyleFactory extends ElementFactory {
183         public Set JavaDoc<QName JavaDoc> getElementQNames() {
184             return Collections.singleton(JAXWSQName.ENABLEWRAPPERSTYLE.getQName());
185         }
186         public <C extends WSDLComponent> C create(WSDLComponent context, Class JavaDoc<C> type) {
187             checkType(EnableWrapperStyle.class, type);
188             return type.cast(new EnableWrapperStyleImpl(context.getModel()));
189         }
190         public WSDLComponent create(WSDLComponent context, Element JavaDoc element) {
191             return new EnableWrapperStyleImpl(context.getModel(), element);
192         }
193     }
194     
195     public static class EnableMIMEContentFactory extends ElementFactory {
196         public Set JavaDoc<QName JavaDoc> getElementQNames() {
197             return Collections.singleton(JAXWSQName.ENABLEMIMECONTENT.getQName());
198         }
199         public <C extends WSDLComponent> C create(WSDLComponent context, Class JavaDoc<C> type) {
200             checkType(EnableMIMEContent.class, type);
201             return type.cast(new EnableMIMEContentImpl(context.getModel()));
202         }
203         public WSDLComponent create(WSDLComponent context, Element JavaDoc element) {
204             return new EnableMIMEContentImpl(context.getModel(), element);
205         }
206     }
207     
208     public static class JavaClassFactory extends ElementFactory {
209         public Set JavaDoc<QName JavaDoc> getElementQNames() {
210             return Collections.singleton(JAXWSQName.CLASS.getQName());
211         }
212         public <C extends WSDLComponent> C create(WSDLComponent context, Class JavaDoc<C> type) {
213             checkType(JavaClass.class, type);
214             return type.cast(new JavaClassImpl(context.getModel()));
215         }
216         public WSDLComponent create(WSDLComponent context, Element JavaDoc element) {
217             return new JavaClassImpl(context.getModel(), element);
218         }
219     }
220     
221     public static class JavaDocFactory extends ElementFactory {
222         public Set JavaDoc<QName JavaDoc> getElementQNames() {
223             return Collections.singleton(JAXWSQName.JAVADOC.getQName());
224         }
225         public <C extends WSDLComponent> C create(WSDLComponent context, Class JavaDoc<C> type) {
226             checkType(JavaDoc.class, type);
227             return type.cast(new JavaDocImpl(context.getModel()));
228         }
229         public WSDLComponent create(WSDLComponent context, Element JavaDoc element) {
230             return new JavaDocImpl(context.getModel(), element);
231         }
232     }
233     
234     public static class JavaMethodFactory extends ElementFactory {
235         public Set JavaDoc<QName JavaDoc> getElementQNames() {
236             return Collections.singleton(JAXWSQName.METHOD.getQName());
237         }
238         public <C extends WSDLComponent> C create(WSDLComponent context, Class JavaDoc<C> type) {
239             checkType(JavaMethod.class, type);
240             return type.cast(new JavaMethodImpl(context.getModel()));
241         }
242         public WSDLComponent create(WSDLComponent context, Element JavaDoc element) {
243             return new JavaMethodImpl(context.getModel(), element);
244         }
245     }
246     public static class JavaPackageFactory extends ElementFactory {
247         public Set JavaDoc<QName JavaDoc> getElementQNames() {
248             return Collections.singleton(JAXWSQName.PACKAGE.getQName());
249         }
250         public <C extends WSDLComponent> C create(WSDLComponent context, Class JavaDoc<C> type) {
251             checkType(JavaPackage.class, type);
252             return type.cast(new JavaPackageImpl(context.getModel()));
253         }
254         public WSDLComponent create(WSDLComponent context, Element JavaDoc element) {
255             return new JavaPackageImpl(context.getModel(), element);
256         }
257     }
258     
259     public static class JavaParameterFactory extends ElementFactory {
260         public Set JavaDoc<QName JavaDoc> getElementQNames() {
261             return Collections.singleton(JAXWSQName.PARAMETER.getQName());
262         }
263         public <C extends WSDLComponent> C create(WSDLComponent context, Class JavaDoc<C> type) {
264             checkType(JavaParameter.class, type);
265             return type.cast(new JavaParameterImpl(context.getModel()));
266         }
267         public WSDLComponent create(WSDLComponent context, Element JavaDoc element) {
268             return new JavaParameterImpl(context.getModel(), element);
269         }
270     }
271     
272     public static class ProviderFactory extends ElementFactory {
273         public Set JavaDoc<QName JavaDoc> getElementQNames() {
274             return Collections.singleton(JAXWSQName.PROVIDER.getQName());
275         }
276         public <C extends WSDLComponent> C create(WSDLComponent context, Class JavaDoc<C> type) {
277             checkType(Provider.class, type);
278             return type.cast(new ProviderImpl(context.getModel()));
279         }
280         public WSDLComponent create(WSDLComponent context, Element JavaDoc element) {
281             return new ProviderImpl(context.getModel(), element);
282         }
283     }
284     
285     @SuppressWarnings JavaDoc("unchecked")
286     public static void checkType(Class JavaDoc type1, Class JavaDoc type2) {
287         if (! type1.isAssignableFrom(type2)) {
288             throw new IllegalArgumentException JavaDoc("Invalid requested component type");
289         }
290     }
291 }
292
Popular Tags