1 |
/* DelegateFactory.java -- |
/* DelegateFactory.java -- |
2 |
Copyright (C) 2002, 2004 Free Software Foundation, Inc. |
Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
38 |
|
|
39 |
package gnu.javax.rmi.CORBA; |
package gnu.javax.rmi.CORBA; |
40 |
|
|
41 |
import java.util.HashMap; |
import gnu.CORBA.ObjectCreator; |
42 |
|
|
43 |
|
|
44 |
|
/** |
45 |
|
* This class produces delegates, using the system properties. If not |
46 |
|
* corresponding property is specified, returns default implementations. |
47 |
|
* |
48 |
|
* @author Wu Gansha (gansha.wu@intel.com) |
49 |
|
* @author Audrius Meskauskas (AudriusA@Bioinformatics.org) |
50 |
|
*/ |
51 |
public class DelegateFactory |
public class DelegateFactory |
52 |
{ |
{ |
53 |
private static HashMap cache = new HashMap(4); |
/** |
54 |
|
* The name to get a stub delegate. |
55 |
public static synchronized Object getInstance(String type) |
*/ |
56 |
throws GetDelegateInstanceException |
public static final String STUB = "Stub"; |
57 |
|
|
58 |
|
/** |
59 |
|
* The name to get the util delegate. |
60 |
|
*/ |
61 |
|
public static final String UTIL = "Util"; |
62 |
|
|
63 |
|
/** |
64 |
|
* The name to get the ValueHandler delegate. |
65 |
|
*/ |
66 |
|
public static final String VALUEHANDLER = "ValueHandler"; |
67 |
|
|
68 |
|
/** |
69 |
|
* The name to get the PortableRemoteObject delegate. |
70 |
|
*/ |
71 |
|
public static final String PORTABLE_REMOTE_OBJECT = "PortableRemoteObject"; |
72 |
|
|
73 |
|
/** |
74 |
|
* Get an instance of the given delegate. As in all cases the singleton |
75 |
|
* instance is used, the caching here would be redundant. |
76 |
|
* |
77 |
|
* @param type a delegate type. |
78 |
|
* |
79 |
|
* @return the associated delegate. |
80 |
|
* |
81 |
|
* @throws InternalError if the delegate class, indicated in the system |
82 |
|
* properties, cannot be instantiated. |
83 |
|
*/ |
84 |
|
public static Object getInstance(String type) |
85 |
|
throws InternalError |
86 |
{ |
{ |
87 |
Object r = cache.get(type); |
String propertyName = "javax.rmi.CORBA." + type + "Class"; |
88 |
if (r != null) |
String dcname = System.getProperty(propertyName); |
|
return r; |
|
|
String dcname = System.getProperty("javax.rmi.CORBA." + type + "Class"); |
|
89 |
if (dcname == null) |
if (dcname == null) |
90 |
{ |
{ |
91 |
//throw new DelegateException |
// // No javax.rmi.CORBA.XXXClass property sepcified. |
92 |
// ("no javax.rmi.CORBA.XXXClass property sepcified."); |
dcname = "gnu.javax.rmi.CORBA." + type + "DelegateImpl"; |
|
dcname = "gnu.javax.rmi.CORBA." + type + "DelegateImpl"; |
|
93 |
} |
} |
94 |
try |
try |
95 |
{ |
{ |
96 |
Class dclass = Class.forName(dcname, |
Class dclass = ObjectCreator.forName(dcname); |
97 |
true, |
return dclass.newInstance(); |
|
Thread.currentThread().getContextClassLoader()); |
|
|
r = dclass.newInstance(); |
|
|
cache.put(type, r); |
|
|
return r; |
|
98 |
} |
} |
99 |
catch(Exception e) |
catch (Exception e) |
100 |
{ |
{ |
101 |
throw new GetDelegateInstanceException |
InternalError ierr = new InternalError("Exception when trying to get " |
102 |
("Exception when trying to get delegate instance:" + dcname, e); |
+ type + "delegate instance:" + dcname); |
103 |
|
ierr.initCause(e); |
104 |
|
throw ierr; |
105 |
} |
} |
106 |
} |
} |
107 |
} |
} |