KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > dynaop > remote > Home


1 package dynaop.remote;
2
3 import java.net.URL JavaDoc;
4
5 import dynaop.Aspects;
6 import dynaop.Pointcuts;
7 import dynaop.ProxyFactory;
8
9 /**
10  * Creates client stubs. Thread safe. Client interface methods should throw
11  * <code>java.rmi.RemoteException</code>.
12  *
13  * @author Bob Lee (crazybob@crazybob.org)
14  */

15 public class Home {
16
17     /**
18      * Creates stub that connects to {@link Service} mapped to specified
19      * URL and implements the specified client interface.
20      */

21     public Object JavaDoc create(URL JavaDoc url, Class JavaDoc intf) {
22         if (url == null)
23             throw new NullPointerException JavaDoc("URL is null");
24         
25         Aspects aspects = new Aspects();
26         aspects.interfaces(Pointcuts.ALL_CLASSES, new Class JavaDoc[] { intf });
27         aspects.interceptor(
28             Pointcuts.ALL_CLASSES,
29             Pointcuts.not(Pointcuts.OBJECT_METHODS),
30             new StubInterceptor()
31         );
32         
33         // the stub wraps the url.
34
Object JavaDoc stub = ProxyFactory.getInstance(aspects).wrap(url);
35         
36         return stub;
37     }
38 }
39
Popular Tags