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
.BufferedCdrOutput
;
42 import gnu
.CORBA
.typecodes
.AliasTypeCode
;
43 import gnu
.CORBA
.typecodes
.ArrayTypeCode
;
44 import gnu
.CORBA
.typecodes
.PrimitiveTypeCode
;
45 import gnu
.CORBA
.typecodes
.RecordTypeCode
;
46 import gnu
.CORBA
.typecodes
.StringTypeCode
;
48 import org
.omg
.CORBA
.Any
;
49 import org
.omg
.CORBA
.BAD_PARAM
;
50 import org
.omg
.CORBA
.Context
;
51 import org
.omg
.CORBA
.ContextList
;
52 import org
.omg
.CORBA
.Environment
;
53 import org
.omg
.CORBA
.ExceptionList
;
54 import org
.omg
.CORBA
.NO_IMPLEMENT
;
55 import org
.omg
.CORBA
.NVList
;
56 import org
.omg
.CORBA
.NamedValue
;
57 import org
.omg
.CORBA
.ORB
;
58 import org
.omg
.CORBA
.ORBPackage
.InvalidName
;
59 import org
.omg
.CORBA
.Request
;
60 import org
.omg
.CORBA
.StructMember
;
61 import org
.omg
.CORBA
.TCKind
;
62 import org
.omg
.CORBA
.TypeCode
;
63 import org
.omg
.CORBA
.TypeCodePackage
.BadKind
;
64 import org
.omg
.CORBA
.UnionMember
;
65 import org
.omg
.CORBA
.portable
.OutputStream
;
66 import org
.omg
.CORBA
.portable
.ValueFactory
;
67 import org
.omg
.PortableInterceptor
.ClientRequestInterceptorOperations
;
68 import org
.omg
.PortableInterceptor
.IORInterceptor_3_0Operations
;
69 import org
.omg
.PortableInterceptor
.ServerRequestInterceptorOperations
;
71 import java
.applet
.Applet
;
73 import java
.util
.Hashtable
;
74 import java
.util
.Properties
;
77 * This class implements so-called Singleton ORB, a highly restricted version
78 * that cannot communicate over network. This ORB is provided for the
79 * potentially malicious applets with heavy security restrictions. It, however,
80 * supports some basic features that might be needed even when the network
81 * access is not granted.
83 * This ORB can only create typecodes, {@link Any}, {@link ContextList},
84 * {@link NVList} and {@link org.omg.CORBA.portable.OutputStream} that writes to
87 * All other methods throw the {@link NO_IMPLEMENT} exception.
89 * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
91 public class OrbRestricted
extends org
.omg
.CORBA_2_3
.ORB
94 * The singleton instance of this ORB.
96 public static final ORB Singleton
= new OrbRestricted();
99 * The cumulated listener for all IOR interceptors. Interceptors are used by
100 * {@link gnu.CORBA.Poa.ORB_1_4}.
102 public IORInterceptor_3_0Operations iIor
;
105 * The cumulated listener for all server request interceptors. Interceptors
106 * are used by {@link gnu.CORBA.Poa.ORB_1_4}.
108 public ServerRequestInterceptorOperations iServer
;
111 * The cumulated listener for all client request interceptros. Interceptors
112 * are used by {@link gnu.CORBA.Poa.ORB_1_4}.
114 public ClientRequestInterceptorOperations iClient
;
117 * The required size of the interceptor slot array.
119 public int icSlotSize
= 0;
122 * The value factories.
124 protected Hashtable factories
= new Hashtable();
127 * The policy factories.
129 protected Hashtable policyFactories
= new Hashtable();
132 * Create a new instance of the RestrictedORB. This is used in derived classes
135 protected OrbRestricted()
140 public TypeCode
create_alias_tc(String id
, String name
, TypeCode typecode
)
142 return new AliasTypeCode(typecode
, id
, name
);
146 public Any
create_any()
148 gnuAny any
= new gnuAny();
154 public TypeCode
create_array_tc(int length
, TypeCode element_type
)
157 new ArrayTypeCode(TCKind
.tk_array
, element_type
);
163 public ContextList
create_context_list()
165 return new gnuContextList();
169 public TypeCode
create_enum_tc(String id
, String name
, String
[] values
)
171 RecordTypeCode r
= new RecordTypeCode(TCKind
.tk_enum
);
172 for (int i
= 0; i
< values
.length
; i
++)
174 r
.field().name
= values
[ i
];
184 public Environment
create_environment()
186 return new gnuEnvironment();
190 public ExceptionList
create_exception_list()
192 return new gnuExceptionList();
196 public TypeCode
create_exception_tc(String id
, String name
,
197 StructMember
[] members
200 RecordTypeCode r
= new RecordTypeCode(TCKind
.tk_except
);
204 for (int i
= 0; i
< members
.length
; i
++)
206 r
.add(members
[ i
]);
213 * This method is not allowed for a RestrictedORB.
215 * @throws NO_IMPLEMENT, always.
217 public TypeCode
create_interface_tc(String id
, String name
)
224 public NVList
create_list(int count
)
226 return new gnuNVList(count
);
230 public NamedValue
create_named_value(String s
, Any any
, int flags
)
232 return new gnuNamedValue();
236 public OutputStream
create_output_stream()
238 BufferedCdrOutput stream
= new BufferedCdrOutput();
244 public TypeCode
create_sequence_tc(int bound
, TypeCode element_type
)
247 new ArrayTypeCode(TCKind
.tk_sequence
, element_type
);
253 public TypeCode
create_string_tc(int bound
)
255 StringTypeCode p
= new StringTypeCode(TCKind
.tk_string
);
261 public TypeCode
create_struct_tc(String id
, String name
,
262 StructMember
[] members
265 RecordTypeCode r
= new RecordTypeCode(TCKind
.tk_struct
);
269 for (int i
= 0; i
< members
.length
; i
++)
271 r
.add(members
[ i
]);
278 public TypeCode
create_union_tc(String id
, String name
,
279 TypeCode discriminator_type
, UnionMember
[] members
282 RecordTypeCode r
= new RecordTypeCode(TCKind
.tk_union
);
285 r
.setDiscriminator_type(discriminator_type
);
286 r
.setDefaultIndex(0);
288 for (int i
= 0; i
< members
.length
; i
++)
290 r
.add(members
[ i
]);
297 public TypeCode
create_wstring_tc(int bound
)
299 StringTypeCode p
= new StringTypeCode(TCKind
.tk_wstring
);
305 public TypeCode
get_primitive_tc(TCKind tcKind
)
309 return TypeKindNamer
.getPrimitveTC(tcKind
);
313 throw new BAD_PARAM("This is not a primitive type code: " +
320 * This method is not allowed for a RestrictedORB.
322 * @throws NO_IMPLEMENT, always.
324 public String
[] list_initial_services()
327 throw new InternalError();
331 * This method is not allowed for a RestrictedORB.
333 * @throws NO_IMPLEMENT, always.
335 public String
object_to_string(org
.omg
.CORBA
.Object forObject
)
338 throw new InternalError();
342 * This method is not allowed for a RestrictedORB.
344 * @throws InvalidName never in this class, but it is thrown in the derived
347 * @throws NO_IMPLEMENT, always.
349 public org
.omg
.CORBA
.Object
resolve_initial_references(String name
)
353 throw new InternalError();
357 * Shutdown the ORB server.
359 * For RestrictedORB, returns witout action.
366 * Shutdown the ORB server.
368 * For RestrictedORB, returns witout action.
370 public void shutdown(boolean wait_for_completion
)
375 * This method is not allowed for a RestrictedORB.
377 * @throws NO_IMPLEMENT, always.
379 public org
.omg
.CORBA
.Object
string_to_object(String IOR
)
382 throw new InternalError();
386 * This method is not allowed for a RestrictedORB.
388 * @throws NO_IMPLEMENT, always.
390 protected void set_parameters(Applet app
, Properties props
)
396 * This method is not allowed for a RestrictedORB.
398 * @throws NO_IMPLEMENT, always.
400 protected void set_parameters(String
[] args
, Properties props
)
406 * Throws an exception, stating that the given method is not supported by the
409 private final void no()
411 // Apart the programming errors, this can only happen if the
412 // malicious code is trying to do that it is not allowed.
413 throw new NO_IMPLEMENT("Use init(args, props) for the functional version.");
417 * This method is not allowed for a RestrictedORB.
419 * @throws NO_IMPLEMENT, always.
421 public Request
get_next_response() throws org
.omg
.CORBA
.WrongTransaction
424 throw new InternalError();
428 * This method is not allowed for a RestrictedORB.
430 * @throws NO_IMPLEMENT, always.
432 public boolean poll_next_response()
435 throw new InternalError();
439 * This method is not allowed for a RestrictedORB.
441 * @throws NO_IMPLEMENT, always.
443 public void send_multiple_requests_deferred(Request
[] requests
)
449 * This method is not allowed for a RestrictedORB.
451 * @throws NO_IMPLEMENT, always.
453 public void send_multiple_requests_oneway(Request
[] requests
)
459 * Register the value factory under the given repository id.
461 public ValueFactory
register_value_factory(String repository_id
,
465 factories
.put(repository_id
, factory
);
470 * Unregister the value factroy.
472 public void unregister_value_factory(String id
)
474 factories
.remove(id
);
478 * Look for the value factory for the value, having the given repository id.
479 * The implementation checks for the registered value factories first. If none
480 * found, it tries to load and instantiate the class, mathing the given naming
481 * convention. If this faild, null is returned.
483 * @param repository_id a repository id.
485 * @return a found value factory, null if none.
487 public ValueFactory
lookup_value_factory(String repository_id
)
489 ValueFactory f
= (ValueFactory
) factories
.get(repository_id
);
495 f
= (ValueFactory
) ObjectCreator
.createObject(repository_id
,
500 factories
.put(repository_id
, f
);
506 * Destroy the interceptors, if they are present.
508 public void destroy()
532 * Create a typecode, representing a tree-like structure.
533 * This structure contains a member that is a sequence of the same type,
534 * as the structure itself. You can imagine as if the folder definition
535 * contains a variable-length array of the enclosed (nested) folder
536 * definitions. In this way, it is possible to have a tree like
537 * structure that can be transferred via CORBA CDR stream.
539 * @deprecated It is easier and clearler to use a combination of
540 * create_recursive_tc and create_sequence_tc instead.
542 * @param bound the maximal expected number of the nested components
543 * on each node; 0 if not limited.
545 * @param offset the position of the field in the returned structure
546 * that contains the sequence of the structures of the same field.
547 * The members before this field are intialised using parameterless
548 * StructMember constructor.
550 * @return a typecode, defining a stucture, where a member at the
551 * <code>offset</code> position defines an array of the identical
554 * @see #create_recursive_tc(String)
555 * @see #create_sequence_tc(int, TypeCode)
557 public TypeCode
create_recursive_sequence_tc(int bound
, int offset
)
559 RecordTypeCode r
= new RecordTypeCode(TCKind
.tk_struct
);
560 for (int i
= 0; i
< offset
; i
++)
561 r
.add(new StructMember());
563 TypeCode recurs
= new PrimitiveTypeCode(TCKind
.tk_sequence
);
565 r
.add(new StructMember("", recurs
, null));
570 * Get the default context of this ORB. This is an initial root of all
573 * The default method returns a new context with the empty name and
576 * @return the default context of this ORB.
578 public Context
get_default_context()
580 return new gnuContext("", null);