01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jboss.injection;
23:
24: // $Id: WebServiceRefInjector.java 61864 2007-03-29 20:01:13Z thomas.diesler@jboss.com $
25:
26: import java.lang.reflect.AnnotatedElement;
27: import java.net.URL;
28:
29: import javax.naming.Context;
30: import javax.xml.ws.WebServiceException;
31:
32: import org.jboss.ejb3.DeploymentUnit;
33: import org.jboss.ejb3.EJBContainer;
34: import org.jboss.logging.Logger;
35: import org.jboss.metadata.serviceref.ServiceRefDelegate;
36: import org.jboss.ws.integration.ServiceRefMetaData;
37: import org.jboss.ws.integration.URLLoaderAdapter;
38:
39: /**
40: * Inject a jaxws web service ref.
41: *
42: * @author Thomas.Diesler@jboss.com
43: * @version $Revision: 61864 $
44: */
45: public class WebServiceRefInjector implements EncInjector {
46: private static final Logger log = Logger
47: .getLogger(WebServiceRefInjector.class);
48:
49: private String name;
50: private ServiceRefMetaData sref;
51:
52: public WebServiceRefInjector(String name,
53: AnnotatedElement anElement, ServiceRefMetaData sref) {
54: this .name = name;
55: this .sref = sref;
56: this .sref.setAnnotatedElement(anElement);
57: }
58:
59: public void inject(InjectionContainer container) {
60: try {
61: Context encCtx = container.getEnc();
62: EJBContainer ejbContainer = (EJBContainer) container;
63: DeploymentUnit unit = ejbContainer.getDeploymentUnit();
64: URL rootURL = unit.getUrl();
65:
66: ClassLoader loader = unit.getClassLoader();
67: URLLoaderAdapter vfsRoot = new URLLoaderAdapter(rootURL);
68: new ServiceRefDelegate().bindServiceRef(encCtx, name,
69: vfsRoot, loader, sref);
70:
71: log.debug("@WebServiceRef bound [env=" + name + "]");
72: } catch (Exception e) {
73: throw new WebServiceException(
74: "Unable to bind @WebServiceRef [enc=" + name + "]",
75: e);
76: }
77: }
78:
79: public String toString() {
80: return super .toString() + "{enc=" + name + "}";
81: }
82: }
|