01: /*
02:
03: This software is OSI Certified Open Source Software.
04: OSI Certified is a certification mark of the Open Source Initiative.
05:
06: The license (Mozilla version 1.0) can be read at the MMBase site.
07: See http://www.MMBase.org/license
08:
09: */
10:
11: package org.mmbase.bridge;
12:
13: import java.rmi.*;
14: import java.lang.reflect.*;
15: import java.net.MalformedURLException;
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.9 2007/02/10 15:47:42 nklasens Exp $
23: * @since MMBase-1.5
24: */
25: public abstract 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 uri) {
37: try {
38:
39: Object remoteCloudContext = Naming.lookup(uri);
40: try {
41: Class<?> clazz = Class
42: .forName("org.mmbase.bridge.remote.implementation.RemoteCloudContext_Impl");
43: Constructor<?> constr = clazz
44: .getConstructor(new Class[] { Class
45: .forName("org.mmbase.bridge.remote.RemoteCloudContext") });
46: return (CloudContext) constr
47: .newInstance(new Object[] { remoteCloudContext });
48: //new RemoteCloudContext_Impl(remoteCloudContext);
49: } catch (ClassNotFoundException e) {
50: return null;
51: } catch (NoSuchMethodException e) {
52: return null;
53: }
54: } catch (MalformedURLException mue) {
55: String message = mue.getMessage();
56: if (message != null && message.indexOf("no protocol") > -1) {
57: throw new RuntimeException(
58: "This exception maybe occured, because the servlet container is "
59: + "installed in a directory with spaces.\n"
60: + "The java.rmi.server.RMIClassLoader loads classes from network locations "
61: + "(one or more URLS) for marschalling and unmarschalling parameters and return values. "
62: + "The RMIClassLoader uses a codebase where to load the classes. The codebase is a string "
63: + "with URLs separated by spaces.\n"
64: + "Error message: " + mue.getMessage());
65: }
66: throw new BridgeException("While connecting to " + uri
67: + ": " + mue.getMessage(), mue);
68: } catch (Exception e) {
69: throw new BridgeException("While connecting to " + uri
70: + ": " + e.getMessage(), e);
71: }
72: }
73:
74: public static void main(String[] argv) {
75: getCloudContext(argv[0]);
76: }
77: }
|