1 /* RestrictedORB.java --
2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
41 import gnu.CORBA.CDR.cdrBufOutput;
43 import org.omg.CORBA.Any;
44 import org.omg.CORBA.BAD_PARAM;
45 import org.omg.CORBA.ContextList;
46 import org.omg.CORBA.Environment;
47 import org.omg.CORBA.ExceptionList;
48 import org.omg.CORBA.NO_IMPLEMENT;
49 import org.omg.CORBA.NVList;
50 import org.omg.CORBA.NamedValue;
51 import org.omg.CORBA.ORB;
52 import org.omg.CORBA.ORBPackage.InvalidName;
53 import org.omg.CORBA.Request;
54 import org.omg.CORBA.StructMember;
55 import org.omg.CORBA.TCKind;
56 import org.omg.CORBA.TypeCode;
57 import org.omg.CORBA.TypeCodePackage.BadKind;
58 import org.omg.CORBA.UnionMember;
59 import org.omg.CORBA.portable.OutputStream;
60 import org.omg.CORBA.portable.ValueFactory;
61 import org.omg.PortableInterceptor.ClientRequestInterceptorOperations;
62 import org.omg.PortableInterceptor.IORInterceptorOperations;
63 import org.omg.PortableInterceptor.ServerRequestInterceptorOperations;
65 import java.applet.Applet;
67 import java.util.Hashtable;
68 import java.util.Properties;
71 * This class implements so-called Singleton ORB, a highly restricted version
72 * that cannot communicate over network. This ORB is provided for the
73 * potentially malicious applets with heavy security restrictions. It, however,
74 * supports some basic features that might be needed even when the network
75 * access is not granted.
77 * This ORB can only create typecodes, {@link Any}, {@link ContextList},
78 * {@link NVList} and {@link org.omg.CORBA.portable.OutputStream} that writes to
81 * All other methods throw the {@link NO_IMPLEMENT} exception.
83 * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
85 public class Restricted_ORB extends org.omg.CORBA_2_3.ORB
88 * The singleton instance of this ORB.
90 public static final ORB Singleton = new Restricted_ORB();
93 * The cumulated listener for all IOR interceptors. Interceptors are used by
94 * {@link gnu.CORBA.Poa.ORB_1_4}.
96 public IORInterceptorOperations iIor;
99 * The cumulated listener for all server request interceptors. Interceptors
100 * are used by {@link gnu.CORBA.Poa.ORB_1_4}.
102 public ServerRequestInterceptorOperations iServer;
105 * The cumulated listener for all client request interceptros. Interceptors
106 * are used by {@link gnu.CORBA.Poa.ORB_1_4}.
108 public ClientRequestInterceptorOperations iClient;
111 * The required size of the interceptor slot array.
113 public int icSlotSize = 0;
116 * The value factories.
118 protected Hashtable factories = new Hashtable();
121 * The policy factories.
123 protected Hashtable policyFactories = new Hashtable();
126 * Create a new instance of the RestrictedORB. This is used in derived classes
129 protected Restricted_ORB()
134 public TypeCode create_alias_tc(String id, String name, TypeCode typecode)
136 return new aliasTypeCode(typecode, id, name);
140 public Any create_any()
142 gnuAny any = new gnuAny();
148 public TypeCode create_array_tc(int length, TypeCode element_type)
150 primitiveArrayTypeCode p =
151 new primitiveArrayTypeCode(TCKind.tk_array, element_type);
157 public ContextList create_context_list()
159 return new gnuContextList();
163 public TypeCode create_enum_tc(String id, String name, String[] values)
165 recordTypeCode r = new recordTypeCode(TCKind.tk_enum);
166 for (int i = 0; i < values.length; i++)
168 r.field().name = values [ i ];
178 public Environment create_environment()
180 return new gnuEnvironment();
184 public ExceptionList create_exception_list()
186 return new gnuExceptionList();
190 public TypeCode create_exception_tc(String id, String name,
191 StructMember[] members
194 recordTypeCode r = new recordTypeCode(TCKind.tk_except);
198 for (int i = 0; i < members.length; i++)
200 r.add(members [ i ]);
207 * This method is not allowed for a RestrictedORB.
209 * @throws NO_IMPLEMENT, always.
211 public TypeCode create_interface_tc(String id, String name)
218 public NVList create_list(int count)
220 return new gnuNVList(count);
224 public NamedValue create_named_value(String s, Any any, int flags)
226 return new gnuNamedValue();
230 public OutputStream create_output_stream()
232 cdrBufOutput stream = new cdrBufOutput();
238 public TypeCode create_sequence_tc(int bound, TypeCode element_type)
240 primitiveArrayTypeCode p =
241 new primitiveArrayTypeCode(TCKind.tk_sequence, element_type);
247 public TypeCode create_string_tc(int bound)
249 stringTypeCode p = new stringTypeCode(TCKind.tk_string);
255 public TypeCode create_struct_tc(String id, String name,
256 StructMember[] members
259 recordTypeCode r = new recordTypeCode(TCKind.tk_struct);
263 for (int i = 0; i < members.length; i++)
265 r.add(members [ i ]);
272 public TypeCode create_union_tc(String id, String name,
273 TypeCode discriminator_type, UnionMember[] members
276 recordTypeCode r = new recordTypeCode(TCKind.tk_union);
279 r.setDiscriminator_type(discriminator_type);
280 r.setDefaultIndex(0);
282 for (int i = 0; i < members.length; i++)
284 r.add(members [ i ]);
291 public TypeCode create_wstring_tc(int bound)
293 stringTypeCode p = new stringTypeCode(TCKind.tk_wstring);
299 public TypeCode get_primitive_tc(TCKind tcKind)
303 return typeNamer.getPrimitveTC(tcKind);
307 throw new BAD_PARAM("This is not a primitive type code: " +
314 * This method is not allowed for a RestrictedORB.
316 * @throws NO_IMPLEMENT, always.
318 public String[] list_initial_services()
321 throw new InternalError();
325 * This method is not allowed for a RestrictedORB.
327 * @throws NO_IMPLEMENT, always.
329 public String object_to_string(org.omg.CORBA.Object forObject)
332 throw new InternalError();
336 * This method is not allowed for a RestrictedORB.
338 * @throws InvalidName never in this class, but it is thrown in the derived
341 * @throws NO_IMPLEMENT, always.
343 public org.omg.CORBA.Object resolve_initial_references(String name)
347 throw new InternalError();
351 * Shutdown the ORB server.
353 * For RestrictedORB, returns witout action.
360 * Shutdown the ORB server.
362 * For RestrictedORB, returns witout action.
364 public void shutdown(boolean wait_for_completion)
369 * This method is not allowed for a RestrictedORB.
371 * @throws NO_IMPLEMENT, always.
373 public org.omg.CORBA.Object string_to_object(String IOR)
376 throw new InternalError();
380 * This method is not allowed for a RestrictedORB.
382 * @throws NO_IMPLEMENT, always.
384 protected void set_parameters(Applet app, Properties props)
390 * This method is not allowed for a RestrictedORB.
392 * @throws NO_IMPLEMENT, always.
394 protected void set_parameters(String[] args, Properties props)
400 * Throws an exception, stating that the given method is not supported by the
403 private final void no()
405 // Apart the programming errors, this can only happen if the
406 // malicious code is trying to do that it is not allowed.
407 throw new NO_IMPLEMENT("Use init(args, props) for the functional version.");
411 * This method is not allowed for a RestrictedORB.
413 * @throws NO_IMPLEMENT, always.
415 public Request get_next_response() throws org.omg.CORBA.WrongTransaction
418 throw new InternalError();
422 * This method is not allowed for a RestrictedORB.
424 * @throws NO_IMPLEMENT, always.
426 public boolean poll_next_response()
429 throw new InternalError();
433 * This method is not allowed for a RestrictedORB.
435 * @throws NO_IMPLEMENT, always.
437 public void send_multiple_requests_deferred(Request[] requests)
443 * This method is not allowed for a RestrictedORB.
445 * @throws NO_IMPLEMENT, always.
447 public void send_multiple_requests_oneway(Request[] requests)
453 * Register the value factory under the given repository id.
455 public ValueFactory register_value_factory(String repository_id,
459 factories.put(repository_id, factory);
464 * Unregister the value factroy.
466 public void unregister_value_factory(String id)
468 factories.remove(id);
472 * Look for the value factory for the value, having the given repository id.
473 * The implementation checks for the registered value factories first. If none
474 * found, it tries to load and instantiate the class, mathing the given naming
475 * convention. If this faild, null is returned.
477 * @param repository_id a repository id.
479 * @return a found value factory, null if none.
481 public ValueFactory lookup_value_factory(String repository_id)
483 ValueFactory f = (ValueFactory) factories.get(repository_id);
489 f = (ValueFactory) ObjectCreator.createObject(repository_id,
494 factories.put(repository_id, f);
500 * Destroy the interceptors, if they are present.
502 public void destroy()