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.axis2.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.geronimo.gbean.GBeanInfo;
028: import org.apache.geronimo.gbean.GBeanInfoBuilder;
029: import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
030: import org.apache.geronimo.jaxws.annotations.AnnotationHolder;
031: import org.apache.geronimo.kernel.Kernel;
032: import org.apache.geronimo.naming.enc.EnterpriseNamingContext;
033: import org.apache.geronimo.naming.reference.SimpleReference;
034: import org.apache.geronimo.transaction.GeronimoUserTransaction;
035: import org.apache.geronimo.webservices.WebServiceContainer;
036: import org.apache.geronimo.webservices.WebServiceContainerFactory;
037:
038: /**
039: * @version $Rev$ $Date$
040: */
041: public class POJOWebServiceContainerFactoryGBean implements
042: WebServiceContainerFactory {
043:
044: private static final Log LOG = LogFactory
045: .getLog(POJOWebServiceContainerFactoryGBean.class);
046:
047: private final ClassLoader classLoader;
048: private final org.apache.geronimo.jaxws.PortInfo portInfo;
049: private final String endpointClassName;
050: private URL configurationBaseUrl;
051: private Context context;
052: private AnnotationHolder holder;
053: private String contextRoot;
054:
055: public POJOWebServiceContainerFactoryGBean(
056: org.apache.geronimo.jaxws.PortInfo portInfo,
057: String endpointClassName, ClassLoader classLoader,
058: Map componentContext, Kernel kernel,
059: TransactionManager transactionManager,
060: URL configurationBaseUrl, AnnotationHolder holder,
061: String contextRoot) throws InstantiationException,
062: IllegalAccessException, ClassNotFoundException {
063:
064: if (componentContext != null) {
065:
066: // The name should match WebServiceContextAnnotationHelper.RELATIVE_JNDI_NAME
067: componentContext.put("env/WebServiceContext",
068: new WebServiceContextReference());
069:
070: GeronimoUserTransaction userTransaction = new GeronimoUserTransaction(
071: transactionManager);
072: try {
073: this .context = EnterpriseNamingContext
074: .createEnterpriseNamingContext(
075: componentContext, userTransaction,
076: kernel, classLoader);
077: } catch (NamingException e) {
078: LOG.warn("Failed to create naming context", e);
079: }
080: }
081:
082: this .portInfo = portInfo;
083: this .classLoader = classLoader;
084: this .endpointClassName = endpointClassName;
085: this .configurationBaseUrl = configurationBaseUrl;
086: this .holder = holder;
087: this .contextRoot = contextRoot;
088: }
089:
090: public WebServiceContainer getWebServiceContainer() {
091: POJOWebServiceContainer container = new POJOWebServiceContainer(
092: portInfo, endpointClassName, classLoader, context,
093: configurationBaseUrl, holder, contextRoot);
094: try {
095: container.init();
096: } catch (Exception e) {
097: throw new RuntimeException(
098: "Failure initializing web service containter", e);
099: }
100: return container;
101: }
102:
103: private static class WebServiceContextReference extends
104: SimpleReference {
105: public Object getContent() throws NamingException {
106: return new POJOWebServiceContext();
107: }
108: }
109:
110: public static final GBeanInfo GBEAN_INFO;
111:
112: static {
113: GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(
114: POJOWebServiceContainerFactoryGBean.class,
115: NameFactory.GERONIMO_SERVICE);
116: infoBuilder.addAttribute("portInfo",
117: org.apache.geronimo.jaxws.PortInfo.class, true, true);
118: infoBuilder.addAttribute("endpointClassName", String.class,
119: true, true);
120: infoBuilder.addAttribute("classLoader", ClassLoader.class,
121: false);
122: infoBuilder.addAttribute("componentContext", Map.class, true,
123: true);
124: infoBuilder.addAttribute("kernel", Kernel.class, false);
125: infoBuilder.addReference("TransactionManager",
126: TransactionManager.class, NameFactory.JTA_RESOURCE);
127: infoBuilder.addAttribute("configurationBaseUrl", URL.class,
128: true);
129: infoBuilder
130: .addAttribute("holder", AnnotationHolder.class, true);
131: infoBuilder.addAttribute("contextRoot", String.class, true,
132: true);
133:
134: infoBuilder.setConstructor(new String[] { "portInfo",
135: "endpointClassName", "classLoader", "componentContext",
136: "kernel", "TransactionManager", "configurationBaseUrl",
137: "holder", "contextRoot" });
138:
139: GBEAN_INFO = infoBuilder.getBeanInfo();
140: }
141:
142: public static GBeanInfo getGBeanInfo() {
143: return GBEAN_INFO;
144: }
145: }
|