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 */
017
018 package org.apache.geronimo.jaxws.builder;
019
020 import java.util.HashMap;
021 import java.util.Map;
022
023 import org.apache.commons.logging.Log;
024 import org.apache.commons.logging.LogFactory;
025 import org.apache.geronimo.common.DeploymentException;
026 import org.apache.geronimo.j2ee.deployment.Module;
027 import org.apache.geronimo.jaxws.JAXWSUtils;
028 import org.apache.geronimo.jaxws.PortInfo;
029 import org.apache.geronimo.openejb.deployment.EjbModule;
030 import org.apache.openejb.assembler.classic.EnterpriseBeanInfo;
031
032 public class EJBWebServiceFinder implements WebServiceFinder {
033
034 private static final Log LOG = LogFactory.getLog(EJBWebServiceFinder.class);
035
036 public Map<String, PortInfo> discoverWebServices(Module module,
037 boolean isEJB,
038 Map correctedPortLocations)
039 throws DeploymentException {
040 Map<String, PortInfo> map = new HashMap<String, PortInfo>();
041 discoverEJBWebServices(module, correctedPortLocations, map);
042 return map;
043 }
044
045 private void discoverEJBWebServices(Module module,
046 Map correctedPortLocations,
047 Map<String, PortInfo> map)
048 throws DeploymentException {
049 ClassLoader classLoader = module.getEarContext().getClassLoader();
050 EjbModule ejbModule = (EjbModule) module;
051 for (EnterpriseBeanInfo bean : ejbModule.getEjbJarInfo().enterpriseBeans) {
052 if (bean.type != EnterpriseBeanInfo.STATELESS) {
053 continue;
054 }
055 try {
056 Class ejbClass = classLoader.loadClass(bean.ejbClass);
057 if (JAXWSUtils.isWebService(ejbClass)) {
058 LOG.debug("Found EJB Web Service: " + bean.ejbName);
059 PortInfo portInfo = new PortInfo();
060 String location = (String) correctedPortLocations.get(bean.ejbName);
061 if (location == null) {
062 // set default location, i.e. /@WebService.serviceName/@WebService.name
063 location = "/" + JAXWSUtils.getServiceName(ejbClass) + "/" + JAXWSUtils.getName(ejbClass);
064 }
065 portInfo.setLocation(location);
066 map.put(bean.ejbName, portInfo);
067 }
068 } catch (Exception e) {
069 throw new DeploymentException("Failed to load ejb class "
070 + bean.ejbName, e);
071 }
072 }
073 }
074 }