KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > bridge > RemoteContext


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10
11 package org.mmbase.bridge;
12
13 import java.rmi.*;
14 import java.lang.reflect.*;
15 import java.net.MalformedURLException JavaDoc;
16
17 // import org.mmbase.bridge.remote.RemoteCloudContext;
18

19 /**
20  * @javadoc
21  * @author Kees Jongenburger <keesj@framfab.nl>
22  * @version $Id: RemoteContext.java,v 1.7 2005/06/07 12:02:37 michiel Exp $
23  * @since MMBase-1.5
24  */

25 public class RemoteContext {
26
27     /**
28      * Connect to a remote cloudcontext. The name of the context
29      * depends on configurations found in mmbaseroot.xml (host) and
30      * rmmci.xml for port and context name
31      * @todo should throw a Bridge Exception (?)
32      * @param uri rmi uri like rmi://www.mmbase.org:1111/remotecontext
33      * @return the remote cloud context named remotecontext
34      * @throws RuntimeException if anything goes wrong
35      */

36     public static CloudContext getCloudContext(String JavaDoc uri) {
37         try {
38             
39             Object JavaDoc remoteCloudContext= Naming.lookup(uri);
40             try {
41                 Class JavaDoc clazz = Class.forName("org.mmbase.bridge.remote.implementation.RemoteCloudContext_Impl");
42                 Constructor constr = clazz.getConstructor(new Class JavaDoc [] { Class.forName("org.mmbase.bridge.remote.RemoteCloudContext") });
43                 return (CloudContext) constr.newInstance(new Object JavaDoc[] { remoteCloudContext } );
44                 //new RemoteCloudContext_Impl(remoteCloudContext);
45
} catch (ClassNotFoundException JavaDoc e) {
46                 return null;
47             } catch (NoSuchMethodException JavaDoc e) {
48                 return null;
49             }
50         } catch (MalformedURLException JavaDoc mue) {
51             String JavaDoc message = mue.getMessage();
52             if (message != null && message.indexOf("no protocol") > -1) {
53                 throw new RuntimeException JavaDoc("This exception maybe occured, because the servlet container is " +
54                                            "installed in a directory with spaces.\n" +
55                                            "The java.rmi.server.RMIClassLoader loads classes from network locations " +
56                                            "(one or more URLS) for marschalling and unmarschalling parameters and return values. " +
57                                            "The RMIClassLoader uses a codebase where to load the classes. The codebase is a string " +
58                                            "with URLs separated by spaces.\n" +
59                                            "Error message: " + mue.getMessage());
60             }
61             throw new BridgeException("While connecting to " + uri + ": " + mue.getMessage(), mue);
62         } catch (Exception JavaDoc e){
63             throw new BridgeException("While connecting to " + uri + ": " + e.getMessage(), e);
64         }
65     }
66     public static void main(String JavaDoc[] argv) {
67         getCloudContext(argv[0]);
68     }
69 }
70
Popular Tags