Author: fnasser(a)redhat.com
Date: 2010-08-04 15:16:21 -0400 (Wed, 04 Aug 2010)
New Revision: 12734
Added:
thirdparty/cxf/branches/cxf-2.2.6/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/DefaultServiceBuilderFactory.java
thirdparty/cxf/branches/cxf-2.2.6/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/SpringServiceBuilderFactory.java
Log:
Make use of Spring optional in CXF's JAXWS tooling (Alessio Soldano) **FIX commit
mistake, missing new files**
Added:
thirdparty/cxf/branches/cxf-2.2.6/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/DefaultServiceBuilderFactory.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.2.6/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/DefaultServiceBuilderFactory.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.2.6/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/DefaultServiceBuilderFactory.java 2010-08-04
19:16:21 UTC (rev 12734)
@@ -0,0 +1,63 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.tools.java2wsdl.processor.internal;
+
+import org.apache.cxf.aegis.databinding.AegisDatabinding;
+import org.apache.cxf.databinding.DataBinding;
+import org.apache.cxf.frontend.AbstractServiceFactory;
+import org.apache.cxf.jaxb.JAXBDataBinding;
+import org.apache.cxf.jaxws.JaxwsServiceBuilder;
+import org.apache.cxf.service.ServiceBuilder;
+import org.apache.cxf.simple.SimpleServiceBuilder;
+import org.apache.cxf.tools.common.ToolConstants;
+import org.apache.cxf.tools.common.ToolException;
+import org.apache.cxf.tools.java2wsdl.processor.FrontendFactory;
+import org.apache.cxf.tools.java2wsdl.processor.FrontendFactory.Style;
+
+/**
+ * This class constructs ServiceBuilder objects. These objects are used to access the
services and the data
+ * bindings to generate the wsdl.
+ */
+public final class DefaultServiceBuilderFactory extends ServiceBuilderFactory {
+
+ @Override
+ public ServiceBuilder newBuilder(FrontendFactory.Style s) {
+ DataBinding dataBinding;
+ final String dbn = getDatabindingName();
+ if (ToolConstants.JAXB_DATABINDING.equals(dbn)) {
+ dataBinding = new JAXBDataBinding();
+ } else if (ToolConstants.AEGIS_DATABINDING.equals(dbn)) {
+ dataBinding = new AegisDatabinding();
+ } else {
+ throw new ToolException("Unsupported databinding: " + s);
+ }
+ AbstractServiceFactory builder = null;
+ if (Style.Jaxws.equals(s)) {
+ builder = new JaxwsServiceBuilder();
+ } else if (Style.Simple.equals(s)) {
+ builder = new SimpleServiceBuilder();
+ } else {
+ throw new ToolException("Unsupported frontend style: " + s);
+ }
+ builder.setDataBinding(dataBinding);
+ builder.setServiceClass(serviceClass);
+ return builder;
+ }
+}
Added:
thirdparty/cxf/branches/cxf-2.2.6/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/SpringServiceBuilderFactory.java
===================================================================
---
thirdparty/cxf/branches/cxf-2.2.6/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/SpringServiceBuilderFactory.java
(rev 0)
+++
thirdparty/cxf/branches/cxf-2.2.6/tools/javato/ws/src/main/java/org/apache/cxf/tools/java2wsdl/processor/internal/SpringServiceBuilderFactory.java 2010-08-04
19:16:21 UTC (rev 12734)
@@ -0,0 +1,136 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.tools.java2wsdl.processor.internal;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.bus.spring.BusApplicationContext;
+import org.apache.cxf.databinding.DataBinding;
+import org.apache.cxf.frontend.AbstractServiceFactory;
+import org.apache.cxf.service.ServiceBuilder;
+import org.apache.cxf.tools.common.ToolConstants;
+import org.apache.cxf.tools.common.ToolException;
+import org.apache.cxf.tools.java2wsdl.processor.FrontendFactory;
+import org.apache.cxf.tools.util.NameUtil;
+
+import org.springframework.beans.factory.BeanDefinitionStoreException;
+import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.GenericApplicationContext;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.FileSystemResource;
+
+/**
+ * This class constructs ServiceBuilder objects using Spring. These objects are used to
access the services
+ * and the data bindings to generate the wsdl.
+ */
+public final class SpringServiceBuilderFactory extends ServiceBuilderFactory {
+
+ private List<String> beanDefinitions;
+
+ public SpringServiceBuilderFactory(List<String> beanDefinitions) {
+ super();
+ this.beanDefinitions = beanDefinitions;
+ }
+
+ public SpringServiceBuilderFactory() {
+ super();
+ this.beanDefinitions = new ArrayList<String>(0);
+ }
+
+ /**
+ * Convert a parameter value to the name of a bean we'd use for a data binding.
+ *
+ * @param databindingName
+ * @return
+ */
+ public static String databindingNameToBeanName(String dbName) {
+ return NameUtil.capitalize(dbName.toLowerCase()) +
ToolConstants.DATABIND_BEAN_NAME_SUFFIX;
+ }
+
+ @Override
+ public ServiceBuilder newBuilder(FrontendFactory.Style s) {
+ ApplicationContext applicationContext = getApplicationContext(beanDefinitions);
+ DataBinding dataBinding;
+ String databindingBeanName = databindingNameToBeanName(databindingName);
+ try {
+ dataBinding = (DataBinding)applicationContext.getBean(databindingBeanName);
+ } catch (RuntimeException e) {
+ throw new ToolException("Cannot get databinding bean " +
databindingBeanName
+ + " for databinding " + databindingName);
+ }
+
+ String beanName = getBuilderBeanName(s);
+ ServiceBuilder builder = null;
+
+ try {
+ builder = (ServiceBuilder)applicationContext.getBean(beanName,
ServiceBuilder.class);
+ AbstractServiceFactory serviceFactory = (AbstractServiceFactory)builder;
+ serviceFactory.setDataBinding(dataBinding);
+ } catch (RuntimeException e) {
+ throw new ToolException("Can not get ServiceBuilder bean " +
beanName
+ + "to initialize the ServiceBuilder for style:
" + s + " Reason: \n"
+ + e.getMessage(), e);
+ }
+ builder.setServiceClass(serviceClass);
+ return builder;
+ }
+
+ /**
+ * Return the name of a prototype bean from Spring that can provide the service. The
use of a bean allows
+ * for the possibility of an override.
+ *
+ * @param s Style of service
+ * @return name of bean.
+ */
+ protected String getBuilderBeanName(FrontendFactory.Style s) {
+ return s + "ServiceBuilderBean";
+ }
+
+ /**
+ * This is factored out to permit use in a unit test.
+ *
+ * @param bus
+ * @return
+ */
+ public static ApplicationContext getApplicationContext(List<String>
additionalFilePathnames) {
+ BusApplicationContext busApplicationContext = BusFactory.getDefaultBus()
+ .getExtension(BusApplicationContext.class);
+ GenericApplicationContext appContext = new
GenericApplicationContext(busApplicationContext);
+ XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(appContext);
+ reader.loadBeanDefinitions(new
ClassPathResource("META-INF/cxf/java2wsbeans.xml"));
+ for (String pathname : additionalFilePathnames) {
+ try {
+ reader.loadBeanDefinitions(new FileSystemResource(pathname));
+ } catch (BeanDefinitionStoreException bdse) {
+ throw new ToolException("Unable to open bean definition file "
+ pathname, bdse.getCause());
+ }
+ }
+
+ return appContext;
+ }
+
+ public void setBeanDefinitions(List<String> beanDefinitions) {
+ this.beanDefinitions = beanDefinitions;
+ }
+
+}