KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.*;
25 import java.lang.reflect.*;
26
27 import org.jacorb.imr.ImRAccessImpl;
28 import org.jacorb.util.*;
29 import org.jacorb.orb.iiop.*;
30 import org.jacorb.orb.policies.*;
31 import org.jacorb.orb.dii.Request;
32 import org.jacorb.orb.giop.*;
33 import org.jacorb.orb.portableInterceptor.*;
34 import org.jacorb.poa.util.POAUtil;
35
36 import org.apache.avalon.framework.logger.*;
37 import org.apache.avalon.framework.configuration.*;
38
39 import org.omg.CORBA.BAD_PARAM JavaDoc;
40 import org.omg.CORBA.BAD_INV_ORDER JavaDoc;
41 import org.omg.CORBA.INITIALIZE JavaDoc;
42 import org.omg.CORBA.INTERNAL JavaDoc;
43 import org.omg.CORBA.BAD_QOS JavaDoc;
44 import org.omg.CORBA.TypeCode JavaDoc;
45 import org.omg.CORBA.BooleanHolder JavaDoc;
46 import org.omg.CORBA.ORBPackage.InvalidName JavaDoc;
47 import org.omg.CORBA.portable.ValueFactory JavaDoc;
48 import org.omg.CORBA.portable.BoxedValueHelper JavaDoc;
49 import org.omg.CORBA.portable.StreamableValue JavaDoc;
50 import org.omg.Messaging.*;
51 import org.omg.PortableInterceptor.*;
52 import org.omg.PortableServer.POAManagerPackage.AdapterInactive JavaDoc;
53 import org.omg.PortableServer.POAManagerPackage.State JavaDoc;
54 import org.omg.IOP.*;
55 import org.omg.IIOP.*;
56 import org.omg.ETF.*;
57
58 /**
59  * @author Gerald Brose, FU Berlin
60  * @version $Id: ORB.java,v 1.124 2005/06/01 19:55:19 brose Exp $
61  */

62
63 public final class ORB
64     extends ORBSingleton
65     implements org.jacorb.poa.POAListener, Configurable
66 {
67     private static final String JavaDoc versionString = org.jacorb.util.Version.version;
68     private static final String JavaDoc dateString = org.jacorb.util.Version.date;
69     private static final String JavaDoc nullIORString =
70         "IOR:00000000000000010000000000000000";
71
72     /** the configuration object for this ORB instance */
73     private org.jacorb.config.Configuration configuration = null;
74
75     /** configuration properties */
76     private boolean cacheReferences;
77     private String JavaDoc implName;
78     private int giopMinorVersion;
79     private boolean giopAdd_1_0_Profiles;
80     private String JavaDoc hashTableClassName;
81     private boolean useIMR;
82     private boolean useIMREndpoint;
83     private String JavaDoc imrProxyHost = null;
84     private int imrProxyPort = -1;
85     private String JavaDoc iorProxyHost;
86     private int iorProxyPort = -1;
87     private boolean printVersion = true;
88
89     /** "initial" references */
90     private Map initial_references = new HashMap();
91
92     private org.jacorb.poa.POA rootpoa;
93     private org.jacorb.poa.Current poaCurrent;
94     private BasicAdapter basicAdapter;
95     private org.omg.SecurityLevel2.Current securityCurrent = null;
96
97     /** interceptor handling */
98     private InterceptorManager interceptor_manager = null;
99     private boolean hasClientInterceptors = false;
100     private boolean hasServerInterceptors = false;
101     private org.omg.PortableInterceptor.Current JavaDoc piCurrent = new PICurrent();
102
103     /** reference caching */
104     private Map knownReferences = null;
105
106     /** connection mgmt. */
107     private ClientConnectionManager clientConnectionManager;
108
109     /** The transport manager*/
110     private TransportManager transport_manager = null;
111
112     private GIOPConnectionManager giop_connection_manager = null;
113
114     /** buffer mgmt. */
115     private BufferManager bufferManager;
116
117     /**
118      * Maps repository ids (strings) to objects that implement
119      * org.omg.CORBA.portable.ValueFactory. This map is used by
120      * register/unregister_value_factory() and lookup_value_factory().
121      */

122     protected Map valueFactories = new HashMap();
123
124     /**
125      * Maps repository ids (strings) of boxed value types to
126      * BoxedValueHelper instances for those types.
127      */

128     protected Map boxedValueHelpers = new HashMap();
129
130     private Map objectKeyMap = new HashMap();
131
132     /** properties */
133     private java.util.Properties JavaDoc _props;
134
135     /** the ORB object's logger */
136     private Logger logger;
137
138     /** command like args */
139     public String JavaDoc[] _args;
140
141     /* for run() and shutdown() */
142     private Object JavaDoc orb_synch = new java.lang.Object JavaDoc();
143     private boolean run = true;
144     private boolean wait = true;
145     private boolean shutdown_in_progress = false;
146     private boolean destroyed = false;
147     private Object JavaDoc shutdown_synch = new Object JavaDoc();
148
149     /* for registering POAs with the ImR */
150     private ImRAccess imr = null;
151     private int persistentPOACount;
152
153     public static final String JavaDoc orb_id = "jacorb:" + org.jacorb.util.Version.version;
154
155     /* outstanding dii requests awaiting completion */
156     private Set requests = Collections.synchronizedSet( new HashSet() );
157     /* most recently completed dii request found during poll */
158     private Request request = null;
159
160     /* PolicyManagement */
161     private org.jacorb.orb.policies.PolicyManager policyManager = null;
162
163     /* policy factories, from portable interceptor spec */
164     private Map policy_factories = null;
165
166     private static org.omg.CORBA.TCKind JavaDoc kind;
167
168     private static final String JavaDoc [] services =
169         {"RootPOA","POACurrent", "DynAnyFactory", "PICurrent", "CodecFactory"};
170
171     private boolean bidir_giop = false;
172
173
174     public ORB()
175     {
176     }
177
178     /**
179      * configure the ORB
180      */

181
182     public void configure(Configuration myConfiguration)
183         throws ConfigurationException
184     {
185         super.configure(myConfiguration);
186         this.configuration =
187             (org.jacorb.config.Configuration)myConfiguration;
188         logger =
189             configuration.getNamedLogger("jacorb.orb");
190
191         cacheReferences =
192             configuration.getAttribute("jacorb.reference_caching", "off").equals("on");
193
194         implName =
195             configuration.getAttribute("jacorb.implname", "" );
196
197         giopMinorVersion =
198             configuration.getAttributeAsInteger("jacorb.giop_minor_version", 2);
199
200         giopAdd_1_0_Profiles =
201             configuration.getAttribute("jacorb.giop.add_1_0_profiles", "off").equals("on");
202
203         hashTableClassName =
204             configuration.getAttribute( "jacorb.hashtable_class", "" );
205
206         useIMR =
207             configuration.getAttribute("jacorb.use_imr","off").equals("on");
208
209         imrProxyHost =
210             configuration.getAttribute("jacorb.imr.ior_proxy_host",null);
211
212         imrProxyPort =
213             configuration.getAttributeAsInteger("jacorb.imr.ior_proxy_port",-1);
214
215         useIMREndpoint =
216             configuration.getAttribute("jacorb.use_imr", "on").equals("on");
217
218         iorProxyHost =
219             configuration.getAttribute("jacorb.ior_proxy_host", null);
220
221         iorProxyPort =
222             configuration.getAttributeAsInteger("jacorb.ior_proxy_port",-1);
223
224         printVersion =
225             configuration.getAttribute("jacorb.orb.print_version", "on").equals("on");
226
227         if( printVersion && logger.isInfoEnabled())
228         {
229             logger.info("\n\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" +
230                         "\tJacORB V " + versionString + ", www.jacorb.org\n" +
231                         "\t(C) The JacORB project " +
232                         dateString + "\n" +
233                         "\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
234         }
235
236         BufferManager.configure( configuration);
237         try
238         {
239             bufferManager = BufferManager.getInstance();
240         }
241         catch( BAD_INV_ORDER JavaDoc b)
242         {
243             b.printStackTrace(); // cannot happen!
244
}
245
246         configureObjectKeyMap(configuration);
247     }
248
249     /**
250      * Some parts of JacORB cannot be elegantly configured from the outside
251      * and need access to the ORB's configuration retrieve config settings.
252      * This method should only be used in those restricted cases!
253      */

254
255     public org.jacorb.config.Configuration getConfiguration()
256     {
257         return configuration;
258     }
259
260     /**
261      * Overrides id() in org.omg.CORBA_2_5.ORB
262      */

263
264     public String JavaDoc id()
265     {
266         return orb_id;
267     }
268
269     public boolean useBiDirGIOP()
270     {
271         return bidir_giop;
272     }
273
274     public void turnOnBiDirGIOP()
275     {
276         if( ! bidir_giop )
277         {
278             bidir_giop = true;
279
280             clientConnectionManager.setRequestListener( basicAdapter.getRequestListener() );
281         }
282     }
283
284     /**
285      * This version of _getObject is used for references that have
286      * arrived over the network and is called from CDRInputStream. It
287      * removes stale cache entries
288      */

289
290     public synchronized org.omg.CORBA.Object JavaDoc _getObject( ParsedIOR pior )
291     {
292         String JavaDoc key = pior.getIORString();
293         org.omg.CORBA.portable.ObjectImpl JavaDoc o =
294             (org.omg.CORBA.portable.ObjectImpl JavaDoc)knownReferences.get( key );
295
296         if( o != null )
297         {
298             org.jacorb.orb.Delegate del = (org.jacorb.orb.Delegate)o._get_delegate();
299             if (del != null)
300             {
301                 ParsedIOR delpior= del.getParsedIOR();
302                 if (delpior == null)
303                 {
304                     knownReferences.remove(key);
305                     if (logger.isDebugEnabled())
306                     {
307                         logger.debug("Removing an invalid reference from cache.");
308                     }
309                 }
310                 else if( pior.getEffectiveProfile()
311                            .is_match(delpior.getEffectiveProfile()))
312                 {
313                     return o._duplicate();
314                 }
315             }
316             else
317             {
318                 if (logger.isDebugEnabled())
319                 {
320                     logger.debug("Remove stale reference from cache ");
321                 }
322                 knownReferences.remove( key );
323             }
324         }
325
326         if (pior == null)
327         {
328             if (logger.isErrorEnabled())
329                 logger.error("Internal error, pior is null");
330         }
331
332         org.jacorb.orb.Delegate d = new Delegate(this, pior );
333         try
334         {
335             d.configure(configuration);
336         }
337         catch(ConfigurationException ce)
338         {
339             if (logger.isErrorEnabled())
340                 logger.error("ConfigurationException", ce);
341         }
342
343         o = d.getReference( null );
344
345         if( cacheReferences )
346         {
347             knownReferences.put( key, o );
348         }
349         return o;
350     }
351
352     /**
353      * Find a local POA for a delegate (called from is_local())
354      * returns non-null only if a root POA is already activated
355      * and all POAs along the path on the poa name are active, i.e.
356      * returns null for POAs in the holding state
357      */

358
359     org.jacorb.poa.POA findPOA( org.jacorb.orb.Delegate d,
360                                 org.omg.CORBA.Object JavaDoc ref )
361     {
362         List scopes;
363         String JavaDoc res;
364         String JavaDoc refImplName = null;
365
366         // if no POAs activated, we don't look further
367
if( rootpoa == null || basicAdapter == null )
368         {
369             return null;
370         }
371
372         // String orbImplName = Environment.getProperty( "jacorb.implname", "" );
373

374         try
375         {
376             refImplName =
377                 org.jacorb.poa.util.POAUtil.extractImplName( d.getObjectKey() );
378         }
379         catch( org.jacorb.poa.except.POAInternalError pie )
380         {
381             if( logger.isDebugEnabled() )
382             {
383                 logger.debug("findPOA: reference generated by foreign POA");
384             }
385             return null;
386         }
387
388         if( refImplName == null )
389         {
390             if( implName.length() > 0 )
391             {
392                 if( logger.isDebugEnabled() )
393                 {
394                     logger.debug("findPOA: impl_name mismatch");
395                 }
396                 return null;
397             }
398         }
399         else
400         {
401             if( !(implName.equals( refImplName ) ))
402             {
403                 if( logger.isDebugEnabled() )
404                 {
405                     logger.debug("findPOA: impl_name mismatch");
406                 }
407                 return null;
408             }
409         }
410
411
412         try
413         {
414             org.jacorb.poa.POA tmp_poa = (org.jacorb.poa.POA)rootpoa;
415             String JavaDoc poa_name =
416                 org.jacorb.poa.util.POAUtil.extractPOAName( d.getObjectKey() );
417
418             /* strip scoped poa name (first part of the object key before "::",
419              * will be empty for the root poa
420              */

421             scopes = POAUtil.extractScopedPOANames (poa_name);
422
423             for( int i = 0; i < scopes.size(); i++)
424             {
425                 res = ((String JavaDoc)scopes.get( i ));
426
427                 if( res.equals (""))
428                     break;
429
430                 /* the following is a call to a method in the private
431                    interface between the ORB and the POA. It does the
432                    necessary synchronization between incoming,
433                    potentially concurrent requests to activate a POA
434                    using its adapter activator. This call will block
435                    until the correct POA is activated and ready to
436                    service requests. Thus, concurrent calls
437                    originating from a single, multi-threaded client
438                    will be serialized because the thread that accepts
439                    incoming requests from the client process is
440                    blocked. Concurrent calls from other destinations
441                    are not serialized unless they involve activating
442                    the same adapter. */

443
444                 try
445                 {
446                     tmp_poa = tmp_poa._getChildPOA( res );
447                 }
448                 catch ( org.jacorb.poa.except.ParentIsHolding p )
449                 {
450                     if( logger.isDebugEnabled() )
451                     {
452                         logger.debug("findPOA: holding adapter");
453                     }
454                     return null;
455                 }
456             }
457             byte[] objectId =
458                 org.jacorb.poa.util.POAUtil.extractOID( ref );
459
460             if( tmp_poa.isSystemId()
461                && ! tmp_poa.previouslyGeneratedObjectId(objectId))
462             {
463                 if( logger.isDebugEnabled() )
464                 {
465                     logger.debug("findPOA: not a previously generated object key.");
466                 }
467                 return null;
468             }
469
470             return tmp_poa;
471         }
472         catch( Exception JavaDoc e )
473         {
474             if( logger.isErrorEnabled() )
475             {
476                 logger.error(e.getMessage());
477             }
478         }
479
480         if( logger.isDebugEnabled() )
481         {
482             logger.debug("findPOA: nothing found");
483         }
484         return null;
485     }
486
487
488     public ClientConnectionManager getClientConnectionManager()
489     {
490         return clientConnectionManager;
491     }
492
493     public GIOPConnectionManager getGIOPConnectionManager()
494     {
495         if (giop_connection_manager == null)
496         {
497             giop_connection_manager =
498                 new GIOPConnectionManager();
499             try
500             {
501                 giop_connection_manager.configure(configuration);
502             }
503             catch( ConfigurationException ce )
504             {
505                 throw new INTERNAL JavaDoc(ce.getMessage());
506             }
507         }
508         return giop_connection_manager;
509     }
510
511
512     /**
513      * Take a string rather then a Delegate object to prevent data race
514      * warning.
515      */

516     synchronized void _release( String JavaDoc iorString )
517     {
518         knownReferences.remove( iorString );
519     }
520
521
522     /**
523      * This method creates a policy with the given type and the given
524      * value.
525      *
526      * @param type The policies type.
527      * @param value The policies value.
528      * @exception org.omg.CORBA.PolicyError There is no PolicyFactory for the
529      * given type or the policy creation failed.
530      * @see org.omg.PortableInterceptor.PolicyFactory
531      */

532
533     public org.omg.CORBA.Policy JavaDoc create_policy( int type, org.omg.CORBA.Any JavaDoc value )
534         throws org.omg.CORBA.PolicyError JavaDoc
535     {
536         switch (type)
537         {
538             case MAX_HOPS_POLICY_TYPE.value:
539                 return new
540                     org.jacorb.orb.policies.MaxHopsPolicy (value);
541             case QUEUE_ORDER_POLICY_TYPE.value:
542                 return new
543                     org.jacorb.orb.policies.QueueOrderPolicy (value);
544             case REBIND_POLICY_TYPE.value:
545                 return new
546                     org.jacorb.orb.policies.RebindPolicy (value);
547             case RELATIVE_REQ_TIMEOUT_POLICY_TYPE.value:
548               return new
549                 org.jacorb.orb.policies.RelativeRequestTimeoutPolicy (value);
550             case RELATIVE_RT_TIMEOUT_POLICY_TYPE.value:
551               return new
552                 org.jacorb.orb.policies.RelativeRoundtripTimeoutPolicy (value);
553             case REPLY_END_TIME_POLICY_TYPE.value:
554                 return new
555                     org.jacorb.orb.policies.ReplyEndTimePolicy (value);
556             case REPLY_PRIORITY_POLICY_TYPE.value:
557                 return new
558                     org.jacorb.orb.policies.ReplyPriorityPolicy (value);
559             case REPLY_START_TIME_POLICY_TYPE.value:
560                 return new
561                     org.jacorb.orb.policies.ReplyStartTimePolicy (value);
562             case REQUEST_END_TIME_POLICY_TYPE.value:
563                 return new
564                     org.jacorb.orb.policies.RequestEndTimePolicy (value);
565             case REQUEST_PRIORITY_POLICY_TYPE.value:
566                 return new
567                     org.jacorb.orb.policies.RequestPriorityPolicy (value);
568             case REQUEST_START_TIME_POLICY_TYPE.value:
569                 return new
570                     org.jacorb.orb.policies.RequestStartTimePolicy (value);
571             case ROUTING_POLICY_TYPE.value:
572                 return new
573                     org.jacorb.orb.policies.RoutingPolicy (value);
574             case SYNC_SCOPE_POLICY_TYPE.value:
575                 return new
576                     org.jacorb.orb.policies.SyncScopePolicy (value);
577             default:
578                 Integer JavaDoc key = new Integer JavaDoc(type);
579                 if ( policy_factories == null ||
580                      (! policy_factories.containsKey(key)) )
581                     throw new org.omg.CORBA.PolicyError JavaDoc();
582                 PolicyFactory factory =
583                     (PolicyFactory)policy_factories.get(key);
584                 return factory.create_policy(type, value);
585         }
586     }
587
588
589     /**
590      * Tests if a policy factory is present for the given type.
591      */

592     public boolean hasPolicyFactoryForType(int type)
593     {
594         return (policy_factories != null &&
595                 policy_factories.containsKey( new Integer JavaDoc(type)) );
596     }
597
598     public org.omg.CORBA.ContextList JavaDoc create_context_list()
599     {
600         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc ();
601     }
602
603     public org.omg.CORBA.Environment JavaDoc create_environment()
604     {
605         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc ();
606     }
607
608     public org.omg.CORBA.portable.OutputStream JavaDoc create_output_stream()
609     {
610         return new CDROutputStream(this);
611     }
612
613     org.omg.IOP.IOR JavaDoc createIOR(String JavaDoc repId,
614                               byte[] objectKey,
615                               boolean _transient,
616                               org.jacorb.poa.POA poa,
617                               Map policy_overrides)
618     {
619         List profiles = new ArrayList();
620         Map componentMap = new HashMap();
621         int[] profileTags = new int[basicAdapter.getEndpointProfiles().size()];
622         int n = 0;
623         for (Iterator i = basicAdapter.getEndpointProfiles().iterator();
624              i.hasNext();)
625         {
626             Profile profile = (Profile)i.next();
627             profile.set_object_key (objectKey);
628             profiles.add (profile);
629             profileTags[n++] = profile.tag();
630
631             TaggedComponentList profileComponents = new TaggedComponentList();
632             profileComponents.addComponent(create_ORB_TYPE_ID());
633             componentMap.put(new Integer JavaDoc(profile.tag()), profileComponents);
634
635             if (profile instanceof IIOPProfile)
636             {
637                 // use proxy or ImR address if necessary
638
patchAddress((IIOPProfile)profile, repId, _transient);
639
640                 // patch primary address port to 0 if SSL is required
641
if (poa.isSSLRequired())
642                 {
643                     ((IIOPProfile)profile).patchPrimaryAddress(null, 0);
644             }
645         }
646
647         }
648
649         TaggedComponentList multipleComponents = new TaggedComponentList();
650         componentMap.put (new Integer JavaDoc (TAG_MULTIPLE_COMPONENTS.value),
651                           multipleComponents);
652
653         // invoke IOR interceptors
654
if ((interceptor_manager != null) &&
655             interceptor_manager.hasIORInterceptors())
656         {
657             IORInfoImpl info = new IORInfoImpl(this, poa,
658                                                componentMap,
659                                                policy_overrides,
660                                                profiles);
661             interceptor_manager.setProfileTags(profileTags);
662             try
663             {
664                 interceptor_manager.getIORIterator().iterate( info );
665             }
666             catch (Exception JavaDoc e)
667             {
668                 if (logger.isErrorEnabled())
669                     logger.error(e.getMessage());
670             }
671         }
672
673         // add GIOP 1.0 profile if necessary
674
IIOPProfile iiopProfile = findIIOPProfile(profiles);
675         if ( (iiopProfile != null)
676              && ( this.giopMinorVersion == 0 || this.giopAdd_1_0_Profiles ))
677             // && ( Environment.giopMinorVersion() == 0
678
// || Environment.giopAdd_1_0_Profiles()))
679
{
680             Profile profile_1_0 = iiopProfile.to_GIOP_1_0();
681             profiles.add(profile_1_0);
682
683             // shuffle all components over into the multiple components profile
684
TaggedComponentList iiopComponents =
685                 (TaggedComponentList)componentMap.get(new Integer JavaDoc(TAG_INTERNET_IOP.value));
686
687             multipleComponents.addAll(iiopProfile.getComponents());
688             multipleComponents.addAll(iiopComponents);
689
690             // if we only want GIOP 1.0, remove the other profile
691
if (giopMinorVersion == 0)
692             {
693                 profiles.remove(iiopProfile);
694             }
695         }
696
697         // marshal the profiles into the IOR and return
698
TaggedProfile[] tps = null;
699         if (multipleComponents.isEmpty())
700         {
701             tps = new TaggedProfile [profiles.size()];
702         }
703         else
704         {
705             tps = new TaggedProfile [profiles.size() + 1];
706             tps[tps.length-1] =
707                 createMultipleComponentsProfile(multipleComponents);
708         }
709
710         TaggedProfileHolder tp = new TaggedProfileHolder();
711         TaggedComponentSeqHolder tc = new TaggedComponentSeqHolder();
712         for (int i=0; i<profiles.size(); i++)
713         {
714             Profile p = (Profile)profiles.get(i);
715             TaggedComponentList c =
716                 (TaggedComponentList)componentMap.get (new Integer JavaDoc (p.tag()));
717             tc.value = c.asArray();
718             p.marshal (tp, tc);
719             tps[i] = tp.value;
720         }
721
722         return new IOR(repId, tps);
723     }
724
725     private TaggedProfile createMultipleComponentsProfile
726                                   (TaggedComponentList components)
727     {
728         CDROutputStream out = new CDROutputStream(this);
729         out.beginEncapsulatedArray();
730         MultipleComponentProfileHelper.write(out, components.asArray());
731         return new TaggedProfile
732         (
733             TAG_MULTIPLE_COMPONENTS.value,
734             out.getBufferCopy()
735         );
736     }
737
738     /**
739      * Finds the first IIOPProfile in the given List of Profiles,
740      * and returns it. If no such profile is found, this method
741      * returns null.
742      */

743     private IIOPProfile findIIOPProfile (List profiles)
744     {
745         for (Iterator i = profiles.iterator(); i.hasNext();)
746         {
747             Profile p = (Profile)i.next();
748             if (p instanceof IIOPProfile)
749                 return (IIOPProfile)p;
750         }
751         return null;
752     }
753
754     public org.omg.CORBA.Context JavaDoc get_default_context ()
755     {
756         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc ();
757     }
758
759
760     /**
761      * used from the POA
762      * @return the basic adapter used by this ORB instance
763      */

764     public org.jacorb.orb.BasicAdapter getBasicAdapter()
765     {
766         if( basicAdapter == null )
767             throw new INITIALIZE JavaDoc("Adapters not initialized; resolve RootPOA.");
768         return basicAdapter;
769     }
770
771
772     /**
773      * getPOACurrent
774      */

775
776     public org.jacorb.poa.Current getPOACurrent()
777     {
778         if (poaCurrent == null)
779         {
780             poaCurrent = org.jacorb.poa.Current._Current_init();
781         }
782         return poaCurrent;
783     }
784
785     /**
786      * called by POA to create an IOR
787      *
788      * @param poa the calling POA
789      * @param object_key
790      * @param rep_id
791      * @param _transient is the new reference transient or persistent
792      * @return a new CORBA Object reference
793      */

794     public org.omg.CORBA.Object JavaDoc getReference( org.jacorb.poa.POA poa,
795                                               byte[] object_key,
796                                               String JavaDoc rep_id,
797                                               boolean _transient )
798     {
799         if( rep_id == null )
800             rep_id = "IDL:omg.org/CORBA/Object:1.0";
801
802         org.omg.IOP.IOR JavaDoc ior =
803             createIOR( rep_id, object_key, _transient, poa, null );
804
805         if (ior == null)
806         {
807             if (logger.isErrorEnabled())
808                 logger.error("Interal error: createIOR returns null");
809         }
810
811         Delegate d = new Delegate( this, ior );
812         try
813         {
814             d.configure(configuration);
815         }
816         catch(ConfigurationException ce)
817         {
818             if (logger.isErrorEnabled())
819                 logger.error(ce.getMessage(), ce);
820         }
821         return d.getReference( poa );
822     }
823
824     public org.jacorb.poa.POA getRootPOA()
825         throws org.omg.CORBA.INITIALIZE JavaDoc
826     {
827         if( rootpoa == null )
828         {
829             rootpoa = org.jacorb.poa.POA._POA_init(this);
830
831             basicAdapter = new BasicAdapter( this,
832                                              rootpoa,
833                                              getTransportManager(),
834                                              getGIOPConnectionManager() );
835
836             try
837             {
838                 basicAdapter.configure(configuration);
839                 rootpoa.configure(configuration);
840             }
841             catch( ConfigurationException ce )
842             {
843                 throw new org.omg.CORBA.INITIALIZE JavaDoc("ConfigurationException: " +
844                                                    ce.getMessage() );
845             }
846             rootpoa._addPOAEventListener( this );
847
848         }
849         return rootpoa;
850     }
851
852     public String JavaDoc[] list_initial_services()
853     {
854         List l = new ArrayList();
855
856         for( Iterator e = initial_references.keySet().iterator();
857              e.hasNext(); l.add( e.next() ) );
858
859         String JavaDoc [] initial_services =
860             new String JavaDoc[ services.length + l.size()];
861
862         l.toArray( initial_services );
863
864         System.arraycopy( services, 0, initial_services, l.size(), services.length );
865         return initial_services;
866     }
867
868     /**
869      * An operation from the POAListener interface. Whenever a new POA is
870      * created, the ORB is notified.
871      */

872
873     public void poaCreated( org.jacorb.poa.POA poa )
874     {
875         /*
876          * Add this orb as the child poa's event listener. This means that the
877          * ORB is always a listener to all poa events!
878          */

879         poa._addPOAEventListener( this );
880
881         /* If the new POA has a persistent lifetime policy, it is registered
882          * with the implementation repository if there is one and the
883          * use_imr policy is set via the "jacorb.orb.use_imr" property
884          */

885
886         if( poa.isPersistent() )
887         {
888             persistentPOACount++;
889
890             getImR ();
891
892             if( imr != null )
893             {
894                 /* Register the POA */
895                 String JavaDoc server_name = implName;
896
897                 imr.registerPOA( server_name + "/" + poa._getQualifiedName(),
898                                  server_name, // logical server name
899
getServerAddress(),
900                                  getServerPort() );
901             }
902         }
903     }
904
905
906     private void getImR ()
907     {
908         /* Lookup the implementation repository */
909         if( imr == null && useIMR )
910         {
911             try
912             {
913                 imr = ImRAccessImpl.connect (this);
914             }
915             catch( Exception JavaDoc e )
916             {
917                 // If we failed to resolve the IMR set the reference to null.
918
if (logger.isWarnEnabled())
919                 {
920                     logger.warn("Error: No connection to ImplementationRepository");
921                 }
922                 if (logger.isDebugEnabled())
923                 {
924                     logger.debug(e.getMessage());
925                 }
926
927                 if( e instanceof org.omg.CORBA.INTERNAL JavaDoc )
928                 {
929                     throw new org.omg.CORBA.OBJ_ADAPTER JavaDoc ("Unable to resolve ImR");
930                 }
931                 else if (e instanceof org.omg.CORBA.TRANSIENT JavaDoc)
932                 {
933                     throw (org.omg.CORBA.TRANSIENT JavaDoc)e;
934                 }
935                 else
936                 {
937                     throw new org.omg.CORBA.OBJ_ADAPTER JavaDoc( e.toString() );
938                 }
939             }
940         }
941     }
942
943     /**
944      * Replace the server address in profile with a proxy address if necessary.
945      */

946     private void patchAddress(IIOPProfile profile,
947                               String JavaDoc repId,
948                               boolean _transient)
949     {
950         if (repId.equals ("IDL:org/jacorb/imr/ImplementationRepository:1.0"))
951         {
952             profile.patchPrimaryAddress(imrProxyHost,imrProxyPort);
953         }
954         else if (!_transient
955                  && useIMR
956                  && useIMREndpoint )
957         {
958             getImR();
959
960             // The double call to patchPrimaryAddress ensures that either the
961
// actual imr address or the environment values are patched into the
962
// address, giving precedence to the latter.
963
profile.patchPrimaryAddress(imr.getImRHost(), imr.getImRPort());
964             profile.patchPrimaryAddress(imrProxyHost, imrProxyPort);
965         }
966         else
967         {
968             profile.patchPrimaryAddress(iorProxyHost, iorProxyPort);
969         }
970     }
971
972     /**
973      * Creates an ORB_TYPE_ID tagged component for JacORB.
974      */

975     private TaggedComponent create_ORB_TYPE_ID()
976     {
977         CDROutputStream orbIDComponentDataStream = new CDROutputStream( this );
978         orbIDComponentDataStream.beginEncapsulatedArray();
979         orbIDComponentDataStream.write_long( ORBConstants.JACORB_ORB_ID );
980
981         return new TaggedComponent
982         (
983             TAG_ORB_TYPE.value,
984             orbIDComponentDataStream.getBufferCopy()
985         );
986     }
987
988
989     /**
990      * <code>getServerAddress</code> returns the address to use to locate the
991      * server. Note that this address will be overwritten by the ImR address in
992      * the IOR of persistent servers if the use_imr and use_imr_endpoint
993      * properties are switched on
994      *
995      * @return a <code>String</code>, the address for the server.
996      */

997     private String JavaDoc getServerAddress()
998     {
999         String JavaDoc address = iorProxyHost;
1000
1001        if( address == null )
1002        {
1003            //property not set
1004
address = getBasicAdapter().getAddress();
1005        }
1006        else
1007        {
1008            if (logger.isInfoEnabled())
1009            {
1010                logger.info("Using proxy host " + address + " in IOR" );
1011            }
1012        }
1013
1014        return address;
1015    }
1016
1017
1018    /**
1019     * <code>getServerPort</code> returns the port to use to locate the server.
1020     * Note that this port will be overwritten by the ImR port in the IOR of
1021     * persistent servers if the use_imr and use_imr_endpoint properties are
1022     * switched on.
1023     *
1024     * @return an <code>int</code>, the port for the server.
1025     */

1026    private int getServerPort()
1027    {
1028        int port = -1;
1029
1030        if( iorProxyPort != -1 )
1031        {
1032            port = iorProxyPort;
1033
1034            if( port < 0 )
1035            {
1036                throw new BAD_QOS JavaDoc( "Negative port numbers are not allowed! " +
1037                                   "(check property \"jacorb.ior_proxy_port\")" );
1038            }
1039
1040            if (logger.isInfoEnabled())
1041            {
1042                logger.info("Using proxy port " + port + " in IOR" );
1043            }
1044        }
1045        else
1046        {
1047            //property not set
1048
port = getBasicAdapter().getPort();
1049        }
1050
1051        return port;
1052    }
1053
1054    /**
1055     * Method to check if a Proxy host is configured for the IMR via the
1056     * <code>jacorb.imr.ior_proxy_host</code> property.
1057     * @param imrAddress The actual host name or IP of the IMR.
1058     * @return The proxy host value, if configured, else the supplied actual host.
1059     */

1060    private String JavaDoc getIMRAddressForIOR(String JavaDoc imrAddress)
1061    {
1062        return (imrProxyHost == null ? imrAddress : imrProxyHost);
1063    }
1064
1065    /**
1066     * Method to check if a Proxy port is configured for the IMR via the
1067     * <code>jacorb.imr.ior_proxy_port</code> property.
1068     * @param imrPort The port number that the IMR is really running on.
1069     * @return The proxy port number, if configured, else the supplied actual port.
1070     */

1071    private int getIMRPortForIOR(int imrPort)
1072    {
1073        return imrProxyPort;
1074    }
1075
1076    public void poaStateChanged(org.jacorb.poa.POA poa, int new_state)
1077    {
1078        if( ( new_state == org.jacorb.poa.POAConstants.DESTROYED ||
1079              new_state == org.jacorb.poa.POAConstants.INACTIVE ) &&
1080            poa.isPersistent() && imr != null
1081            )
1082        {
1083            /* if all persistent POAs in this server have gone down, unregister
1084               the server */

1085            if( --persistentPOACount == 0 )
1086            {
1087                imr.setServerDown(implName);
1088            }
1089        }
1090    }
1091
1092
1093    public void referenceCreated(org.omg.CORBA.Object JavaDoc o) {}
1094
1095    public boolean get_service_information( short service_type,
1096                                            org.omg.CORBA.ServiceInformationHolder JavaDoc service_information)
1097    {
1098        // if (( service_type == org.omg.CORBA.Security.value ) && Environment.supportSSL ())
1099
// {
1100
// byte options[] = new byte [5]; // ServiceOption[]
1101
// options[0] = (byte)org.omg.Security.SecurityLevel1.value;
1102
// options[1] = (byte)org.omg.Security.SecurityLevel2.value;
1103
// options[2] = (byte)org.omg.Security.ReplaceORBServices.value;
1104
// options[3] = (byte)org.omg.Security.ReplaceSecurityServices.value;
1105
// options[4] = (byte)org.omg.Security.CommonInteroperabilityLevel0.value;
1106
// org.omg.CORBA.ServiceDetail details[] = new org.omg.CORBA.ServiceDetail [2];
1107
// details[0].service_detail_type = org.omg.Security.SecureTransportType.value;
1108
// details[0].service_detail = org.jacorb.security.ssl.SSLSetup.getMechanismType().getBytes();
1109
// details[1].service_detail_type = org.omg.Security.SecureTransportType.value;
1110
// details[1].service_detail = "001010011".getBytes(); // AuditId, _PublicId, AccessId
1111
// return true;
1112
// }
1113
// else return false;
1114
throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc ();
1115    }
1116
1117    /**
1118     * resolve_initial_references
1119     */

1120
1121    public org.omg.CORBA.Object JavaDoc resolve_initial_references(String JavaDoc identifier)
1122        throws org.omg.CORBA.ORBPackage.InvalidName JavaDoc
1123    {
1124        if ( initial_references.containsKey(identifier) )
1125        {
1126            return (org.omg.CORBA.Object JavaDoc)initial_references.get(identifier);
1127        }
1128        else
1129        {
1130            org.omg.CORBA.Object JavaDoc obj = null;
1131            String JavaDoc url = null;
1132
1133            try
1134            {
1135                url =
1136                    configuration.getAttribute("ORBInitRef." + identifier);
1137            }
1138            catch( Exception JavaDoc e )
1139            {
1140                // ignore
1141
}
1142
1143            if( url != null )
1144            {
1145                try
1146                {
1147                    obj = this.string_to_object( url );
1148                }
1149                catch( Exception JavaDoc e )
1150                {
1151                    if (logger.isErrorEnabled())
1152                    {
1153                        logger.error( "Could not create initial reference for \"" +
1154                                      identifier + "\"\n" +
1155                                      "Please check property \"ORBInitRef." +
1156                                      identifier + '\"' );
1157                    }
1158                    if (logger.isDebugEnabled())
1159                    {
1160                        logger.debug( e.getMessage() );
1161                    }
1162
1163                    throw new org.omg.CORBA.ORBPackage.InvalidName JavaDoc();
1164                }
1165            }
1166            else if( identifier.equals("RootPOA") )
1167            {
1168                return (org.omg.CORBA.Object JavaDoc)getRootPOA();
1169            }
1170            else if( identifier.equals("POACurrent") )
1171            {
1172                return (org.omg.CORBA.Object JavaDoc)getPOACurrent();
1173            }
1174            else if( identifier.equals("SecurityCurrent") )
1175            {
1176                if( securityCurrent == null )
1177                {
1178                    try
1179                    {
1180                        Class JavaDoc currentClass =
1181                            ObjectUtil.classForName( "org.jacorb.security.level2.CurrentImpl" );
1182
1183                        Constructor constr =
1184                            currentClass.getConstructor( new Class JavaDoc[]{ org.omg.CORBA.ORB JavaDoc.class });
1185
1186                        securityCurrent =
1187                            (org.omg.SecurityLevel2.Current)constr.newInstance( new Object JavaDoc[]{ this });
1188
1189                        Method configureMethod =
1190                            currentClass.getDeclaredMethod( "configure",
1191                                                            new Class JavaDoc[]{ Configuration.class } );
1192
1193                        configureMethod.invoke( securityCurrent, new Object JavaDoc[]{ configuration });
1194
1195                        Method init =
1196                            currentClass.getDeclaredMethod( "init", new Class JavaDoc[0] );
1197
1198                        init.invoke( securityCurrent, new Object JavaDoc[0] );
1199                    }
1200                    catch (Exception JavaDoc e)
1201                    {
1202                        if (logger.isWarnEnabled())
1203                        {
1204                            logger.warn("Exception",e);
1205                        }
1206                    }
1207                }
1208
1209                obj = securityCurrent;
1210            }
1211            else if( identifier.equals("DynAnyFactory") )
1212            {
1213                obj = new org.jacorb.orb.dynany.DynAnyFactoryImpl( this );
1214            }
1215            else if( identifier.equals("PICurrent") )
1216            {
1217                return piCurrent;
1218            }
1219            else if( identifier.equals("ORBPolicyManager") )
1220            {
1221                return getPolicyManager();
1222            }
1223            else if( identifier.equals("CodecFactory") )
1224            {
1225                obj = new CodecFactoryImpl(this);
1226            }
1227            else
1228            {
1229                throw new org.omg.CORBA.ORBPackage.InvalidName JavaDoc();
1230            }
1231
1232            if (obj != null)
1233            {
1234                initial_references.put (identifier, obj);
1235            }
1236
1237            return obj;
1238        }
1239    }
1240
1241    PolicyManager getPolicyManager()
1242    {
1243        return policyManager;
1244    }
1245
1246    /**
1247     * Register a reference, that will be returned on subsequent calls
1248     * to resove_initial_references(id). <br>
1249     * The references "RootPOA", "POACurrent" and "PICurrent" can be set,
1250     * but will not be resolved with the passed in references.
1251     * <p>
1252     * Overrides register_initial_reference() in org.omg.CORBA_2_5.ORB
1253     *
1254     * @param id The references human-readable id, e.g. "MyService".
1255     * @param obj The objects reference.
1256     * @exception InvalidName A reference with id has already been registered.
1257     */

1258
1259    public void register_initial_reference( String JavaDoc id, org.omg.CORBA.Object JavaDoc obj )
1260        throws InvalidName JavaDoc
1261    {
1262        if (id == null || id.length() == 0 ||
1263            initial_references.containsKey(id) )
1264        {
1265            throw new InvalidName JavaDoc();
1266        }
1267        else
1268        {
1269            if (logger.isDebugEnabled())
1270            {
1271                logger.debug( "Registering initial ref " + id );
1272            }
1273            initial_references.put(id, obj);
1274        }
1275    }
1276
1277    public void run()
1278    {
1279        if (logger.isInfoEnabled())
1280        {
1281            logger.info("ORB run");
1282        }
1283
1284        try
1285        {
1286            synchronized( orb_synch )
1287            {
1288                while( run )
1289                {
1290                    orb_synch.wait();
1291                }
1292            }
1293        }
1294        catch (InterruptedException JavaDoc ex)
1295        {
1296        }
1297        if (logger.isInfoEnabled())
1298        {
1299            logger.info("ORB run, exit");
1300        }
1301    }
1302
1303
1304    public void send_multiple_requests_oneway( org.omg.CORBA.Request JavaDoc[] req )
1305    {
1306        for( int i = 0; i < req.length; i++ )
1307        {
1308            req[i].send_oneway();
1309        }
1310    }
1311
1312    public void send_multiple_requests_deferred( org.omg.CORBA.Request JavaDoc[] req )
1313    {
1314        for( int i = 0; i < req.length; i++ )
1315        {
1316            req[i].send_deferred();
1317        }
1318    }
1319
1320    public boolean poll_next_response()
1321    {
1322        if( requests.size () == 0 )
1323        {
1324            throw new org.omg.CORBA.BAD_INV_ORDER JavaDoc
1325                ( 11, org.omg.CORBA.CompletionStatus.COMPLETED_NO );
1326        }
1327
1328        synchronized( requests )
1329        {
1330            Request req;
1331            Iterator iter = requests.iterator();
1332            while( iter.hasNext() )
1333            {
1334                req = (Request)iter.next();
1335                if( req.poll_response() )
1336                {
1337                    request = req;
1338                    return true;
1339                }
1340            }
1341        }
1342        return false;
1343    }
1344
1345    public org.omg.CORBA.Request JavaDoc get_next_response ()
1346    {
1347        if( requests.size () == 0 )
1348        {
1349            throw new org.omg.CORBA.BAD_INV_ORDER JavaDoc
1350                ( 11, org.omg.CORBA.CompletionStatus.COMPLETED_NO );
1351        }
1352
1353        synchronized( requests )
1354        {
1355            Request req = null;
1356            if( request != null )
1357            {
1358                request.get_response();
1359                req = request;
1360                request = null;
1361                return req;
1362            }
1363
1364            Iterator iter;
1365            while( true )
1366            {
1367                iter = requests.iterator();
1368                while( iter.hasNext() )
1369                {
1370                    req = (Request)iter.next();
1371                    if( req.poll_response() )
1372                    {
1373                        req.get_response();
1374                        return req;
1375                    }
1376                }
1377            }
1378        }
1379    }
1380
1381    public void addRequest( org.omg.CORBA.Request JavaDoc req )
1382    {
1383        requests.add( req );
1384    }
1385
1386    public void removeRequest( org.omg.CORBA.Request JavaDoc req )
1387    {
1388        requests.remove( req );
1389    }
1390
1391
1392    /**
1393     * called from ORB.init(), entry point for initialization.
1394     */

1395
1396    protected void set_parameters(String JavaDoc[] args, java.util.Properties JavaDoc props)
1397    {
1398        _props = props;
1399
1400        try
1401        {
1402            configure( org.jacorb.config.Configuration.getConfiguration(props,
1403                                                                        this,
1404                                                                        false)); // no applet support
1405
}
1406        catch( ConfigurationException ce )
1407        {
1408            if ( logger != null && logger.isErrorEnabled())
1409            {
1410                logger.error( ce.getMessage());
1411            }
1412            else
1413                ce.printStackTrace();
1414
1415            throw new org.omg.CORBA.INITIALIZE JavaDoc( ce.getMessage() );
1416        }
1417
1418        /*
1419         * find -ORBInitRef args and add them to Environment
1420         * (overwriting existing props).
1421         */

1422
1423        if( args != null )
1424        {
1425            _args = args;
1426            for( int i = 0; i < args.length; i++ )
1427            {
1428                String JavaDoc arg = args[ i ].trim();
1429
1430                if( arg.startsWith( "-ORBInitRef." ))
1431                {
1432                    //This is the wrong jacorb form -ORBInitRef.<name>=<val>
1433

1434                    //get rid of the leading `-'
1435
String JavaDoc prop = arg.substring( 1 );
1436
1437                    //find the equals char that separates prop name from
1438
//prop value
1439
int equals_pos = prop.indexOf( '=' );
1440                    if ( equals_pos == -1 )
1441                    {
1442                        throw new org.omg.CORBA.BAD_PARAM JavaDoc( "InitRef format invalid for " + prop );
1443                    }
1444
1445                    //add the property to environment
1446
((DefaultConfiguration)configuration).setAttribute( prop.substring( 0, equals_pos ),
1447                                                                        prop.substring( equals_pos + 1) );
1448                }
1449                else if( arg.equals( "-ORBInitRef" ))
1450                {
1451                    //This is the compliant form -ORBInitRef <name>=<val>
1452

1453                    //Is there a next arg?
1454
if( (args.length - 1) < (i + 1) )
1455                    {
1456                        if (logger.isWarnEnabled())
1457                        {
1458                            logger.warn( "WARNING: -ORBInitRef argument without value" );
1459                        }
1460                        continue;
1461                    }
1462
1463                    String JavaDoc prop = args[ ++i ].trim();
1464
1465                    //find the equals char that separates prop name from
1466
//prop value
1467
int equals_pos = prop.indexOf( '=' );
1468                    if ( equals_pos == -1 )
1469                    {
1470                        throw new org.omg.CORBA.BAD_PARAM JavaDoc( "InitRef format invalid for " + prop );
1471                    }
1472
1473                    //add the property to environment
1474
((DefaultConfiguration)configuration).setAttribute( "ORBInitRef." +
1475                                                                         prop.substring( 0, equals_pos ),
1476                                                                         prop.substring( equals_pos + 1) );
1477                }
1478            }
1479        }
1480
1481        internalInit();
1482    }
1483
1484    /**
1485     * Initialization method, called from within the super class
1486     * org.omg.CORBA.ORB
1487     */

1488
1489    protected void set_parameters(java.applet.Applet JavaDoc app,
1490                                  java.util.Properties JavaDoc props)
1491    {
1492        _props = props;
1493
1494        try
1495        {
1496            configure( org.jacorb.config.Configuration.getConfiguration(props,
1497                                                                        this,
1498                                                                        true)); //applet support
1499
}
1500        catch( ConfigurationException ce )
1501        {
1502            if (logger.isErrorEnabled())
1503            {
1504                logger.error( ce.getMessage());
1505            }
1506            throw new org.omg.CORBA.INITIALIZE JavaDoc( ce.getMessage() );
1507        }
1508
1509        internalInit();
1510    }
1511
1512    private void internalInit()
1513    {
1514        policyManager = new PolicyManager( this );
1515
1516        try
1517        {
1518            clientConnectionManager =
1519                new ClientConnectionManager( this,
1520                                             getTransportManager(),
1521                                             getGIOPConnectionManager());
1522            clientConnectionManager.configure(configuration);
1523        }
1524        catch( ConfigurationException ce )
1525        {
1526            if (logger.isErrorEnabled())
1527                logger.error(ce.getMessage());
1528        }
1529
1530
1531        //String s = Environment.getProperty( "jacorb.hashtable_class" );
1532
if( hashTableClassName == null || hashTableClassName.length() == 0 )
1533        {
1534            if (logger.isInfoEnabled())
1535            {
1536                logger.info("Property \"jacorb.hashtable_class\" not present. Will use default hashtable implementation" );
1537            }
1538            knownReferences = new HashMap();
1539        }
1540        else
1541        {
1542            try
1543            {
1544                knownReferences =
1545                    (Map)ObjectUtil.classForName( hashTableClassName ).newInstance();
1546            }
1547            catch( Exception JavaDoc e )
1548            {
1549                if (logger.isInfoEnabled())
1550                {
1551                    logger.info(e.getMessage());
1552                }
1553                knownReferences = new HashMap();
1554            }
1555        }
1556
1557        interceptorInit();
1558    }
1559    /**
1560     * This method retrieves the ORBInitializer-Names from the Environment,
1561     * and runs them.
1562     */

1563
1564    private void interceptorInit()
1565    {
1566        Vector orb_initializers = getORBInitializers();
1567
1568        if (orb_initializers.size () > 0)
1569        {
1570            ORBInitInfoImpl info = new ORBInitInfoImpl (this);
1571            ORBInitializer init;
1572
1573            // call pre_init in ORBInitializers
1574
for (int i = 0; i < orb_initializers.size(); i++)
1575            {
1576                try
1577                {
1578                    init = (ORBInitializer) orb_initializers.elementAt (i);
1579                    init.pre_init (info);
1580                }
1581                catch (Exception JavaDoc e)
1582                {
1583                    if (logger.isWarnEnabled())
1584                    {
1585                        logger.warn( e.getMessage());
1586                    }
1587                }
1588            }
1589
1590            //call post_init on ORBInitializers
1591
for (int i = 0; i < orb_initializers.size (); i++)
1592            {
1593                try
1594                {
1595                    init = (ORBInitializer) orb_initializers.elementAt (i);
1596                    init.post_init (info);
1597                }
1598                catch (Exception JavaDoc e)
1599                {
1600                    if (logger.isWarnEnabled())
1601                    {
1602                        logger.warn( e.getMessage());
1603                    }
1604                }
1605            }
1606
1607            //allow no more access to ORBInitInfo from ORBInitializers
1608
info.setInvalid ();
1609
1610            Vector client_interceptors = info.getClientInterceptors ();
1611            Vector server_interceptors = info.getServerInterceptors ();
1612            Vector ior_intercept = info.getIORInterceptors ();
1613
1614            hasClientInterceptors = (client_interceptors.size () > 0);
1615            hasServerInterceptors = (server_interceptors.size () > 0);
1616
1617            if (hasClientInterceptors || hasServerInterceptors || (ior_intercept.size () > 0))
1618            {
1619                interceptor_manager = new InterceptorManager
1620                (
1621                    client_interceptors,
1622                    server_interceptors,
1623                    ior_intercept,
1624                    info.getSlotCount (),
1625                    this
1626                );
1627            }
1628
1629            // add PolicyFactories to ORB
1630
policy_factories = info.getPolicyFactories();
1631        }
1632    }
1633
1634
1635    /**
1636     * Collects all properties with prefix "org.omg.PortableInterceptor.ORBInitializerClass."
1637     * and try to instantiate their values as ORBInitializer-Classes.
1638     *
1639     * @return a Vector containing ORBInitializer instances
1640     */

1641
1642    private Vector getORBInitializers()
1643    {
1644        String JavaDoc[] prop_names = configuration.getAttributeNames();
1645        Vector orb_initializers = new Vector();
1646
1647        String JavaDoc initializer_prefix =
1648            "org.omg.PortableInterceptor.ORBInitializerClass.";
1649
1650        //Test EVERY property if prefix matches.
1651
for(int i = 0; i < prop_names.length; i++)
1652        {
1653            if ( prop_names[i].startsWith( initializer_prefix ))
1654            {
1655                String JavaDoc name = null;
1656// try
1657
// {
1658
name = configuration.getAttribute( prop_names[i], "" );
1659 // }
1660
// catch( ConfigurationException ce )
1661
// {
1662
// ce.printStackTrace(); // debug
1663
// }
1664

1665                if( name.length() == 0 )
1666                {
1667                    if( prop_names[i].length() > initializer_prefix.length() )
1668                    {
1669                        name =
1670                            prop_names[i].substring( initializer_prefix.length() );
1671                    }
1672                }
1673
1674                if( name == null )
1675                {
1676                    continue;
1677                }
1678
1679                try
1680                {
1681                    orb_initializers.addElement(ObjectUtil.classForName(name).newInstance());
1682                    if( logger.isDebugEnabled())
1683                        logger.debug("Build: " + name);
1684                }
1685                catch (Exception JavaDoc e)
1686                {
1687                    if( logger.isDebugEnabled())
1688                        logger.debug( "Unable to build ORBInitializer from >>" +
1689                                      name + "<<" );
1690                }
1691            }
1692        }
1693
1694        return orb_initializers;
1695    }
1696
1697
1698
1699
1700    public void shutdown( boolean wait_for_completion )
1701    {
1702        if (logger.isInfoEnabled())
1703        {
1704            logger.info("prepare ORB for shutdown...");
1705        }
1706
1707        if( ! run )
1708        {
1709            return; // ORB already shut down...
1710
}
1711
1712        synchronized( shutdown_synch )
1713        {
1714            if (logger.isInfoEnabled())
1715            {
1716                logger.info("ORB going down...");
1717            }
1718
1719            if( shutdown_in_progress && wait_for_completion )
1720            {
1721                synchronized( shutdown_synch )
1722                {
1723                    try
1724                    {
1725                        shutdown_synch.wait();
1726                    }
1727                    catch( InterruptedException JavaDoc ie )
1728                    {}
1729
1730                    if (logger.isDebugEnabled())
1731                    {
1732                        logger.debug("ORB going shutdown complete (1)");
1733                    }
1734
1735                    return;
1736                }
1737            }
1738            else if( shutdown_in_progress && !wait_for_completion )
1739            {
1740                if (logger.isDebugEnabled())
1741                {
1742                    logger.debug("ORB going shutdown complete (2)");
1743                }
1744                return;
1745            }
1746
1747            shutdown_in_progress = true;
1748        }
1749
1750        if( rootpoa != null )
1751            rootpoa.destroy(true, wait_for_completion);
1752
1753        if( basicAdapter != null )
1754        {
1755            basicAdapter.stopListeners();
1756        }
1757
1758        if (logger.isDebugEnabled())
1759        {
1760            logger.debug("ORB going shutdown (cleaning up ORB...)");
1761        }
1762
1763        clientConnectionManager.shutdown();
1764        knownReferences.clear();
1765        bufferManager.release();
1766
1767        /* notify all threads waiting for shutdown to complete */
1768
1769        synchronized( shutdown_synch )
1770        {
1771            shutdown_synch.notifyAll();
1772        }
1773
1774        /* notify all threads waiting in orb.run() */
1775        synchronized( orb_synch )
1776        {
1777            run = false;
1778            orb_synch.notifyAll();
1779        }
1780        if (logger.isInfoEnabled())
1781        {
1782            logger.info("ORB shutdown complete");
1783        }
1784    }
1785
1786    public void destroy()
1787    {
1788        if( destroyed )
1789            throw new org.omg.CORBA.OBJECT_NOT_EXIST JavaDoc();
1790
1791        if( run )
1792        {
1793            shutdown( true );
1794        }
1795
1796        if( interceptor_manager != null )
1797        {
1798            interceptor_manager.destroy();
1799        }
1800
1801        // other clean up possible here ?
1802
destroyed = true;
1803    }
1804
1805    public org.omg.CORBA.Object JavaDoc string_to_object (String JavaDoc str)
1806    {
1807        if (str == null)
1808        {
1809            return null;
1810        }
1811
1812        try
1813        {
1814            ParsedIOR pior = new ParsedIOR( str, this, logger );
1815            if( pior.isNull() )
1816            {
1817                return null;
1818            }
1819            else
1820            {
1821                return _getObject(pior);
1822            }
1823        }
1824        catch (IllegalArgumentException JavaDoc iae)
1825        {
1826            if (logger.isDebugEnabled())
1827            {
1828                logger.debug(iae.getMessage());
1829            }
1830            return null;
1831        }
1832    }
1833
1834    /**
1835     * always return a ValueDef or throw BAD_PARAM if not repid of a value
1836     */

1837
1838    public org.omg.CORBA.Object JavaDoc get_value_def(String JavaDoc repid)
1839        throws org.omg.CORBA.BAD_PARAM JavaDoc
1840    {
1841        throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
1842    }
1843
1844    /**
1845     * called by org.jacorb.poa.RequestProcessor
1846     */

1847
1848    public void set_delegate( java.lang.Object JavaDoc wrapper )
1849    {
1850        if( ! (wrapper instanceof org.omg.PortableServer.Servant JavaDoc) )
1851            throw new org.omg.CORBA.BAD_PARAM JavaDoc("Argument must be of type org.omg.PortableServer.Servant");
1852        else
1853        {
1854            try
1855            {
1856                ((org.omg.PortableServer.Servant JavaDoc)wrapper)._get_delegate();
1857            }
1858            catch( org.omg.CORBA.BAD_INV_ORDER JavaDoc bio )
1859            {
1860                // only set the delegate if it has not been set already
1861
org.jacorb.orb.ServantDelegate delegate =
1862                    new org.jacorb.orb.ServantDelegate( this );
1863                ((org.omg.PortableServer.Servant JavaDoc)wrapper)._set_delegate(delegate);
1864            }
1865        }
1866    }
1867
1868
1869    public String JavaDoc object_to_string( org.omg.CORBA.Object JavaDoc obj)
1870    {
1871        if (obj == null)
1872        {
1873            return nullIORString;
1874        }
1875
1876        if (obj instanceof org.omg.CORBA.LocalObject JavaDoc)
1877        {
1878           throw new org.omg.CORBA.MARSHAL JavaDoc ("Attempt to stringify a local object");
1879        }
1880
1881        Object JavaDoc delegate =
1882            ((org.omg.CORBA.portable.ObjectImpl JavaDoc)obj)._get_delegate();
1883        if (delegate instanceof org.jacorb.orb.Delegate)
1884            return delegate.toString();
1885        else
1886            throw new BAD_PARAM JavaDoc("Argument has a delegate whose class is "
1887                                + delegate.getClass().getName()
1888                                + ", a org.jacorb.orb.Delegate was expected");
1889    }
1890
1891    public void perform_work ()
1892    {
1893        if (! run)
1894        {
1895            throw new org.omg.CORBA.BAD_INV_ORDER JavaDoc
1896                (4, org.omg.CORBA.CompletionStatus.COMPLETED_NO);
1897        }
1898    }
1899
1900    public boolean work_pending ()
1901    {
1902        if (! run)
1903        {
1904            throw new org.omg.CORBA.BAD_INV_ORDER JavaDoc
1905                (4, org.omg.CORBA.CompletionStatus.COMPLETED_NO);
1906        }
1907
1908        return false;
1909    }
1910
1911    public ValueFactory JavaDoc register_value_factory(String JavaDoc id,
1912                                                ValueFactory JavaDoc factory)
1913    {
1914        return (ValueFactory JavaDoc)valueFactories.put (id, factory);
1915    }
1916
1917    public void unregister_value_factory(String JavaDoc id)
1918    {
1919        valueFactories.remove (id);
1920    }
1921
1922    public ValueFactory JavaDoc lookup_value_factory(String JavaDoc id)
1923    {
1924        ValueFactory JavaDoc result = (ValueFactory JavaDoc)valueFactories.get (id);
1925
1926        if (result == null)
1927        {
1928            if (id.startsWith("IDL"))
1929            {
1930                String JavaDoc valueName = org.jacorb.ir.RepositoryID.className(id, null);
1931                result = findValueFactory(valueName);
1932                valueFactories.put(id, result);
1933            }
1934        }
1935        return result;
1936    }
1937
1938    /**
1939     * Finds a ValueFactory for class valueName by trying standard class names.
1940     */

1941
1942    private ValueFactory JavaDoc findValueFactory(String JavaDoc valueName)
1943    {
1944        Class JavaDoc result = null;
1945        result = findClass (valueName + "DefaultFactory", true);
1946        if (result != null)
1947        {
1948            return (ValueFactory JavaDoc)instantiate (result);
1949        }
1950        else
1951        {
1952            // Extension of the standard: Handle the common case
1953
// when the Impl class is its own factory...
1954
Class JavaDoc c = findClass (valueName, false);
1955            result = findClass (valueName + "Impl", false);
1956
1957            if (result != null && c.isAssignableFrom (result))
1958            {
1959                if (ValueFactory JavaDoc.class.isAssignableFrom (result))
1960                {
1961                    return (ValueFactory JavaDoc)instantiate (result);
1962                }
1963                else
1964                {
1965                    // ... or create a factory on the fly
1966
return new JacORBValueFactory (result);
1967                }
1968            }
1969            else
1970                return null;
1971        }
1972    }
1973
1974    /**
1975     * Internal value factory class. This can be used for any value
1976     * implementation that has a no-arg constructor.
1977     */

1978    private class JacORBValueFactory
1979        implements org.omg.CORBA.portable.ValueFactory JavaDoc
1980    {
1981        private Class JavaDoc implementationClass;
1982
1983        public JacORBValueFactory (Class JavaDoc c)
1984        {
1985            implementationClass = c;
1986        }
1987
1988        public java.io.Serializable JavaDoc read_value
1989          (org.omg.CORBA_2_3.portable.InputStream JavaDoc is)
1990        {
1991            StreamableValue JavaDoc value =
1992                (StreamableValue JavaDoc)instantiate (implementationClass);
1993            return is.read_value(value);
1994        }
1995
1996    }
1997
1998    /**
1999     * Returns the class object for `name', if it exists, otherwise
2000     * returns null. If `orgomg' is true, and `name' starts with "org.omg",
2001     * do a double-take using "omg.org" as the prefix.
2002     */

2003    private Class JavaDoc findClass (String JavaDoc name, boolean orgomg)
2004    {
2005        Class JavaDoc result = null;
2006        try
2007        {
2008            result = ObjectUtil.classForName(name);
2009        }
2010        catch (ClassNotFoundException JavaDoc e)
2011        {
2012            if (orgomg && name.startsWith ("org.omg"))
2013                try
2014                {
2015                    result = ObjectUtil.classForName("omg.org" + name.substring(7));
2016                }
2017                catch (ClassNotFoundException JavaDoc x)
2018                {
2019                    // nothing, result is null
2020
}
2021        }
2022        return result;
2023    }
2024
2025    /**
2026     * Instantiates class `c' using its no-arg constructor. Throws a
2027     * run-time exception if that fails.
2028     */

2029    private Object JavaDoc instantiate (Class JavaDoc c)
2030    {
2031        try
2032        {
2033            return c.newInstance();
2034        }
2035        catch (IllegalAccessException JavaDoc e1)
2036        {
2037            throw new RuntimeException JavaDoc ("cannot instantiate class "
2038                                        + c.getName()
2039                                        + " (IllegalAccessException)");
2040        }
2041        catch (InstantiationException JavaDoc e2)
2042        {
2043            throw new RuntimeException JavaDoc ("cannot instantiate class "
2044                                        + c.getName()
2045                                        + " (InstantiationException)");
2046        }
2047    }
2048
2049    /**
2050     * Returns a BoxedValueHelper for the type specified by repId, or
2051     * null if no such BoxedValueHelper can be found. This method uses an
2052     * internal cache of BoxedValueHelpers so that each class needs only
2053     * be looked up once.
2054     *
2055     * @param repId the repository id of the type for which a BoxedValueHelper
2056     * should be returned. It is assumed that repId is the repository id of a
2057     * boxed value type. Otherwise, the result will be null.
2058     * @return an instance of the BoxedValueHelper class that corresponds
2059     * to repId.
2060     */

2061
2062    public BoxedValueHelper JavaDoc getBoxedValueHelper(String JavaDoc repId)
2063    {
2064        BoxedValueHelper JavaDoc result = (BoxedValueHelper JavaDoc)boxedValueHelpers.get(repId);
2065        if (result == null)
2066        {
2067            if (boxedValueHelpers.containsKey(repId))
2068                return null;
2069            else
2070            {
2071                result = org.jacorb.ir.RepositoryID.createBoxedValueHelper(repId, null);
2072                boxedValueHelpers.put(repId, result);
2073            }
2074        }
2075        return result;
2076    }
2077
2078    /**
2079     * Test, if the ORB has ClientRequestInterceptors <br>
2080     * Called by Delegate.
2081     */

2082
2083    public boolean hasClientRequestInterceptors ()
2084    {
2085        return hasClientInterceptors;
2086    }
2087
2088    /**
2089     * Test, if the ORB has ServerRequestInterceptors <br>
2090     * Called by poa.RequestProcessor.
2091     */

2092
2093    public boolean hasServerRequestInterceptors ()
2094    {
2095        return hasServerInterceptors;
2096    }
2097
2098    /**
2099     * Test, if the ORB has client or server side interceptors.
2100     */

2101
2102    public boolean hasRequestInterceptors ()
2103    {
2104        return (hasServerInterceptors || hasClientInterceptors);
2105    }
2106
2107    /**
2108     * Get the InterceptorManager, if present.
2109     *
2110     * @return the InterceptorManager, or null, if none is present.
2111     */

2112
2113    public org.jacorb.orb.portableInterceptor.InterceptorManager getInterceptorManager()
2114    {
2115        return interceptor_manager;
2116    }
2117
2118    public TransportManager getTransportManager()
2119    {
2120        if (transport_manager == null)
2121        {
2122            transport_manager = new TransportManager(this);
2123            try
2124            {
2125                transport_manager.configure(configuration);
2126            }
2127            catch( ConfigurationException ce )
2128            {
2129                throw new INTERNAL JavaDoc(ce.getMessage());
2130            }
2131        }
2132        return transport_manager;
2133    }
2134
2135    /* DII helper methods */
2136
2137    public org.omg.CORBA.ExceptionList JavaDoc create_exception_list ()
2138    {
2139        return new org.jacorb.orb.dii.ExceptionList ();
2140    }
2141
2142    public org.omg.CORBA.NVList JavaDoc create_list (int count)
2143    {
2144        return new org.jacorb.orb.NVList (this, count);
2145    }
2146
2147    public org.omg.CORBA.NamedValue JavaDoc create_named_value
2148        (String JavaDoc name, org.omg.CORBA.Any JavaDoc value, int flags)
2149    {
2150        return new org.jacorb.orb.NamedValue (name, value, flags);
2151    }
2152
2153    public org.omg.CORBA.NVList JavaDoc create_operation_list (org.omg.CORBA.Object JavaDoc obj)
2154    {
2155        org.omg.CORBA.OperationDef JavaDoc oper;
2156
2157        if (obj instanceof org.omg.CORBA.OperationDef JavaDoc)
2158        {
2159            oper = (org.omg.CORBA.OperationDef JavaDoc) obj;
2160        }
2161        else
2162        {
2163            throw new org.omg.CORBA.BAD_PARAM JavaDoc ("Argument must be of type org.omg.CORBA.OperationDef");
2164        }
2165        return (create_operation_list (oper));
2166    }
2167
2168    // This operation is under deprecation. To be replaced by one above.
2169

2170    public org.omg.CORBA.NVList JavaDoc create_operation_list
2171        (org.omg.CORBA.OperationDef JavaDoc oper)
2172    {
2173        int no = 0;
2174        org.omg.CORBA.Any JavaDoc any;
2175        org.omg.CORBA.ParameterDescription JavaDoc[] params = null;
2176        org.omg.CORBA.ParameterDescription JavaDoc param;
2177        org.omg.CORBA.NVList JavaDoc list;
2178
2179        params = oper.params ();
2180        if (params != null)
2181        {
2182            no = params.length;
2183        }
2184        list = new org.jacorb.orb.NVList (this, no);
2185
2186        for (int i = 0; i < no; i++)
2187        {
2188            param = params[i];
2189            any = create_any ();
2190            any.type (param.type);
2191            list.add_value (param.name, any, param.mode.value ());
2192        }
2193
2194        return list;
2195    }
2196
2197    /**
2198     * a helper method supplied to initialize the object key map. This
2199     * replaces functionality from the defunct Environment class to populate
2200     * a hash map based on the names starting with "jacorb.orb.ObjectKeyMap"
2201     */

2202
2203    private void configureObjectKeyMap (Configuration config)
2204    {
2205        String JavaDoc[] names = config.getAttributeNames();
2206        String JavaDoc prefix = "jacorb.orb.objectKeyMap.";
2207        for (int i = 0; i < names.length; i++)
2208            if (names[i].startsWith (prefix))
2209                objectKeyMap.put(names[i].substring (prefix.length()),
2210                                 config.getAttribute (names[i],""));
2211    }
2212
2213    /**
2214     * <code>addObjectKey </code> is a proprietary method that allows the
2215     * internal objectKeyMap to be altered programmatically. The objectKeyMap
2216     * allows more readable corbaloc URLs by mapping the actual object key to
2217     * an arbitary string. See the jacorb.properties file for more information.
2218     *
2219     * @param key_name a <code>String</code> value e.g. NameService
2220     * @param full_path an <code>String</code> value e.g. file:/home/rnc/NameSingleton.ior
2221     */

2222    public void addObjectKey(String JavaDoc key_name, String JavaDoc full_path)
2223    {
2224        objectKeyMap.put(key_name, full_path);
2225    }
2226
2227
2228    /**
2229     * Map an object key to another, as defined by the value
2230     * of a corresponding configuration property in the properties
2231     * file, e.g. map "NameService" to "StandardNS/NameServer-POA/_root"
2232     *
2233     * @param originalKey a <code>byte[]</code> value containing the original
2234     * key.
2235     * @return a <code>byte[]</code> value containing the mapped key, if a
2236     * mapping is defined, originalKey otherwise.
2237     */

2238    public byte[] mapObjectKey( byte[] originalKey )
2239    {
2240        BufferedReader br = null;
2241        File iorFile = null;
2242        ParsedIOR pIOR = null;
2243        String JavaDoc found = null;
2244        String JavaDoc original = null;
2245
2246        if( objectKeyMap.size() != 0 )
2247        {
2248            original = new String JavaDoc( originalKey );
2249            found = (String JavaDoc)objectKeyMap.get( original );
2250
2251            if( found != null )
2252            {
2253                if ( ParsedIOR.isParsableProtocol ( found ) )
2254                {
2255                    // We have found a file reference. Use ParsedIOR to get
2256
// the byte key.
2257
try
2258                    {
2259                        pIOR = new ParsedIOR( found, this, logger );
2260                        return pIOR.get_object_key();
2261                    }
2262                    catch ( IllegalArgumentException JavaDoc e )
2263                    {
2264                        if (logger.isDebugEnabled())
2265                        {
2266                            logger.debug("Error - could not read protocol " + found );
2267                        }
2268                        return originalKey;
2269                    }
2270                }
2271                else
2272                {
2273                    return org.jacorb.orb.util.CorbaLoc.parseKey(found);
2274                }
2275            }
2276        }
2277        // else:
2278
return originalKey;
2279    }
2280
2281    /**
2282     * Inner class that implements org.omg.PortableInterceptor.Current
2283     * by forwarding each invocation to a thread-dependent target.
2284     */

2285    private class PICurrent
2286        extends org.omg.CORBA.LocalObject JavaDoc
2287        implements org.omg.PortableInterceptor.Current JavaDoc
2288    {
2289        // Helper method that returns the actual
2290
// target of a PICurrent invocation
2291
private Current getTarget()
2292        {
2293            if (interceptor_manager == null)
2294                return InterceptorManager.EMPTY_CURRENT;
2295            else
2296                return interceptor_manager.getCurrent();
2297        }
2298
2299        // org.omg.PortableInterceptor.Current implementation ---
2300

2301        public org.omg.CORBA.Any JavaDoc get_slot(int id)
2302            throws InvalidSlot
2303        {
2304            return getTarget().get_slot(id);
2305        }
2306
2307        public void set_slot(int id, org.omg.CORBA.Any JavaDoc data)
2308            throws InvalidSlot
2309        {
2310            getTarget().set_slot(id, data);
2311        }
2312
2313    }
2314
2315    // Even though the methods connect(obj) and disconnect(obj) are
2316
// deprecated, they are implemented here because the server-side
2317
// programming model traditionally used by RMI/IIOP strongly relies
2318
// on them.
2319

2320    /**
2321     * Indicates that the root POA manager was not yet activated.
2322     */

2323    private boolean firstConnection = true;
2324
2325    /**
2326     * Associates connected objects to their servants. The servant associated
2327     * with a connected object is retrieved from this map when disconnect is
2328     * called on the object.
2329     */

2330    private Map connectedObjects = new HashMap();
2331
2332    /**
2333     * Servant class used by connect and disconnect
2334     */

2335    static class HandlerWrapper extends org.omg.PortableServer.Servant JavaDoc
2336                                implements org.omg.CORBA.portable.InvokeHandler JavaDoc
2337    {
2338        private org.omg.CORBA.portable.InvokeHandler JavaDoc wrappedHandler;
2339
2340        public HandlerWrapper(org.omg.CORBA.portable.ObjectImpl JavaDoc objectImpl)
2341        {
2342            wrappedHandler = (org.omg.CORBA.portable.InvokeHandler JavaDoc)objectImpl;
2343        }
2344
2345        public String JavaDoc[] _all_interfaces(org.omg.PortableServer.POA JavaDoc poa,
2346                                        byte[] objectID)
2347        {
2348            return ((org.omg.CORBA.portable.ObjectImpl JavaDoc)wrappedHandler)._ids();
2349        }
2350
2351        public org.omg.CORBA.portable.OutputStream JavaDoc _invoke(
2352                                String JavaDoc method,
2353                                org.omg.CORBA.portable.InputStream JavaDoc input,
2354                                org.omg.CORBA.portable.ResponseHandler JavaDoc handler)
2355            throws org.omg.CORBA.SystemException JavaDoc
2356        {
2357            return wrappedHandler._invoke(method, input, handler);
2358        }
2359
2360    }
2361
2362        public void connect(org.omg.CORBA.Object JavaDoc obj)
2363    {
2364        if (!(obj instanceof org.omg.CORBA.portable.ObjectImpl JavaDoc))
2365            throw new BAD_PARAM JavaDoc("connect parameter must extend " +
2366                                "org.omg.CORBA.portable.ObjectImpl");
2367        
2368        if (!(obj instanceof org.omg.CORBA.portable.InvokeHandler JavaDoc))
2369            throw new BAD_PARAM JavaDoc("connect parameter must implement " +
2370                                "org.omg.CORBA.portable.InvokeHandler");
2371        
2372        synchronized (connectedObjects)
2373        {
2374            if (connectedObjects.containsKey(obj) == false)
2375            {
2376                org.omg.CORBA.portable.ObjectImpl JavaDoc objectImpl =
2377                    (org.omg.CORBA.portable.ObjectImpl JavaDoc)obj;
2378                org.omg.PortableServer.Servant JavaDoc servant =
2379                    new HandlerWrapper(objectImpl);
2380                org.omg.CORBA.Object JavaDoc ref = servant._this_object(this);
2381                objectImpl._set_delegate(
2382                    ((org.omg.CORBA.portable.ObjectImpl JavaDoc)ref)._get_delegate());
2383                connectedObjects.put(obj, servant);
2384                if (firstConnection)
2385                {
2386                    firstConnection = false;
2387                    org.omg.PortableServer.POAManager JavaDoc rootPOAManager =
2388                        getRootPOA().the_POAManager();
2389                    if (rootPOAManager.get_state() == State.HOLDING)
2390                    {
2391                        try
2392                        {
2393                            rootPOAManager.activate();
2394                        }
2395                        catch (AdapterInactive JavaDoc adapterInactive)
2396                        {
2397                            // cannot happen
2398
if( logger.isErrorEnabled() )
2399                            {
2400                                logger.error(adapterInactive.getMessage());
2401                            }
2402                        }
2403                    }
2404                }
2405            }
2406        }
2407    }
2408
2409    public void disconnect(org.omg.CORBA.Object JavaDoc obj)
2410    {
2411        if (!(obj instanceof org.omg.CORBA.portable.ObjectImpl JavaDoc))
2412            throw new BAD_PARAM JavaDoc("disconnect parameter must extend " +
2413                                "org.omg.CORBA.portable.ObjectImpl");
2414        
2415        if (!(obj instanceof org.omg.CORBA.portable.InvokeHandler JavaDoc))
2416            throw new BAD_PARAM JavaDoc("disconnect parameter must implement " +
2417                                "org.omg.CORBA.portable.InvokeHandler");
2418        
2419        synchronized (connectedObjects)
2420        {
2421            org.omg.PortableServer.Servant JavaDoc servant =
2422                (org.omg.PortableServer.Servant JavaDoc)connectedObjects.get(obj);
2423            
2424            if (servant != null)
2425            {
2426                connectedObjects.remove(obj);
2427                try
2428                {
2429                    getRootPOA().deactivate_object(
2430                                        getRootPOA().servant_to_id(servant));
2431                }
2432                catch (Exception JavaDoc e)
2433                {
2434                    // cannot happen
2435
if( logger.isErrorEnabled())
2436                    {
2437                        logger.error(e.getMessage());
2438                    }
2439                }
2440            }
2441        }
2442    }
2443
2444}
2445
Popular Tags