001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.cxf.pojo;
017:
018: import java.net.URL;
019: import java.util.Map;
020:
021: import javax.naming.Context;
022: import javax.naming.NamingException;
023: import javax.transaction.TransactionManager;
024:
025: import org.apache.commons.logging.Log;
026: import org.apache.commons.logging.LogFactory;
027: import org.apache.cxf.Bus;
028: import org.apache.cxf.jaxws.context.WebServiceContextImpl;
029: import org.apache.geronimo.cxf.CXFCatalogUtils;
030: import org.apache.geronimo.cxf.CXFWebServiceContainer;
031: import org.apache.geronimo.gbean.GBeanInfo;
032: import org.apache.geronimo.gbean.GBeanInfoBuilder;
033: import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
034: import org.apache.geronimo.jaxws.JNDIResolver;
035: import org.apache.geronimo.jaxws.PortInfo;
036: import org.apache.geronimo.jaxws.ServerJNDIResolver;
037: import org.apache.geronimo.jaxws.annotations.AnnotationHolder;
038: import org.apache.geronimo.kernel.Kernel;
039: import org.apache.geronimo.naming.enc.EnterpriseNamingContext;
040: import org.apache.geronimo.naming.reference.SimpleReference;
041: import org.apache.geronimo.transaction.GeronimoUserTransaction;
042: import org.apache.geronimo.webservices.WebServiceContainer;
043: import org.apache.geronimo.webservices.WebServiceContainerFactory;
044:
045: /**
046: * @version $Rev: 508298 $ $Date: 2007-02-15 22:25:05 -0500 (Thu, 15 Feb 2007) $
047: */
048: public class POJOWebServiceContainerFactoryGBean implements
049: WebServiceContainerFactory {
050:
051: private static final Log LOG = LogFactory
052: .getLog(POJOWebServiceContainerFactoryGBean.class);
053:
054: private final Bus bus;
055: private final Class servletClass;
056: private final URL configurationBaseUrl;
057:
058: public POJOWebServiceContainerFactoryGBean(PortInfo portInfo,
059: String endpointClassName, ClassLoader classLoader,
060: Map componentContext, Kernel kernel,
061: TransactionManager transactionManager,
062: URL configurationBaseUrl, AnnotationHolder holder,
063: String contextRoot) throws ClassNotFoundException,
064: IllegalAccessException, InstantiationException {
065:
066: Context context = null;
067:
068: if (componentContext != null) {
069:
070: // The name should match WebServiceContextAnnotationHelper.RELATIVE_JNDI_NAME
071: componentContext.put("env/WebServiceContext",
072: new WebServiceContextReference());
073:
074: GeronimoUserTransaction userTransaction = new GeronimoUserTransaction(
075: transactionManager);
076: try {
077: context = EnterpriseNamingContext
078: .createEnterpriseNamingContext(
079: componentContext, userTransaction,
080: kernel, classLoader);
081: } catch (NamingException e) {
082: LOG.warn("Failed to create naming context", e);
083: }
084: }
085:
086: this .bus = CXFWebServiceContainer.getBus();
087: this .configurationBaseUrl = configurationBaseUrl;
088:
089: this .servletClass = classLoader.loadClass(endpointClassName);
090:
091: this .bus.setExtension(new ServerJNDIResolver(context),
092: JNDIResolver.class);
093: this .bus.setExtension(portInfo, PortInfo.class);
094: this .bus.setExtension(context, Context.class);
095: this .bus.setExtension(holder, AnnotationHolder.class);
096:
097: CXFCatalogUtils
098: .loadOASISCatalog(this .bus, this .configurationBaseUrl,
099: "WEB-INF/jax-ws-catalog.xml");
100: }
101:
102: public WebServiceContainer getWebServiceContainer() {
103: return new POJOWebServiceContainer(bus, configurationBaseUrl,
104: servletClass);
105: }
106:
107: private static class WebServiceContextReference extends
108: SimpleReference {
109: public Object getContent() throws NamingException {
110: return new WebServiceContextImpl();
111: }
112: }
113:
114: public static final GBeanInfo GBEAN_INFO;
115:
116: static {
117: GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(
118: POJOWebServiceContainerFactoryGBean.class,
119: NameFactory.GERONIMO_SERVICE);
120: infoBuilder
121: .addAttribute("portInfo", PortInfo.class, true, true);
122: infoBuilder.addAttribute("endpointClassName", String.class,
123: true, true);
124: infoBuilder.addAttribute("classLoader", ClassLoader.class,
125: false);
126: infoBuilder.addAttribute("componentContext", Map.class, true,
127: true);
128: infoBuilder.addAttribute("kernel", Kernel.class, false);
129: infoBuilder.addReference("TransactionManager",
130: TransactionManager.class, NameFactory.JTA_RESOURCE);
131: infoBuilder.addAttribute("configurationBaseUrl", URL.class,
132: true);
133: infoBuilder
134: .addAttribute("holder", AnnotationHolder.class, true);
135: infoBuilder.addAttribute("contextRoot", String.class, true,
136: true);
137:
138: infoBuilder.setConstructor(new String[] { "portInfo",
139: "endpointClassName", "classLoader", "componentContext",
140: "kernel", "TransactionManager", "configurationBaseUrl",
141: "holder", "contextRoot" });
142:
143: GBEAN_INFO = infoBuilder.getBeanInfo();
144: }
145:
146: public static GBeanInfo getGBeanInfo() {
147: return GBEAN_INFO;
148: }
149: }
|