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
.IORInterceptorOperations
;
69 import org
.omg
.PortableInterceptor
.IORInterceptor_3_0Operations
;
70 import org
.omg
.PortableInterceptor
.ServerRequestInterceptorOperations
;
72 import java
.applet
.Applet
;
74 import java
.util
.Hashtable
;
75 import java
.util
.Properties
;
78 * This class implements so-called Singleton ORB, a highly restricted version
79 * that cannot communicate over network. This ORB is provided for the
80 * potentially malicious applets with heavy security restrictions. It, however,
81 * supports some basic features that might be needed even when the network
82 * access is not granted.
84 * This ORB can only create typecodes, {@link Any}, {@link ContextList},
85 * {@link NVList} and {@link org.omg.CORBA.portable.OutputStream} that writes to
88 * All other methods throw the {@link NO_IMPLEMENT} exception.
90 * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
92 public class OrbRestricted
extends org
.omg
.CORBA_2_3
.ORB
95 * The singleton instance of this ORB.
97 public static final ORB Singleton
= new OrbRestricted();
100 * The cumulated listener for all IOR interceptors. Interceptors are used by
101 * {@link gnu.CORBA.Poa.ORB_1_4}.
103 public IORInterceptor_3_0Operations iIor
;
106 * The cumulated listener for all server request interceptors. Interceptors
107 * are used by {@link gnu.CORBA.Poa.ORB_1_4}.
109 public ServerRequestInterceptorOperations iServer
;
112 * The cumulated listener for all client request interceptros. Interceptors
113 * are used by {@link gnu.CORBA.Poa.ORB_1_4}.
115 public ClientRequestInterceptorOperations iClient
;
118 * The required size of the interceptor slot array.
120 public int icSlotSize
= 0;
123 * The value factories.
125 protected Hashtable factories
= new Hashtable();
128 * The policy factories.
130 protected Hashtable policyFactories
= new Hashtable();
133 * Create a new instance of the RestrictedORB. This is used in derived classes
136 protected OrbRestricted()
141 public TypeCode
create_alias_tc(String id
, String name
, TypeCode typecode
)
143 return new AliasTypeCode(typecode
, id
, name
);
147 public Any
create_any()
149 gnuAny any
= new gnuAny();
155 public TypeCode
create_array_tc(int length
, TypeCode element_type
)
158 new ArrayTypeCode(TCKind
.tk_array
, element_type
);
164 public ContextList
create_context_list()
166 return new gnuContextList();
170 public TypeCode
create_enum_tc(String id
, String name
, String
[] values
)
172 RecordTypeCode r
= new RecordTypeCode(TCKind
.tk_enum
);
173 for (int i
= 0; i
< values
.length
; i
++)
175 r
.field().name
= values
[ i
];
185 public Environment
create_environment()
187 return new gnuEnvironment();
191 public ExceptionList
create_exception_list()
193 return new gnuExceptionList();
197 public TypeCode
create_exception_tc(String id
, String name
,
198 StructMember
[] members
201 RecordTypeCode r
= new RecordTypeCode(TCKind
.tk_except
);
205 for (int i
= 0; i
< members
.length
; i
++)
207 r
.add(members
[ i
]);
214 * This method is not allowed for a RestrictedORB.
216 * @throws NO_IMPLEMENT, always.
218 public TypeCode
create_interface_tc(String id
, String name
)
225 public NVList
create_list(int count
)
227 return new gnuNVList(count
);
231 public NamedValue
create_named_value(String s
, Any any
, int flags
)
233 return new gnuNamedValue();
237 public OutputStream
create_output_stream()
239 BufferedCdrOutput stream
= new BufferedCdrOutput();
245 public TypeCode
create_sequence_tc(int bound
, TypeCode element_type
)
248 new ArrayTypeCode(TCKind
.tk_sequence
, element_type
);
254 public TypeCode
create_string_tc(int bound
)
256 StringTypeCode p
= new StringTypeCode(TCKind
.tk_string
);
262 public TypeCode
create_struct_tc(String id
, String name
,
263 StructMember
[] members
266 RecordTypeCode r
= new RecordTypeCode(TCKind
.tk_struct
);
270 for (int i
= 0; i
< members
.length
; i
++)
272 r
.add(members
[ i
]);
279 public TypeCode
create_union_tc(String id
, String name
,
280 TypeCode discriminator_type
, UnionMember
[] members
283 RecordTypeCode r
= new RecordTypeCode(TCKind
.tk_union
);
286 r
.setDiscriminator_type(discriminator_type
);
287 r
.setDefaultIndex(0);
289 for (int i
= 0; i
< members
.length
; i
++)
291 r
.add(members
[ i
]);
298 public TypeCode
create_wstring_tc(int bound
)
300 StringTypeCode p
= new StringTypeCode(TCKind
.tk_wstring
);
306 public TypeCode
get_primitive_tc(TCKind tcKind
)
310 return TypeKindNamer
.getPrimitveTC(tcKind
);
314 throw new BAD_PARAM("This is not a primitive type code: " +
321 * This method is not allowed for a RestrictedORB.
323 * @throws NO_IMPLEMENT, always.
325 public String
[] list_initial_services()
328 throw new InternalError();
332 * This method is not allowed for a RestrictedORB.
334 * @throws NO_IMPLEMENT, always.
336 public String
object_to_string(org
.omg
.CORBA
.Object forObject
)
339 throw new InternalError();
343 * This method is not allowed for a RestrictedORB.
345 * @throws InvalidName never in this class, but it is thrown in the derived
348 * @throws NO_IMPLEMENT, always.
350 public org
.omg
.CORBA
.Object
resolve_initial_references(String name
)
354 throw new InternalError();
358 * Shutdown the ORB server.
360 * For RestrictedORB, returns witout action.
367 * Shutdown the ORB server.
369 * For RestrictedORB, returns witout action.
371 public void shutdown(boolean wait_for_completion
)
376 * This method is not allowed for a RestrictedORB.
378 * @throws NO_IMPLEMENT, always.
380 public org
.omg
.CORBA
.Object
string_to_object(String IOR
)
383 throw new InternalError();
387 * This method is not allowed for a RestrictedORB.
389 * @throws NO_IMPLEMENT, always.
391 protected void set_parameters(Applet app
, Properties props
)
397 * This method is not allowed for a RestrictedORB.
399 * @throws NO_IMPLEMENT, always.
401 protected void set_parameters(String
[] args
, Properties props
)
407 * Throws an exception, stating that the given method is not supported by the
410 private final void no()
412 // Apart the programming errors, this can only happen if the
413 // malicious code is trying to do that it is not allowed.
414 throw new NO_IMPLEMENT("Use init(args, props) for the functional version.");
418 * This method is not allowed for a RestrictedORB.
420 * @throws NO_IMPLEMENT, always.
422 public Request
get_next_response() throws org
.omg
.CORBA
.WrongTransaction
425 throw new InternalError();
429 * This method is not allowed for a RestrictedORB.
431 * @throws NO_IMPLEMENT, always.
433 public boolean poll_next_response()
436 throw new InternalError();
440 * This method is not allowed for a RestrictedORB.
442 * @throws NO_IMPLEMENT, always.
444 public void send_multiple_requests_deferred(Request
[] requests
)
450 * This method is not allowed for a RestrictedORB.
452 * @throws NO_IMPLEMENT, always.
454 public void send_multiple_requests_oneway(Request
[] requests
)
460 * Register the value factory under the given repository id.
462 public ValueFactory
register_value_factory(String repository_id
,
466 factories
.put(repository_id
, factory
);
471 * Unregister the value factroy.
473 public void unregister_value_factory(String id
)
475 factories
.remove(id
);
479 * Look for the value factory for the value, having the given repository id.
480 * The implementation checks for the registered value factories first. If none
481 * found, it tries to load and instantiate the class, mathing the given naming
482 * convention. If this faild, null is returned.
484 * @param repository_id a repository id.
486 * @return a found value factory, null if none.
488 public ValueFactory
lookup_value_factory(String repository_id
)
490 ValueFactory f
= (ValueFactory
) factories
.get(repository_id
);
496 f
= (ValueFactory
) ObjectCreator
.createObject(repository_id
,
501 factories
.put(repository_id
, f
);
507 * Destroy the interceptors, if they are present.
509 public void destroy()
533 * Create a typecode, representing a tree-like structure.
534 * This structure contains a member that is a sequence of the same type,
535 * as the structure itself. You can imagine as if the folder definition
536 * contains a variable-length array of the enclosed (nested) folder
537 * definitions. In this way, it is possible to have a tree like
538 * structure that can be transferred via CORBA CDR stream.
540 * @deprecated It is easier and clearler to use a combination of
541 * create_recursive_tc and create_sequence_tc instead.
543 * @param bound the maximal expected number of the nested components
544 * on each node; 0 if not limited.
546 * @param offset the position of the field in the returned structure
547 * that contains the sequence of the structures of the same field.
548 * The members before this field are intialised using parameterless
549 * StructMember constructor.
551 * @return a typecode, defining a stucture, where a member at the
552 * <code>offset</code> position defines an array of the identical
555 * @see #create_recursive_tc(String)
556 * @see #create_sequence_tc(int, TypeCode)
558 public TypeCode
create_recursive_sequence_tc(int bound
, int offset
)
560 RecordTypeCode r
= new RecordTypeCode(TCKind
.tk_struct
);
561 for (int i
= 0; i
< offset
; i
++)
562 r
.add(new StructMember());
564 TypeCode recurs
= new PrimitiveTypeCode(TCKind
.tk_sequence
);
566 r
.add(new StructMember("", recurs
, null));
571 * Get the default context of this ORB. This is an initial root of all
574 * The default method returns a new context with the empty name and
577 * @return the default context of this ORB.
579 public Context
get_default_context()
581 return new gnuContext("", null);