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.ejb3.service;
23:
24: import java.lang.reflect.InvocationTargetException;
25: import org.jboss.annotation.ejb.RemoteBinding;
26: import org.jboss.aop.Advisor;
27: import org.jboss.aop.AspectManager;
28: import org.jboss.aop.advice.AdviceStack;
29: import org.jboss.ejb3.JBossProxy;
30: import org.jboss.ejb3.ProxyFactoryHelper;
31: import org.jboss.ejb3.remoting.RemoteProxyFactory;
32: import org.jboss.remoting.InvokerLocator;
33:
34: /**
35: * @author <a href="mailto:kabir.khan@jboss.org">Kabir Khan</a>
36: * @version $Revision: 57207 $
37: */
38: public class ServiceRemoteProxyFactory extends BaseServiceProxyFactory
39: implements RemoteProxyFactory {
40: private RemoteBinding binding;
41: private InvokerLocator locator;
42:
43: public void setRemoteBinding(RemoteBinding binding) {
44: this .binding = binding;
45: }
46:
47: protected Class[] getInterfaces() {
48: Class[] remoteInterfaces = ProxyFactoryHelper
49: .getRemoteInterfaces(container);
50: Class[] interfaces = new Class[remoteInterfaces.length + 1];
51: System.arraycopy(remoteInterfaces, 0, interfaces, 0,
52: remoteInterfaces.length);
53: interfaces[remoteInterfaces.length] = JBossProxy.class;
54: return interfaces;
55: }
56:
57: protected void initializeJndiName() {
58: jndiName = ProxyFactoryHelper.getRemoteJndiName(container,
59: binding);
60: }
61:
62: public void start() throws Exception {
63: String clientBindUrl = ProxyFactoryHelper
64: .getClientBindUrl(binding);
65: locator = new InvokerLocator(clientBindUrl);
66: super .start();
67: }
68:
69: public Object createProxy() {
70: try {
71: Object containerId = container.getObjectName()
72: .getCanonicalName();
73: String stackName = "ServiceClientInterceptors";
74: if (binding.interceptorStack() != null
75: && !binding.interceptorStack().equals("")) {
76: stackName = binding.interceptorStack();
77: }
78: AdviceStack stack = AspectManager.instance()
79: .getAdviceStack(stackName);
80: Object[] args = { new ServiceRemoteProxy(containerId, stack
81: .createInterceptors((Advisor) container, null),
82: locator) };
83: return proxyConstructor.newInstance(args);
84: } catch (InstantiationException e) {
85: throw new RuntimeException(e); //To change body of catch statement use Options | File Templates.
86: } catch (IllegalAccessException e) {
87: throw new RuntimeException(e); //To change body of catch statement use Options | File Templates.
88: } catch (IllegalArgumentException e) {
89: throw new RuntimeException(e); //To change body of catch statement use Options | File Templates.
90: } catch (InvocationTargetException e) {
91: throw new RuntimeException(e.getTargetException()); //To change body of catch statement use Options | File Templates.
92: }
93: }
94:
95: }
|