KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > service > ServiceRemoteProxyFactory


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * 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 JavaDoc;
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 /**
36  * @author <a HREF="mailto:kabir.khan@jboss.org">Kabir Khan</a>
37  * @version $Revision: 56516 $
38  */

39 public class ServiceRemoteProxyFactory extends BaseServiceProxyFactory implements RemoteProxyFactory
40 {
41    private RemoteBinding binding;
42    private InvokerLocator locator;
43
44    public void setRemoteBinding(RemoteBinding binding)
45    {
46       this.binding = binding;
47    }
48
49    protected Class JavaDoc[] getInterfaces()
50    {
51       Class JavaDoc[] remoteInterfaces = ProxyFactoryHelper.getRemoteInterfaces(container);
52       Class JavaDoc[] interfaces = new Class JavaDoc[remoteInterfaces.length + 1];
53       System.arraycopy(remoteInterfaces, 0, interfaces, 0, remoteInterfaces.length);
54       interfaces[remoteInterfaces.length] = JBossProxy.class;
55       return interfaces;
56    }
57
58    protected void initializeJndiName()
59    {
60       jndiName = ProxyFactoryHelper.getRemoteJndiName(container, binding);
61    }
62
63    public void start() throws Exception JavaDoc
64    {
65       String JavaDoc clientBindUrl = ProxyFactoryHelper.getClientBindUrl(binding);
66       locator = new InvokerLocator(clientBindUrl);
67       super.start();
68    }
69
70    public Object JavaDoc createProxy()
71    {
72       try
73       {
74          Object JavaDoc containerId = container.getObjectName().getCanonicalName();
75          String JavaDoc stackName = "ServiceClientInterceptors";
76          if (binding.interceptorStack() != null && !binding.interceptorStack().equals(""))
77          {
78             stackName = binding.interceptorStack();
79          }
80          AdviceStack stack = AspectManager.instance().getAdviceStack(stackName);
81          Object JavaDoc[] args = {new ServiceRemoteProxy(containerId, stack.createInterceptors((Advisor) container, null), locator)};
82          return proxyConstructor.newInstance(args);
83       }
84       catch (InstantiationException JavaDoc e)
85       {
86          throw new RuntimeException JavaDoc(e); //To change body of catch statement use Options | File Templates.
87
}
88       catch (IllegalAccessException JavaDoc e)
89       {
90          throw new RuntimeException JavaDoc(e); //To change body of catch statement use Options | File Templates.
91
}
92       catch (IllegalArgumentException JavaDoc e)
93       {
94          throw new RuntimeException JavaDoc(e); //To change body of catch statement use Options | File Templates.
95
}
96       catch (InvocationTargetException JavaDoc e)
97       {
98          throw new RuntimeException JavaDoc(e.getTargetException()); //To change body of catch statement use Options | File Templates.
99
}
100    }
101
102 }
103
Popular Tags