001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.system;
023:
024: import java.util.Properties;
025: import org.omg.CORBA.Any;
026: import org.omg.CORBA.Context;
027: import org.omg.CORBA.ContextList;
028: import org.omg.CORBA.Current;
029: import org.omg.CORBA.Environment;
030: import org.omg.CORBA.ExceptionList;
031: import org.omg.CORBA.INITIALIZE;
032: import org.omg.CORBA.NamedValue;
033: import org.omg.CORBA.NO_IMPLEMENT;
034: import org.omg.CORBA.NVList;
035: import org.omg.CORBA.ORBPackage.InvalidName;
036: import org.omg.CORBA.Request;
037: import org.omg.CORBA.StructMember;
038: import org.omg.CORBA.TCKind;
039: import org.omg.CORBA.TypeCode;
040: import org.omg.CORBA.UnionMember;
041: import org.omg.CORBA.ValueMember;
042: import org.omg.CORBA_2_3.ORB;
043:
044: /**
045: * Thin wrapper class that fulfills the contract of an ORB singleton and
046: * forwards every invocation to an instance of the actual ORB singleton class,
047: * which it loads with the context classloader. The name of the actual ORB
048: * singleton class is specified by the system property
049: * <code>org.jboss.ORBSingletonDelegate</code>.
050: * <p>
051: * This class is a workaround to the the following problem: unlike the Sun VMs,
052: * IBM VMs do not use the context classloader to load the ORB singleton class
053: * specified by the system property
054: * <code>org.omg.CORBA.ORBSingletonClass</code>. IBM VMs use the
055: * system classloader, thus requiring the ORB singleton class to be in
056: * the system classpath. Rather than adding a third-party jar file (e.g.
057: * jacorb.jar) to the system classpath, we include this class in run.jar.
058: * Instead of setting the system property
059: * <pre>
060: * org.omg.CORBA.ORBSingletonClass=some.orb.impl.ORBSingletonImpl
061: * </pre>
062: * we set two properties:
063: * <pre>
064: * org.omg.CORBA.ORBSingletonClass=org.jboss.system.ORBSingleton
065: * org.jboss.ORBSingletonDelegate=some.orb.impl.ORBSingletonImpl
066: * </pre>
067: * <p>
068: * This class should be removed when IBM fixes its VMs.
069: *
070: * @author <a href="mailto:reverbel@ime.usp.br">Francisco Reverbel</a>
071: * @version $Revision: 57205 $
072: */
073: public class ORBSingleton extends ORB {
074: /** System property key that specifies the actual ORB singleton class. */
075: public static String DELEGATE_CLASS_KEY = "org.jboss.ORBSingletonDelegate";
076:
077: /** The ORB singleton instance to which all invocations are forwarded. */
078: private static ORB delegate = null;
079:
080: /**
081: * The ORBSingleton constructor does what the IBM VM does not do: it uses
082: * the context classloader to load the actual ORB singleton class.
083: */
084: public ORBSingleton() {
085: if (delegate == null) {
086: String className = System.getProperty(DELEGATE_CLASS_KEY);
087: if (className == null)
088: className = "org.jacorb.orb.ORBSingleton";
089: try {
090: delegate = (ORB) Class.forName(className).newInstance();
091: } catch (ClassNotFoundException ex) {
092: } catch (Exception ex) {
093: throw new INITIALIZE(
094: "can't instantiate ORBSingleton implementation "
095: + className);
096: }
097:
098: ClassLoader cl = Thread.currentThread()
099: .getContextClassLoader();
100: if (cl == null)
101: cl = ClassLoader.getSystemClassLoader();
102: try {
103: delegate = (ORB) Class.forName(className, true, cl)
104: .newInstance();
105: } catch (Exception ex) {
106: throw new INITIALIZE(
107: "can't instantiate ORBSingleton implementation "
108: + className);
109: }
110: }
111: }
112:
113: // All the rest is pretty dumb code: it implements all the methods of the
114: // class org.omg.CORBA.ORB, either forwarding the invocation to the
115: // delegate (methods that may be called on the restricted singleton ORB
116: // instance) or throwing an exception (methods that may not be called on
117: // the restricted singleton ORB instance).
118:
119: public Any create_any() {
120: return delegate.create_any();
121: }
122:
123: public TypeCode create_alias_tc(String id, String name,
124: TypeCode original_type) {
125: return delegate.create_alias_tc(id, name, original_type);
126: }
127:
128: public TypeCode create_array_tc(int length, TypeCode element_type) {
129: return delegate.create_array_tc(length, element_type);
130: }
131:
132: public TypeCode create_enum_tc(String id, String name,
133: String[] members) {
134: return delegate.create_enum_tc(id, name, members);
135: }
136:
137: public TypeCode create_exception_tc(String id, String name,
138: StructMember[] members) {
139: return delegate.create_exception_tc(id, name, members);
140: }
141:
142: public TypeCode create_interface_tc(String id, String name) {
143: return delegate.create_interface_tc(id, name);
144: }
145:
146: public TypeCode create_fixed_tc(short digits, short scale) {
147: return delegate.create_fixed_tc(digits, scale);
148: }
149:
150: public TypeCode create_recursive_tc(String id) {
151: return delegate.create_recursive_tc(id);
152: }
153:
154: /**
155: * @deprecated Deprecated by CORBA 2.3.
156: */
157: public TypeCode create_recursive_sequence_tc(int bound, int offset) {
158: throw new NO_IMPLEMENT("deprecated by CORBA 2.3");
159: }
160:
161: public TypeCode create_sequence_tc(int bound, TypeCode element_type) {
162: return delegate.create_sequence_tc(bound, element_type);
163: }
164:
165: public TypeCode create_string_tc(int bound) {
166: return delegate.create_string_tc(bound);
167: }
168:
169: public TypeCode create_wstring_tc(int bound) {
170: return delegate.create_wstring_tc(bound);
171: }
172:
173: public TypeCode create_struct_tc(String id, String name,
174: StructMember[] members) {
175: return delegate.create_struct_tc(id, name, members);
176: }
177:
178: public TypeCode create_union_tc(String id, String name,
179: TypeCode discriminator_type, UnionMember[] members) {
180: return delegate.create_union_tc(id, name, discriminator_type,
181: members);
182: }
183:
184: public TypeCode get_primitive_tc(TCKind tcKind) {
185: return delegate.get_primitive_tc(tcKind);
186: }
187:
188: public TypeCode create_value_tc(String id, String name,
189: short type_modifier, TypeCode concrete_base,
190: ValueMember[] members) {
191: return delegate.create_value_tc(id, name, type_modifier,
192: concrete_base, members);
193: }
194:
195: public TypeCode create_value_box_tc(String id, String name,
196: TypeCode boxed_type) {
197: return delegate.create_value_box_tc(id, name, boxed_type);
198: }
199:
200: public TypeCode create_abstract_interface_tc(String id, String name) {
201: return delegate.create_abstract_interface_tc(id, name);
202: }
203:
204: public TypeCode create_native_tc(String id, String name) {
205: return delegate.create_native_tc(id, name);
206: }
207:
208: /* Methods not allowed on the singleton ORB: */
209:
210: public ExceptionList create_exception_list() {
211: throw new NO_IMPLEMENT(
212: "The Singleton ORB only permits factory methods");
213: }
214:
215: public NVList create_list(int count) {
216: throw new NO_IMPLEMENT(
217: "The Singleton ORB only permits factory methods");
218: }
219:
220: public NamedValue create_named_value(String name, Any value,
221: int flags) {
222: throw new NO_IMPLEMENT(
223: "The Singleton ORB only permits factory methods");
224: }
225:
226: public NVList create_operation_list(org.omg.CORBA.Object obj) {
227: throw new NO_IMPLEMENT(
228: "The Singleton ORB only permits factory methods");
229: }
230:
231: public org.omg.CORBA.Object string_to_object(String str) {
232: throw new NO_IMPLEMENT(
233: "The Singleton ORB only permits factory methods");
234: }
235:
236: public Environment create_environment() {
237: throw new NO_IMPLEMENT(
238: "The Singleton ORB only permits factory methods");
239: }
240:
241: public ContextList create_context_list() {
242: throw new NO_IMPLEMENT(
243: "The Singleton ORB only permits factory methods");
244: }
245:
246: public org.omg.CORBA.portable.OutputStream create_output_stream() {
247: throw new NO_IMPLEMENT(
248: "The Singleton ORB only permits factory methods");
249: }
250:
251: /**
252: * @deprecated Deprecated by CORBA 2.3.
253: */
254: public Current get_current() {
255: throw new NO_IMPLEMENT(
256: "The Singleton ORB only permits factory methods");
257: }
258:
259: public Context get_default_context() {
260: throw new NO_IMPLEMENT(
261: "The Singleton ORB only permits factory methods");
262: }
263:
264: public Request get_next_response() {
265: throw new NO_IMPLEMENT(
266: "The Singleton ORB only permits factory methods");
267: }
268:
269: public String[] list_initial_services() {
270: throw new NO_IMPLEMENT(
271: "The Singleton ORB only permits factory methods");
272: }
273:
274: public String object_to_string(org.omg.CORBA.Object obj) {
275: throw new NO_IMPLEMENT(
276: "The Singleton ORB only permits factory methods");
277: }
278:
279: public boolean poll_next_response() {
280: throw new NO_IMPLEMENT(
281: "The Singleton ORB only permits factory methods");
282: }
283:
284: public org.omg.CORBA.Object resolve_initial_references(
285: String identifier) throws InvalidName {
286: throw new NO_IMPLEMENT(
287: "The Singleton ORB only permits factory methods");
288: }
289:
290: public void send_multiple_requests_deferred(Request[] req) {
291: throw new NO_IMPLEMENT(
292: "The Singleton ORB only permits factory methods");
293: }
294:
295: public void send_multiple_requests_oneway(Request[] req) {
296: throw new NO_IMPLEMENT(
297: "The Singleton ORB only permits factory methods");
298: }
299:
300: protected void set_parameters(String[] args, Properties props) {
301: throw new NO_IMPLEMENT(
302: "The Singleton ORB only permits factory methods");
303: }
304:
305: protected void set_parameters(java.applet.Applet app,
306: Properties props) {
307: throw new NO_IMPLEMENT(
308: "The Singleton ORB only permits factory methods");
309: }
310:
311: public void run() {
312: throw new NO_IMPLEMENT(
313: "The Singleton ORB only permits factory methods");
314: }
315:
316: public void shutdown(boolean wait_for_completion) {
317: throw new NO_IMPLEMENT(
318: "The Singleton ORB only permits factory methods");
319: }
320:
321: public boolean work_pending() {
322: throw new NO_IMPLEMENT(
323: "The Singleton ORB only permits factory methods");
324: }
325:
326: public void perform_work() {
327: throw new NO_IMPLEMENT(
328: "The Singleton ORB only permits factory methods");
329: }
330: }
|