1 19 27 28 package org.netbeans.modules.websvc.customization.model.impl; 29 30 import java.util.ArrayList ; 31 import java.util.Collection ; 32 import java.util.Collections ; 33 import java.util.Set ; 34 import javax.xml.namespace.QName ; 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 ; 65 66 70 public class JAXWSElementFactoryProvider { 71 72 private Collection <ElementFactory> factories; 73 74 public JAXWSElementFactoryProvider() { 75 } 76 77 public Set <QName > getElementQNames() { 78 return JAXWSQName.getQNames(); 79 } 80 81 public Collection <ElementFactory> getElementFactories() { 82 if(factories == null){ 83 factories = new ArrayList <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 <QName > getElementQNames() { 101 return Collections.singleton(JAXWSQName.BINDINGS.getQName()); 102 } 103 public <C extends WSDLComponent> C create(WSDLComponent context, Class <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 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 <QName > getElementQNames() { 158 return Collections.singleton(JAXWSQName.JAVAEXCEPTION.getQName()); 159 } 160 public <C extends WSDLComponent> C create(WSDLComponent context, Class <C> type) { 161 checkType(JavaException.class, type); 162 return type.cast(new JavaExceptionImpl(context.getModel())); 163 164 } 165 public WSDLComponent create(WSDLComponent context, Element element) { 166 return new JavaExceptionImpl(context.getModel(), element); 167 } 168 } 169 public static class EnableAsyncMappingFactory extends ElementFactory { 170 public Set <QName > getElementQNames() { 171 return Collections.singleton(JAXWSQName.ENABLEASYNCMAPPING.getQName()); 172 } 173 public <C extends WSDLComponent> C create(WSDLComponent context, Class <C> type) { 174 checkType(EnableAsyncMapping.class, type); 175 return type.cast(new EnableAsyncMappingImpl(context.getModel())); 176 } 177 public WSDLComponent create(WSDLComponent context, Element element) { 178 return new EnableAsyncMappingImpl(context.getModel(), element); 179 } 180 } 181 182 public static class EnableWrapperStyleFactory extends ElementFactory { 183 public Set <QName > getElementQNames() { 184 return Collections.singleton(JAXWSQName.ENABLEWRAPPERSTYLE.getQName()); 185 } 186 public <C extends WSDLComponent> C create(WSDLComponent context, Class <C> type) { 187 checkType(EnableWrapperStyle.class, type); 188 return type.cast(new EnableWrapperStyleImpl(context.getModel())); 189 } 190 public WSDLComponent create(WSDLComponent context, Element element) { 191 return new EnableWrapperStyleImpl(context.getModel(), element); 192 } 193 } 194 195 public static class EnableMIMEContentFactory extends ElementFactory { 196 public Set <QName > getElementQNames() { 197 return Collections.singleton(JAXWSQName.ENABLEMIMECONTENT.getQName()); 198 } 199 public <C extends WSDLComponent> C create(WSDLComponent context, Class <C> type) { 200 checkType(EnableMIMEContent.class, type); 201 return type.cast(new EnableMIMEContentImpl(context.getModel())); 202 } 203 public WSDLComponent create(WSDLComponent context, Element element) { 204 return new EnableMIMEContentImpl(context.getModel(), element); 205 } 206 } 207 208 public static class JavaClassFactory extends ElementFactory { 209 public Set <QName > getElementQNames() { 210 return Collections.singleton(JAXWSQName.CLASS.getQName()); 211 } 212 public <C extends WSDLComponent> C create(WSDLComponent context, Class <C> type) { 213 checkType(JavaClass.class, type); 214 return type.cast(new JavaClassImpl(context.getModel())); 215 } 216 public WSDLComponent create(WSDLComponent context, Element element) { 217 return new JavaClassImpl(context.getModel(), element); 218 } 219 } 220 221 public static class JavaDocFactory extends ElementFactory { 222 public Set <QName > getElementQNames() { 223 return Collections.singleton(JAXWSQName.JAVADOC.getQName()); 224 } 225 public <C extends WSDLComponent> C create(WSDLComponent context, Class <C> type) { 226 checkType(JavaDoc.class, type); 227 return type.cast(new JavaDocImpl(context.getModel())); 228 } 229 public WSDLComponent create(WSDLComponent context, Element element) { 230 return new JavaDocImpl(context.getModel(), element); 231 } 232 } 233 234 public static class JavaMethodFactory extends ElementFactory { 235 public Set <QName > getElementQNames() { 236 return Collections.singleton(JAXWSQName.METHOD.getQName()); 237 } 238 public <C extends WSDLComponent> C create(WSDLComponent context, Class <C> type) { 239 checkType(JavaMethod.class, type); 240 return type.cast(new JavaMethodImpl(context.getModel())); 241 } 242 public WSDLComponent create(WSDLComponent context, Element element) { 243 return new JavaMethodImpl(context.getModel(), element); 244 } 245 } 246 public static class JavaPackageFactory extends ElementFactory { 247 public Set <QName > getElementQNames() { 248 return Collections.singleton(JAXWSQName.PACKAGE.getQName()); 249 } 250 public <C extends WSDLComponent> C create(WSDLComponent context, Class <C> type) { 251 checkType(JavaPackage.class, type); 252 return type.cast(new JavaPackageImpl(context.getModel())); 253 } 254 public WSDLComponent create(WSDLComponent context, Element element) { 255 return new JavaPackageImpl(context.getModel(), element); 256 } 257 } 258 259 public static class JavaParameterFactory extends ElementFactory { 260 public Set <QName > getElementQNames() { 261 return Collections.singleton(JAXWSQName.PARAMETER.getQName()); 262 } 263 public <C extends WSDLComponent> C create(WSDLComponent context, Class <C> type) { 264 checkType(JavaParameter.class, type); 265 return type.cast(new JavaParameterImpl(context.getModel())); 266 } 267 public WSDLComponent create(WSDLComponent context, Element element) { 268 return new JavaParameterImpl(context.getModel(), element); 269 } 270 } 271 272 public static class ProviderFactory extends ElementFactory { 273 public Set <QName > getElementQNames() { 274 return Collections.singleton(JAXWSQName.PROVIDER.getQName()); 275 } 276 public <C extends WSDLComponent> C create(WSDLComponent context, Class <C> type) { 277 checkType(Provider.class, type); 278 return type.cast(new ProviderImpl(context.getModel())); 279 } 280 public WSDLComponent create(WSDLComponent context, Element element) { 281 return new ProviderImpl(context.getModel(), element); 282 } 283 } 284 285 @SuppressWarnings ("unchecked") 286 public static void checkType(Class type1, Class type2) { 287 if (! type1.isAssignableFrom(type2)) { 288 throw new IllegalArgumentException ("Invalid requested component type"); 289 } 290 } 291 } 292 | Popular Tags |