KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > orb > ORBSingleton


1 package org.jacorb.orb;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1997-2004 Gerald Brose.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */

22
23 import java.util.*;
24 import org.omg.CORBA.TypeCode JavaDoc;
25 import org.omg.CORBA.BAD_PARAM JavaDoc;
26 import org.omg.CORBA.BAD_TYPECODE JavaDoc;
27 import org.omg.CORBA.TCKind JavaDoc;
28 import org.omg.CORBA.CompletionStatus JavaDoc;
29
30 import org.apache.avalon.framework.configuration.*;
31
32 /**
33  * @author Gerald Brose, FU Berlin
34  * @version $Id: ORBSingleton.java,v 1.38 2004/05/06 12:40:00 nicolas Exp $
35  */

36
37 public class ORBSingleton
38     extends org.omg.CORBA_2_5.ORB
39     implements Configurable
40 {
41     private boolean doStrictCheckOnTypecodeCreation = false;
42
43     public void configure(Configuration configuration)
44         throws ConfigurationException
45     {
46         doStrictCheckOnTypecodeCreation =
47             configuration.getAttribute("jacorb.interop.strict_check_on_tc_creation", "on").equals("on");
48                   
49     }
50
51     
52     /* factory methods: */
53
54     public org.omg.CORBA.Any JavaDoc create_any()
55     {
56         return new org.jacorb.orb.Any(this);
57     }
58
59     /**
60      * Determine if a character is ok to start an id.
61      * (Note that '_' is allowed here - it might have
62      * been inserted by the IDL compiler to avoid clashes
63      * with reserved Java identifiers )
64      * @param ch the character in question.
65      */

66
67     final protected static boolean legalStartChar(int ch)
68     {
69         return
70            ( ch >= 'a' && ch <= 'z') || (ch == '_') ||
71            ( ch >= 'A' && ch <= 'Z');
72     }
73
74
75     /**
76      * Determine if a character is ok for the middle of an id.
77      * @param ch the character in question.
78      */

79     final protected static boolean legalNameChar(int ch)
80     {
81         return
82            legalStartChar(ch) ||
83            (ch == '_')
84            || (ch >= '0' && ch <= '9');
85     }
86
87
88     /**
89      * code>checkTCName</code> checks that a name is a legal IDL name
90      * (CORBA 2.6 4-59).
91      * @throws org.omg.CORBA.BAD_PARAM
92      */

93     private void checkTCName (String JavaDoc name) throws BAD_PARAM JavaDoc
94     {
95         checkTCName (name, false);
96     }
97
98
99    /**
100     * <code>checkTCName</code> checks the name is a legal IDL name and
101     * may optionally allow a null string (CORBA 2.6 4-59).
102     *
103     * @param name a <code>String</code> value
104     * @param allowNull a <code>boolean</code> value
105     * @exception BAD_PARAM if an error occurs
106     */

107    private void checkTCName (String JavaDoc name, boolean allowNull)
108         throws BAD_PARAM JavaDoc
109     {
110         if (name != null)
111         {
112             if( name.length() > 0 )
113             {
114                 // check that name begins with an ASCII char
115
if( !legalStartChar( name.charAt(0)) )
116                 {
117                     throw new BAD_PARAM JavaDoc
118                     (
119                        "Illegal start character to IDL name: " + name,
120                        15,
121                        CompletionStatus.COMPLETED_NO
122                     );
123                 }
124                 for( int i = 0; i < name.length(); i++ )
125                 {
126                     if( ! legalNameChar( name.charAt(i) ))
127                         throw new BAD_PARAM JavaDoc("Illegal IDL name: " + name, 15,
128                                             CompletionStatus.COMPLETED_NO );
129                 }
130             }
131             else
132             {
133                 throw new BAD_PARAM JavaDoc("Illegal blank IDL name", 15,
134                                     CompletionStatus.COMPLETED_NO );
135             }
136         }
137         else if (allowNull == false)
138         {
139             throw new BAD_PARAM JavaDoc("Illegal null IDL name", 15,
140                                 CompletionStatus.COMPLETED_NO );
141         }
142     }
143
144     /**
145      * Check that a repository ID is legal
146      * (cf. CORBA 2.4 chapter 10, section 7.3
147      * @param repId a <code>String</code> value
148      * @exception BAD_PARAM if an error occurs
149      */

150     private void checkTCRepositoryId( String JavaDoc repId )
151         throws BAD_PARAM JavaDoc
152     {
153         if( repId == null || repId.indexOf( ':' ) < 0 )
154         {
155             throw new BAD_PARAM JavaDoc("Illegal Repository ID: " + repId,
156                                 16, CompletionStatus.COMPLETED_NO );
157         }
158     }
159
160     /**
161      * check that a type is a legal member type
162      * (cf. CORBA 2.4 chapter 10, section 7.3
163      * @throws org.omg.CORBA.BAD_PARAM
164      */

165
166     private void checkTCMemberType( TypeCode tc )
167         throws BAD_TYPECODE JavaDoc
168     {
169         if( !org.jacorb.orb.TypeCode.isRecursive(tc) &&
170             (tc == null ||
171              tc.kind().value() == TCKind._tk_null ||
172              tc.kind().value() == TCKind._tk_void ||
173              tc.kind().value() == TCKind._tk_except
174              )
175             )
176         {
177             throw new BAD_TYPECODE JavaDoc("Illegal member tc", 2,
178                                    CompletionStatus.COMPLETED_NO );
179         }
180     }
181
182
183
184     /* TypeCode factory section */
185
186
187     public TypeCode create_alias_tc( String JavaDoc id,
188                                      String JavaDoc name,
189                                      TypeCode original_type)
190     {
191         checkTCRepositoryId( id );
192         checkTCName (name, true);
193         checkTCMemberType( original_type );
194         return new org.jacorb.orb.TypeCode( org.omg.CORBA.TCKind._tk_alias,
195                                             id, name, original_type);
196     }
197
198     public TypeCode create_array_tc( int length, TypeCode element_type)
199     {
200         checkTCMemberType( element_type );
201         return new org.jacorb.orb.TypeCode( org.omg.CORBA.TCKind._tk_array,
202                                             length,
203                                             element_type);
204     }
205
206     /**
207      * create an enum TypeCode
208      */

209
210     public TypeCode create_enum_tc( String JavaDoc id,
211                                     String JavaDoc name,
212                                     String JavaDoc[] members)
213     {
214         checkTCRepositoryId( id );
215         checkTCName (name, true);
216
217         // check that member names are legal and unique
218
Hashtable names = new Hashtable() ;
219         for( int i = 0; i < members.length; i++ )
220         {
221             boolean fault = false;
222             try
223             {
224                 checkTCName( members[i] );
225             }
226             catch( BAD_PARAM JavaDoc bp )
227             {
228                 fault = true;
229             }
230             if( names.containsKey( members[i] ) || fault )
231             {
232                 throw new BAD_PARAM JavaDoc("Illegal enum member name: " + members[i],
233                                     17, CompletionStatus.COMPLETED_NO );
234             }
235             names.put( members[i], "" );
236         }
237         names.clear();
238
239         return new org.jacorb.orb.TypeCode( id, name, members);
240     }
241
242     /**
243      * create an exception TypeCode
244      */

245
246     public TypeCode create_exception_tc( String JavaDoc id,
247                                          String JavaDoc name,
248                                          org.omg.CORBA.StructMember JavaDoc[] members)
249     {
250         checkTCRepositoryId( id );
251         checkTCName (name, true);
252
253         // check that member names are legal and unique
254
Hashtable names = new Hashtable() ;
255         for( int i = 0; i < members.length; i++ )
256         {
257             checkTCMemberType( members[i].type );
258             boolean fault = false;
259             try
260             {
261                 checkTCName( members[i].name );
262             }
263             catch( BAD_PARAM JavaDoc bp )
264             {
265                 fault = true;
266             }
267             if( names.containsKey( members[i].name ) || fault )
268             {
269                 throw new BAD_PARAM JavaDoc("Illegal exception member name: " +
270                                     members[i].name,
271                                     17, CompletionStatus.COMPLETED_NO );
272             }
273             names.put( members[i].name, "" );
274         }
275         names.clear();
276
277
278         return new org.jacorb.orb.TypeCode( org.omg.CORBA.TCKind._tk_except,
279                                             id,
280                                             name,
281                                             members);
282     }
283
284     public TypeCode create_interface_tc( String JavaDoc id, String JavaDoc name)
285     {
286         checkTCRepositoryId( id );
287         checkTCName (name, true);
288         return new org.jacorb.orb.TypeCode( org.omg.CORBA.TCKind._tk_objref,
289                                             id, name);
290     }
291
292     public org.omg.CORBA.TypeCode JavaDoc create_fixed_tc( short digits,
293                                                    short scale)
294     {
295         if (digits <= 0 || scale < 0 || scale > digits)
296         {
297             throw new org.omg.CORBA.BAD_PARAM JavaDoc
298                ("Invalid combination of digits and scale factor");
299         }
300         return new org.jacorb.orb.TypeCode(digits, scale);
301     }
302
303     public org.omg.CORBA.TypeCode JavaDoc create_recursive_tc( String JavaDoc id )
304     {
305         checkTCRepositoryId( id );
306         return new org.jacorb.orb.TypeCode( id );
307     }
308
309     public TypeCode create_sequence_tc( int bound, TypeCode element_type)
310     {
311         checkTCMemberType( element_type );
312         TypeCode tc =
313             new org.jacorb.orb.TypeCode( org.omg.CORBA.TCKind._tk_sequence,
314                                          bound,
315                                          element_type);
316         return tc;
317     }
318
319     public TypeCode create_string_tc(int bound)
320     {
321         return new org.jacorb.orb.TypeCode( org.omg.CORBA.TCKind._tk_string, bound );
322     }
323
324     public TypeCode create_wstring_tc(int bound)
325     {
326         return new org.jacorb.orb.TypeCode( org.omg.CORBA.TCKind._tk_wstring, bound);
327     }
328
329     /**
330      * create a struct TypeCode
331      */

332
333     public TypeCode create_struct_tc(String JavaDoc id,
334                                      String JavaDoc name,
335                                      org.omg.CORBA.StructMember JavaDoc[] members)
336     {
337         checkTCRepositoryId( id );
338         checkTCName (name, true);
339
340         // check that member names are legal and unique
341
Hashtable names = new Hashtable() ;
342         for( int i = 0; i < members.length; i++ )
343         {
344             checkTCMemberType( members[i].type );
345             boolean fault = false;
346             try
347             {
348                 checkTCName( members[i].name );
349             }
350             catch( BAD_PARAM JavaDoc bp )
351             {
352                 fault = true;
353             }
354             if( names.containsKey( members[i].name ) || fault )
355             {
356                 throw new BAD_PARAM JavaDoc("Illegal struct member name: " +
357                                     members[i].name + (fault? " (Bad PARAM) ": "" ),
358                                     17, CompletionStatus.COMPLETED_NO );
359             }
360             names.put( members[i].name, "" );
361         }
362         names.clear();
363
364         org.jacorb.orb.TypeCode tc =
365             new org.jacorb.orb.TypeCode( org.omg.CORBA.TCKind._tk_struct,
366                                          id,
367                                          name,
368                                          members);
369
370         // resolve any recursive references to this TypeCode in its members
371
tc.resolveRecursion();
372         return tc;
373     }
374
375     /**
376      * create a union TypeCode
377      */

378
379     public TypeCode create_union_tc( String JavaDoc id,
380                                      String JavaDoc name,
381                                      TypeCode discriminator_type,
382                                      org.omg.CORBA.UnionMember JavaDoc[] members)
383     {
384         checkTCRepositoryId( id );
385         checkTCName (name, true);
386
387         // check discriminator type
388

389         TypeCode disc_tc =
390             org.jacorb.orb.TypeCode.originalType(discriminator_type);
391
392         if (disc_tc == null ||
393             !(disc_tc.kind().value() == TCKind._tk_short ||
394               disc_tc.kind().value() == TCKind._tk_long ||
395               disc_tc.kind().value() == TCKind._tk_longlong ||
396               disc_tc.kind().value() == TCKind._tk_ushort ||
397               disc_tc.kind().value() == TCKind._tk_ulong ||
398               disc_tc.kind().value() == TCKind._tk_ulonglong ||
399               disc_tc.kind().value() == TCKind._tk_char ||
400               disc_tc.kind().value() == TCKind._tk_boolean ||
401               disc_tc.kind().value() == TCKind._tk_enum
402               )
403             )
404         {
405             throw new BAD_PARAM JavaDoc("Illegal union discriminator type",
406                                 20, CompletionStatus.COMPLETED_NO );
407         }
408
409         // check that member names are legal (they do not need to be unique)
410

411         for( int i = 0; i < members.length; i++ )
412         {
413             checkTCMemberType( members[i].type );
414             try
415             {
416                 checkTCName( members[i].name );
417             }
418             catch( BAD_PARAM JavaDoc bp )
419             {
420                 throw new BAD_PARAM JavaDoc("Illegal union member name: " +
421                                     members[i].name,
422                                     17, CompletionStatus.COMPLETED_NO );
423             }
424
425             // check that member type matches discriminator type or is default
426

427             org.omg.CORBA.Any JavaDoc label = members[i].label;
428             if (! discriminator_type.equivalent( label.type () ) &&
429                 ! ( label.type().kind().value() == TCKind._tk_octet &&
430                     label.extract_octet() == (byte)0
431                     )
432                 )
433             {
434                 throw new BAD_PARAM JavaDoc("Label type does not match discriminator type",
435                                     19,
436                                     CompletionStatus.COMPLETED_NO );
437             }
438
439             // check that member labels are unique
440

441             for( int j = 0; j < i; j++ )
442             {
443                 if( label.equal( members[j].label ))
444                 {
445                     throw new BAD_PARAM JavaDoc("Duplicate union case label",
446                                         18,
447                                         CompletionStatus.COMPLETED_NO );
448                 }
449             }
450         }
451
452         org.jacorb.orb.TypeCode tc =
453            new org.jacorb.orb.TypeCode( id,
454                                         name,
455                                         discriminator_type,
456                                         members);
457
458         // resolve any recursive references to this TypeCode in its members
459
tc.resolveRecursion();
460         return tc;
461     }
462
463
464     public TypeCode get_primitive_tc(org.omg.CORBA.TCKind JavaDoc tcKind)
465     {
466         return org.jacorb.orb.TypeCode.get_primitive_tc( tcKind.value() );
467     }
468
469     public org.omg.CORBA.TypeCode JavaDoc create_value_tc(String JavaDoc id,
470                                                   String JavaDoc name,
471                                                   short type_modifier,
472                                                   TypeCode concrete_base,
473                                                   org.omg.CORBA.ValueMember JavaDoc[] members)
474     {
475         checkTCRepositoryId( id );
476
477         // The name parameter should be a valid IDL name, but in the case of
478
// an RMI valuetype the ORB in jdk1.4 sends a dotted name (such as
479
// "some.package.SomeClass") over the wire. For interoperability with
480
// Sun's ORB we skip the name check in this case.
481

482         if ( !id.startsWith("RMI:") )
483             checkTCName (name, true);
484         return new org.jacorb.orb.TypeCode (id,
485                                             name,
486                                             type_modifier,
487                                             concrete_base,
488                                             members);
489     }
490
491     public org.omg.CORBA.TypeCode JavaDoc create_value_box_tc(String JavaDoc id,
492                                                       String JavaDoc name,
493                                                       TypeCode boxed_type)
494     {
495         checkTCRepositoryId( id );
496         checkTCName (name, true);
497         return new org.jacorb.orb.TypeCode (org.omg.CORBA.TCKind._tk_value_box,
498                                             id,
499                                             name,
500                                             boxed_type);
501     }
502
503     public org.omg.CORBA.TypeCode JavaDoc create_abstract_interface_tc(String JavaDoc id,
504                                                                String JavaDoc name)
505     {
506        checkTCRepositoryId( id );
507
508        // strict_check_on_tc_creation is incompatible with Sun's ValueHandler,
509
// which calls create_abstract_interface_tc() passing an empty string
510
// as the name parameter. checkTCName() then throws
511
//`org.omg.CORBA.BAD_PARAM: Illegal blank IDL name'.
512
if ( doStrictCheckOnTypecodeCreation )
513            checkTCName (name, true);
514
515        return new org.jacorb.orb.TypeCode (org.omg.CORBA.TCKind._tk_abstract_interface,
516                                            id,
517                                            name);
518     }
519
520     public org.omg.CORBA.TypeCode JavaDoc create_local_interface_tc(String JavaDoc id,
521                                                             String JavaDoc name)
522     {
523        checkTCRepositoryId( id );
524        checkTCName (name, true);
525        return new org.jacorb.orb.TypeCode (org.omg.CORBA.TCKind._tk_local_interface,
526                                            id,
527                                            name);
528     }
529
530     public org.omg.CORBA.TypeCode JavaDoc create_native_tc(String JavaDoc id,
531                                                    String JavaDoc name)
532     {
533        checkTCRepositoryId( id );
534        checkTCName (name, true);
535        return new org.jacorb.orb.TypeCode (org.omg.CORBA.TCKind._tk_native,
536                                            id,
537                                            name);
538     }
539
540    /* not allowed on the singleton: */
541
542     public org.omg.CORBA.ExceptionList JavaDoc create_exception_list()
543     {
544         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc ("The Singleton ORB only permits factory methods");
545     }
546
547     public org.omg.CORBA.NVList JavaDoc create_list (int count)
548     {
549         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc ("The Singleton ORB only permits factory methods");
550     }
551
552     public org.omg.CORBA.NamedValue JavaDoc create_named_value
553         (String JavaDoc name, org.omg.CORBA.Any JavaDoc value, int flags)
554     {
555         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc ("The Singleton ORB only permits factory methods");
556     }
557
558     public org.omg.CORBA.NVList JavaDoc create_operation_list
559         (org.omg.CORBA.OperationDef JavaDoc oper)
560     {
561         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc ("The Singleton ORB only permits factory methods");
562     }
563
564     public org.omg.CORBA.NVList JavaDoc create_operation_list
565         (org.omg.CORBA.Object JavaDoc obj)
566     {
567         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc ("The Singleton ORB only permits factory methods");
568     }
569
570     public org.omg.CORBA.Object JavaDoc string_to_object(String JavaDoc str)
571     {
572         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc ("The Singleton ORB only permits factory methods");
573     }
574
575     public org.omg.CORBA.Environment JavaDoc create_environment()
576     {
577         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc ("The Singleton ORB only permits factory methods");
578     }
579
580     public org.omg.CORBA.ContextList JavaDoc create_context_list()
581     {
582         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc ("The Singleton ORB only permits factory methods");
583     }
584
585     public org.omg.CORBA.portable.OutputStream JavaDoc create_output_stream()
586     {
587         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc ("The Singleton ORB only permits factory methods");
588     }
589
590     public org.omg.CORBA.Current JavaDoc get_current()
591     {
592         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc ("The Singleton ORB only permits factory methods");
593     }
594
595     public org.omg.CORBA.Context JavaDoc get_default_context()
596     {
597         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc ("The Singleton ORB only permits factory methods");
598     }
599
600     public org.omg.CORBA.Request JavaDoc get_next_response()
601     {
602         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc ("The Singleton ORB only permits factory methods");
603     }
604
605     public String JavaDoc[] list_initial_services()
606     {
607         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc ("The Singleton ORB only permits factory methods");
608     }
609
610     public String JavaDoc object_to_string( org.omg.CORBA.Object JavaDoc obj)
611     {
612         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc ("The Singleton ORB only permits factory methods");
613     }
614
615     public boolean poll_next_response()
616     {
617         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc ("The Singleton ORB only permits factory methods");
618     }
619
620     public org.omg.CORBA.Object JavaDoc resolve_initial_references(String JavaDoc identifier)
621         throws org.omg.CORBA.ORBPackage.InvalidName JavaDoc
622     {
623         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc ("The Singleton ORB only permits factory methods");
624     }
625
626     public void send_multiple_requests_deferred(org.omg.CORBA.Request JavaDoc[] req)
627     {
628         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc ("The Singleton ORB only permits factory methods");
629     }
630
631     public void send_multiple_requests_oneway(org.omg.CORBA.Request JavaDoc[] req)
632     {
633         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc ("The Singleton ORB only permits factory methods");
634     }
635
636     protected void set_parameters(String JavaDoc[] args, java.util.Properties JavaDoc props)
637     {
638         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc ("The Singleton ORB only permits factory methods");
639     }
640
641     protected void set_parameters(java.applet.Applet JavaDoc app, java.util.Properties JavaDoc props)
642     {
643         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc ("The Singleton ORB only permits factory methods");
644     }
645
646     public void run()
647     {
648         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc ("The Singleton ORB only permits factory methods");
649     }
650
651     public void shutdown(boolean wait_for_completion)
652     {
653         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc ("The Singleton ORB only permits factory methods");
654     }
655
656     public boolean work_pending()
657     {
658         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc ("The Singleton ORB only permits factory methods");
659     }
660
661     public void perform_work()
662     {
663         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc ("The Singleton ORB only permits factory methods");
664     }
665 }
666
Popular Tags