01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.geronimo.jaxws.builder;
17:
18: import java.util.HashMap;
19: import java.util.Map;
20:
21: import org.apache.commons.logging.Log;
22: import org.apache.commons.logging.LogFactory;
23: import org.apache.geronimo.common.DeploymentException;
24: import org.apache.geronimo.j2ee.deployment.Module;
25: import org.apache.geronimo.jaxws.JAXWSUtils;
26: import org.apache.geronimo.jaxws.PortInfo;
27: import org.apache.geronimo.openejb.deployment.EjbModule;
28: import org.apache.openejb.assembler.classic.EnterpriseBeanInfo;
29:
30: public class EJBWebServiceFinder implements WebServiceFinder {
31:
32: private static final Log LOG = LogFactory
33: .getLog(EJBWebServiceFinder.class);
34:
35: public Map<String, PortInfo> discoverWebServices(Module module,
36: boolean isEJB, Map correctedPortLocations)
37: throws DeploymentException {
38: Map<String, PortInfo> map = new HashMap<String, PortInfo>();
39: discoverEJBWebServices(module, correctedPortLocations, map);
40: return map;
41: }
42:
43: private void discoverEJBWebServices(Module module,
44: Map correctedPortLocations, Map<String, PortInfo> map)
45: throws DeploymentException {
46: ClassLoader classLoader = module.getEarContext()
47: .getClassLoader();
48: EjbModule ejbModule = (EjbModule) module;
49: for (EnterpriseBeanInfo bean : ejbModule.getEjbJarInfo().enterpriseBeans) {
50: if (bean.type != EnterpriseBeanInfo.STATELESS) {
51: continue;
52: }
53: try {
54: Class ejbClass = classLoader.loadClass(bean.ejbClass);
55: if (JAXWSUtils.isWebService(ejbClass)) {
56: LOG.debug("Found EJB Web Service: " + bean.ejbName);
57: PortInfo portInfo = new PortInfo();
58: String location = (String) correctedPortLocations
59: .get(bean.ejbName);
60: if (location == null) {
61: // set default location, i.e. /@WebService.serviceName/@WebService.name
62: location = "/"
63: + JAXWSUtils.getServiceName(ejbClass)
64: + "/" + JAXWSUtils.getName(ejbClass);
65: }
66: portInfo.setLocation(location);
67: map.put(bean.ejbName, portInfo);
68: }
69: } catch (Exception e) {
70: throw new DeploymentException(
71: "Failed to load ejb class " + bean.ejbName, e);
72: }
73: }
74: }
75: }
|