Source Code Cross Referenced for ORB.java in  » Collaboration » JacORB » org » jacorb » orb » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Collaboration » JacORB » org.jacorb.orb 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        package org.jacorb.orb;
0002:
0003:        /*
0004:         *        JacORB  - a free Java ORB
0005:         *
0006:         *   Copyright (C) 1997-2004 Gerald Brose.
0007:         *
0008:         *   This library is free software; you can redistribute it and/or
0009:         *   modify it under the terms of the GNU Library General Public
0010:         *   License as published by the Free Software Foundation; either
0011:         *   version 2 of the License, or (at your option) any later version.
0012:         *
0013:         *   This library is distributed in the hope that it will be useful,
0014:         *   but WITHOUT ANY WARRANTY; without even the implied warranty of
0015:         *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0016:         *   Library General Public License for more details.
0017:         *
0018:         *   You should have received a copy of the GNU Library General Public
0019:         *   License along with this library; if not, write to the Free
0020:         *   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
0021:         */
0022:
0023:        import java.util.*;
0024:
0025:        import org.jacorb.imr.ImRAccessImpl;
0026:        import org.jacorb.util.*;
0027:        import org.jacorb.orb.iiop.IIOPAddress;
0028:        import org.jacorb.orb.iiop.IIOPProfile;
0029:        import org.jacorb.orb.etf.*;
0030:        import org.jacorb.orb.policies.*;
0031:        import org.jacorb.orb.dii.Request;
0032:        import org.jacorb.orb.giop.*;
0033:        import org.jacorb.orb.portableInterceptor.*;
0034:        import org.jacorb.poa.RPPoolManager;
0035:        import org.jacorb.poa.RPPoolManagerFactory;
0036:        import org.jacorb.poa.util.POAUtil;
0037:
0038:        import org.apache.avalon.framework.logger.*;
0039:        import org.apache.avalon.framework.configuration.*;
0040:
0041:        import org.omg.CORBA.BAD_PARAM;
0042:        import org.omg.CORBA.BAD_INV_ORDER;
0043:        import org.omg.CORBA.CompletionStatus;
0044:        import org.omg.CORBA.INITIALIZE;
0045:        import org.omg.CORBA.INTERNAL;
0046:        import org.omg.CORBA.MARSHAL;
0047:        import org.omg.CORBA.ORBPackage.InvalidName;
0048:        import org.omg.CORBA.portable.ValueFactory;
0049:        import org.omg.CORBA.portable.BoxedValueHelper;
0050:        import org.omg.CORBA.portable.StreamableValue;
0051:        import org.omg.Messaging.*;
0052:        import org.omg.PortableInterceptor.*;
0053:        import org.omg.PortableServer.POAManagerPackage.AdapterInactive;
0054:        import org.omg.PortableServer.POAManagerPackage.State;
0055:        import org.omg.IOP.*;
0056:        import org.omg.ETF.*;
0057:
0058:        /**
0059:         * @author Gerald Brose, FU Berlin
0060:         * @version $Id: ORB.java,v 1.172 2007/02/14 09:55:24 andre.spiegel Exp $
0061:         */
0062:
0063:        public final class ORB extends ORBSingleton implements 
0064:                org.jacorb.poa.POAListener, Configurable {
0065:            private static final String versionString = org.jacorb.util.Version.version;
0066:            private static final String dateString = org.jacorb.util.Version.date;
0067:            private static final String nullIORString = "IOR:00000000000000010000000000000000";
0068:
0069:            /**
0070:             * the configuration object for this ORB instance
0071:             */
0072:            private org.jacorb.config.Configuration configuration = null;
0073:
0074:            // configuration properties
0075:            private boolean cacheReferences;
0076:            private String implName;
0077:            private int giopMinorVersion;
0078:            private boolean giopAdd_1_0_Profiles;
0079:            private String hashTableClassName;
0080:            private boolean useIMR;
0081:
0082:            private ProtocolAddressBase imrProxyAddress = null;
0083:            private ProtocolAddressBase iorProxyAddress;
0084:
0085:            /**
0086:             *  "initial" references
0087:             */
0088:            private final Map initial_references = new HashMap();
0089:
0090:            private org.jacorb.poa.POA rootpoa;
0091:            private org.jacorb.poa.Current poaCurrent;
0092:            private BasicAdapter basicAdapter;
0093:
0094:            /** interceptor handling */
0095:            private InterceptorManager interceptor_manager = null;
0096:            private boolean hasClientInterceptors = false;
0097:            private boolean hasServerInterceptors = false;
0098:            private final org.omg.PortableInterceptor.Current piCurrent = new PICurrent();
0099:
0100:            /** reference caching */
0101:            private Map knownReferences = null;
0102:
0103:            /** connection mgmt. */
0104:            private ClientConnectionManager clientConnectionManager;
0105:
0106:            /** The transport manager*/
0107:            private TransportManager transport_manager = null;
0108:
0109:            private GIOPConnectionManager giop_connection_manager = null;
0110:
0111:            /** buffer mgmt. */
0112:            private BufferManager bufferManager;
0113:
0114:            /**
0115:             * Maps repository ids (strings) to objects that implement
0116:             * org.omg.CORBA.portable.ValueFactory.  This map is used by
0117:             * register/unregister_value_factory() and lookup_value_factory().
0118:             */
0119:            private final Map valueFactories = new HashMap();
0120:
0121:            /**
0122:             * Maps repository ids (strings) of boxed value types to
0123:             * BoxedValueHelper instances for those types.
0124:             */
0125:            private final Map boxedValueHelpers = new HashMap();
0126:
0127:            private final Map objectKeyMap = new HashMap();
0128:
0129:            /** the ORB object's logger */
0130:            private Logger logger;
0131:
0132:            /** command like args */
0133:            public String[] _args;
0134:
0135:            /* for run() and shutdown()  */
0136:            private final Object runSync = new java.lang.Object();
0137:            private boolean run = true;
0138:
0139:            private boolean shutdown_in_progress = false;
0140:            private boolean destroyed = false;
0141:            private final Object shutdown_synch = new Object();
0142:
0143:            /**
0144:             *  for registering POAs with the ImR
0145:             */
0146:            private ImRAccess imr = null;
0147:            private int persistentPOACount;
0148:
0149:            public static final String orb_id = "jacorb:"
0150:                    + org.jacorb.util.Version.version;
0151:
0152:            /**
0153:             * outstanding dii requests awaiting completion
0154:             */
0155:            private final Set requests = Collections
0156:                    .synchronizedSet(new HashSet());
0157:
0158:            /**
0159:             * most recently completed dii request found during poll
0160:             */
0161:            private Request request = null;
0162:
0163:            private RTORB rtORB;
0164:
0165:            /* PolicyManagement */
0166:            private org.jacorb.orb.policies.PolicyManager policyManager;
0167:
0168:            /* policy factories, from portable interceptor spec */
0169:            private final Map policy_factories = Collections
0170:                    .synchronizedMap(new HashMap());
0171:
0172:            private static final String[] services = { "RootPOA", "POACurrent",
0173:                    "DynAnyFactory", "PICurrent", "CodecFactory", "RTORB", };
0174:
0175:            private boolean bidir_giop = false;
0176:
0177:            /**
0178:             * <code>serverIdStr</code> is a unique ID that will be used to identify this
0179:             * server.
0180:             */
0181:            private final String serverIdStr = String.valueOf((long) (Math
0182:                    .random() * 9999999999L));
0183:
0184:            /**
0185:             * <code>serverId</code> is the bytes form of serverIdStr.
0186:             */
0187:            private final byte[] serverId = serverIdStr.getBytes();
0188:
0189:            private RPPoolManagerFactory poolManagerFactory;
0190:            private boolean failOnORBInitializerError;
0191:
0192:            public ORB() {
0193:                super (false);
0194:            }
0195:
0196:            /**
0197:             * configure the ORB
0198:             */
0199:            public void configure(Configuration config)
0200:                    throws ConfigurationException {
0201:                super .configure(config);
0202:
0203:                this .configuration = (org.jacorb.config.Configuration) config;
0204:                logger = configuration.getNamedLogger("jacorb.orb");
0205:
0206:                cacheReferences = configuration.getAttributeAsBoolean(
0207:                        "jacorb.reference_caching", false);
0208:
0209:                implName = configuration.getAttribute("jacorb.implname", "");
0210:
0211:                giopMinorVersion = configuration.getAttributeAsInteger(
0212:                        "jacorb.giop_minor_version", 2);
0213:
0214:                giopAdd_1_0_Profiles = configuration.getAttributeAsBoolean(
0215:                        "jacorb.giop.add_1_0_profiles", false);
0216:
0217:                hashTableClassName = configuration.getAttribute(
0218:                        "jacorb.hashtable_class", HashMap.class.getName());
0219:
0220:                useIMR = configuration.getAttributeAsBoolean("jacorb.use_imr",
0221:                        false);
0222:
0223:                String host = configuration.getAttribute(
0224:                        "jacorb.imr.ior_proxy_host", null);
0225:                int port = configuration.getAttributeAsInteger(
0226:                        "jacorb.imr.ior_proxy_port", -1);
0227:                String address = configuration.getAttribute(
0228:                        "jacorb.imr.ior_proxy_address", null);
0229:
0230:                imrProxyAddress = createAddress(host, port, address);
0231:
0232:                host = configuration
0233:                        .getAttribute("jacorb.ior_proxy_host", null);
0234:                port = configuration.getAttributeAsInteger(
0235:                        "jacorb.ior_proxy_port", -1);
0236:                address = configuration.getAttribute(
0237:                        "jacorb.ior_proxy_address", null);
0238:
0239:                iorProxyAddress = createAddress(host, port, address);
0240:
0241:                failOnORBInitializerError = configuration
0242:                        .getAttributeAsBoolean(
0243:                                "jacorb.orb_initializer.fail_on_error", false);
0244:
0245:                printVersion(configuration);
0246:
0247:                BufferManager.configure(configuration);
0248:
0249:                try {
0250:                    bufferManager = BufferManager.getInstance();
0251:                } catch (BAD_INV_ORDER b) {
0252:                    logger.fatalError("unexpected exception", b);
0253:                    throw new INTERNAL(b.toString());
0254:                }
0255:
0256:                configureObjectKeyMap(configuration);
0257:
0258:                if (poolManagerFactory != null) {
0259:                    // currently the ORB is only re-configured during
0260:                    // test runs. in this case an existing the poolManagerFactory
0261:                    // should be shut down properly to give its threads the
0262:                    // change to exit.
0263:
0264:                    // doesn't work this way as configure is invoked during
0265:                    // a request. causes the test to hang (alphonse)
0266:
0267:                    //poolManagerFactory.destroy();
0268:                }
0269:
0270:                poolManagerFactory = new RPPoolManagerFactory(this );
0271:            }
0272:
0273:            /**
0274:             * create an address based on addressString OR (host AND port)
0275:             * it neither addressString NOR (host AND port) are specified this method
0276:             * will return null.
0277:             */
0278:            private ProtocolAddressBase createAddress(String host, int port,
0279:                    String addressString) {
0280:                final ProtocolAddressBase address;
0281:
0282:                try {
0283:                    if (addressString == null) {
0284:                        if (host != null || port != -1) {
0285:                            address = new IIOPAddress();
0286:                            address.configure(configuration);
0287:                            if (host != null) {
0288:                                ((IIOPAddress) address).setHostname(host);
0289:                            }
0290:                            if (port != -1) {
0291:                                ((IIOPAddress) address).setPort(port);
0292:                            }
0293:                        } else {
0294:                            address = null;
0295:                        }
0296:                    } else {
0297:                        address = createAddress(addressString);
0298:                    }
0299:                } catch (Exception ex) {
0300:                    logger.error("error initializing ProxyAddress", ex);
0301:                    throw new INITIALIZE(ex.toString());
0302:                }
0303:
0304:                return address;
0305:            }
0306:
0307:            private void printVersion(
0308:                    org.jacorb.config.Configuration configuration) {
0309:                final boolean printVersion = configuration
0310:                        .getAttributeAsBoolean("jacorb.orb.print_version", true);
0311:
0312:                if (!printVersion) {
0313:                    return;
0314:                }
0315:
0316:                final Logger logger = configuration
0317:                        .getNamedLogger("jacorb.orb.print_version");
0318:
0319:                logger
0320:                        .info("\n\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"
0321:                                + "\tJacORB V "
0322:                                + versionString
0323:                                + ", www.jacorb.org\n"
0324:                                + "\t(C) The JacORB project "
0325:                                + dateString
0326:                                + "\n"
0327:                                + "\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
0328:            }
0329:
0330:            /**
0331:             * Some parts of JacORB cannot be elegantly configured from the outside
0332:             * and need access to the ORB's configuration retrieve config settings.
0333:             * This method should only be used in those restricted cases!
0334:             */
0335:
0336:            public org.jacorb.config.Configuration getConfiguration() {
0337:                return configuration;
0338:            }
0339:
0340:            /**
0341:             * Overrides id() in org.omg.CORBA_2_5.ORB
0342:             */
0343:
0344:            public String id() {
0345:                return orb_id;
0346:            }
0347:
0348:            public boolean useBiDirGIOP() {
0349:                return bidir_giop;
0350:            }
0351:
0352:            public void turnOnBiDirGIOP() {
0353:                if (!bidir_giop) {
0354:                    bidir_giop = true;
0355:
0356:                    clientConnectionManager.setRequestListener(basicAdapter
0357:                            .getRequestListener());
0358:                }
0359:            }
0360:
0361:            public ProtocolAddressBase createAddress(String address) {
0362:                List factorylist = getTransportManager().getFactoriesList();
0363:                ProtocolAddressBase result = null;
0364:                for (Iterator i = factorylist.iterator(); i.hasNext()
0365:                        && result == null;) {
0366:                    FactoriesBase f = (FactoriesBase) i.next();
0367:                    result = f.create_protocol_address(address);
0368:                }
0369:                return result;
0370:            }
0371:
0372:            /**
0373:             *  This  version of _getObject  is used for references  that have
0374:             *  arrived over the network and is called from CDRInputStream. It
0375:             *  removes stale cache entries
0376:             */
0377:
0378:            public synchronized org.omg.CORBA.Object _getObject(ParsedIOR pior) {
0379:                String key = pior.getIORString();
0380:                org.omg.CORBA.portable.ObjectImpl object = (org.omg.CORBA.portable.ObjectImpl) knownReferences
0381:                        .get(key);
0382:
0383:                if (object != null) {
0384:                    org.jacorb.orb.Delegate del = (org.jacorb.orb.Delegate) object
0385:                            ._get_delegate();
0386:                    if (del != null) {
0387:                        ParsedIOR delpior = del.getParsedIOR();
0388:                        if (delpior == null) {
0389:                            knownReferences.remove(key);
0390:                            if (logger.isDebugEnabled()) {
0391:                                logger
0392:                                        .debug("Removing an invalid reference from cache.");
0393:                            }
0394:                        } else if (pior.getEffectiveProfile().is_match(
0395:                                delpior.getEffectiveProfile())) {
0396:                            return object._duplicate();
0397:                        }
0398:                    } else {
0399:                        if (logger.isDebugEnabled()) {
0400:                            logger.debug("Remove stale reference from cache ");
0401:                        }
0402:                        knownReferences.remove(key);
0403:                    }
0404:                }
0405:
0406:                org.jacorb.orb.Delegate d = new Delegate(this , pior);
0407:                try {
0408:                    d.configure(configuration);
0409:                } catch (ConfigurationException ce) {
0410:                    logger.error("ConfigurationException", ce);
0411:                }
0412:
0413:                object = d.getReference(null);
0414:
0415:                if (cacheReferences) {
0416:                    knownReferences.put(key, object);
0417:                }
0418:                return object;
0419:            }
0420:
0421:            /**
0422:             * Find a local POA for a delegate (called from is_local())
0423:             * returns non-null only if a root POA is already activated
0424:             * and all POAs along the path on the poa name are active, i.e.
0425:             * returns null for POAs in the holding state
0426:             */
0427:
0428:            org.jacorb.poa.POA findPOA(org.jacorb.orb.Delegate d,
0429:                    org.omg.CORBA.Object ref) {
0430:                List scopes;
0431:                String res;
0432:                String refImplName = null;
0433:
0434:                // if no POAs activated, we don't look further
0435:                if (rootpoa == null || basicAdapter == null) {
0436:                    return null;
0437:                }
0438:
0439:                try {
0440:                    refImplName = org.jacorb.poa.util.POAUtil.extractImplName(d
0441:                            .getObjectKey());
0442:                } catch (org.jacorb.poa.except.POAInternalError pie) {
0443:                    if (logger.isDebugEnabled()) {
0444:                        logger
0445:                                .debug("findPOA: reference generated by foreign POA");
0446:                    }
0447:                    return null;
0448:                }
0449:
0450:                if (refImplName == null) {
0451:                    if (implName.length() > 0 || serverIdStr.length() > 0) {
0452:                        if (logger.isDebugEnabled()) {
0453:                            logger
0454:                                    .debug("findPOA: impl_name mismatch - null != "
0455:                                            + implName);
0456:                        }
0457:                        return null;
0458:                    }
0459:                } else {
0460:                    if (!(implName.equals(refImplName))
0461:                            && !(serverIdStr.equals(refImplName))) {
0462:                        if (logger.isDebugEnabled()) {
0463:                            logger.debug("findPOA: impl_name mismatch - "
0464:                                    + refImplName + " != " + implName);
0465:                        }
0466:                        return null;
0467:                    }
0468:                }
0469:
0470:                try {
0471:                    org.jacorb.poa.POA tmp_poa = rootpoa;
0472:                    String poa_name = org.jacorb.poa.util.POAUtil
0473:                            .extractPOAName(d.getObjectKey());
0474:
0475:                    /* strip scoped poa name (first part of the object key before "::",
0476:                     *  will be empty for the root poa
0477:                     */
0478:                    scopes = POAUtil.extractScopedPOANames(poa_name);
0479:
0480:                    for (int i = 0; i < scopes.size(); i++) {
0481:                        res = ((String) scopes.get(i));
0482:
0483:                        if ("".equals(res)) {
0484:                            break;
0485:                        }
0486:
0487:                        /* the following is a  call to a method in the private
0488:                           interface between the ORB  and the POA. It does the
0489:                           necessary    synchronization    between   incoming,
0490:                           potentially concurrent  requests to activate  a POA
0491:                           using its  adapter activator. This  call will block
0492:                           until  the correct  POA is  activated and  ready to
0493:                           service    requests.    Thus,    concurrent   calls
0494:                           originating  from a  single,  multi-threaded client
0495:                           will be serialized  because the thread that accepts
0496:                           incoming  requests  from   the  client  process  is
0497:                           blocked.  Concurrent  calls from other destinations
0498:                           are not  serialized unless they  involve activating
0499:                           the same adapter.  */
0500:
0501:                        try {
0502:                            tmp_poa = tmp_poa._getChildPOA(res);
0503:                        } catch (org.jacorb.poa.except.ParentIsHolding p) {
0504:                            if (logger.isDebugEnabled()) {
0505:                                logger.debug("findPOA: holding adapter");
0506:                            }
0507:                            return null;
0508:                        }
0509:                    }
0510:                    byte[] objectId = org.jacorb.poa.util.POAUtil
0511:                            .extractOID(ref);
0512:
0513:                    if (tmp_poa.isSystemId()
0514:                            && !tmp_poa.previouslyGeneratedObjectId(objectId)) {
0515:                        if (logger.isDebugEnabled()) {
0516:                            logger
0517:                                    .debug("findPOA: not a previously generated object key.");
0518:                        }
0519:                        return null;
0520:                    }
0521:
0522:                    return tmp_poa;
0523:                } catch (Exception e) {
0524:                    if (logger.isErrorEnabled()) {
0525:                        logger.error(e.getMessage());
0526:                    }
0527:                }
0528:
0529:                if (logger.isDebugEnabled()) {
0530:                    logger.debug("findPOA: nothing found");
0531:                }
0532:                return null;
0533:            }
0534:
0535:            public ClientConnectionManager getClientConnectionManager() {
0536:                return clientConnectionManager;
0537:            }
0538:
0539:            public synchronized GIOPConnectionManager getGIOPConnectionManager() {
0540:                if (giop_connection_manager == null) {
0541:                    giop_connection_manager = new GIOPConnectionManager();
0542:                    try {
0543:                        giop_connection_manager.configure(configuration);
0544:                    } catch (ConfigurationException ce) {
0545:                        throw new INTERNAL(ce.toString());
0546:                    }
0547:                }
0548:                return giop_connection_manager;
0549:            }
0550:
0551:            /**
0552:             * Take a string rather then a Delegate object to prevent data race
0553:             * warning.
0554:             */
0555:            synchronized void _release(String iorString) {
0556:                knownReferences.remove(iorString);
0557:            }
0558:
0559:            /**
0560:             * This method creates a policy  with the given type and the given
0561:             * value.
0562:             *
0563:             * @param type The policies type.
0564:             * @param value The policies value.
0565:             * @exception org.omg.CORBA.PolicyError There is no PolicyFactory for the
0566:             * given type or the policy creation failed.
0567:             * @see org.omg.PortableInterceptor.PolicyFactory
0568:             */
0569:
0570:            public org.omg.CORBA.Policy create_policy(int type,
0571:                    org.omg.CORBA.Any value) throws org.omg.CORBA.PolicyError {
0572:                switch (type) {
0573:                case MAX_HOPS_POLICY_TYPE.value:
0574:                    return new org.jacorb.orb.policies.MaxHopsPolicy(value);
0575:                case QUEUE_ORDER_POLICY_TYPE.value:
0576:                    return new org.jacorb.orb.policies.QueueOrderPolicy(value);
0577:                case REBIND_POLICY_TYPE.value:
0578:                    return new org.jacorb.orb.policies.RebindPolicy(value);
0579:                case RELATIVE_REQ_TIMEOUT_POLICY_TYPE.value:
0580:                    return new org.jacorb.orb.policies.RelativeRequestTimeoutPolicy(
0581:                            value);
0582:                case RELATIVE_RT_TIMEOUT_POLICY_TYPE.value:
0583:                    return new org.jacorb.orb.policies.RelativeRoundtripTimeoutPolicy(
0584:                            value);
0585:                case REPLY_END_TIME_POLICY_TYPE.value:
0586:                    return new org.jacorb.orb.policies.ReplyEndTimePolicy(value);
0587:                case REPLY_PRIORITY_POLICY_TYPE.value:
0588:                    return new org.jacorb.orb.policies.ReplyPriorityPolicy(
0589:                            value);
0590:                case REPLY_START_TIME_POLICY_TYPE.value:
0591:                    return new org.jacorb.orb.policies.ReplyStartTimePolicy(
0592:                            value);
0593:                case REQUEST_END_TIME_POLICY_TYPE.value:
0594:                    return new org.jacorb.orb.policies.RequestEndTimePolicy(
0595:                            value);
0596:                case REQUEST_PRIORITY_POLICY_TYPE.value:
0597:                    return new org.jacorb.orb.policies.RequestPriorityPolicy(
0598:                            value);
0599:                case REQUEST_START_TIME_POLICY_TYPE.value:
0600:                    return new org.jacorb.orb.policies.RequestStartTimePolicy(
0601:                            value);
0602:                case ROUTING_POLICY_TYPE.value:
0603:                    return new org.jacorb.orb.policies.RoutingPolicy(value);
0604:                case SYNC_SCOPE_POLICY_TYPE.value:
0605:                    return new org.jacorb.orb.policies.SyncScopePolicy(value);
0606:                case org.omg.RTCORBA.CLIENT_PROTOCOL_POLICY_TYPE.value:
0607:                    return new org.jacorb.orb.policies.ClientProtocolPolicy(
0608:                            value);
0609:                default:
0610:                    final PolicyFactory factory = (PolicyFactory) policy_factories
0611:                            .get(ObjectUtil.newInteger(type));
0612:
0613:                    if (factory == null) {
0614:                        throw new org.omg.CORBA.PolicyError();
0615:                    }
0616:
0617:                    return factory.create_policy(type, value);
0618:                }
0619:            }
0620:
0621:            /**
0622:             * Tests if a policy factory is present for the given type.
0623:             */
0624:            public boolean hasPolicyFactoryForType(int type) {
0625:                return (policy_factories.containsKey(ObjectUtil
0626:                        .newInteger(type)));
0627:            }
0628:
0629:            public org.omg.CORBA.ContextList create_context_list() {
0630:                throw new org.omg.CORBA.NO_IMPLEMENT();
0631:            }
0632:
0633:            public org.omg.CORBA.Environment create_environment() {
0634:                throw new org.omg.CORBA.NO_IMPLEMENT();
0635:            }
0636:
0637:            public org.omg.CORBA.portable.OutputStream create_output_stream() {
0638:                return new CDROutputStream(this );
0639:            }
0640:
0641:            org.omg.IOP.IOR createIOR(String repId, byte[] objectKey,
0642:                    boolean _transient, org.jacorb.poa.POA poa,
0643:                    Map policy_overrides) {
0644:                List profiles = new ArrayList();
0645:                Map componentMap = new HashMap();
0646:                int[] profileTags = new int[basicAdapter.getEndpointProfiles()
0647:                        .size()];
0648:                int n = 0;
0649:                for (Iterator i = basicAdapter.getEndpointProfiles().iterator(); i
0650:                        .hasNext();) {
0651:                    Profile profile = (Profile) i.next();
0652:                    profile.set_object_key(objectKey);
0653:                    profiles.add(profile);
0654:                    profileTags[n++] = profile.tag();
0655:
0656:                    TaggedComponentList profileComponents = new TaggedComponentList();
0657:                    profileComponents.addComponent(create_ORB_TYPE_ID());
0658:                    componentMap.put(ObjectUtil.newInteger(profile.tag()),
0659:                            profileComponents);
0660:
0661:                    if (profile instanceof  ProfileBase) {
0662:                        // use proxy or ImR address if necessary
0663:                        patchAddress((ProfileBase) profile, repId, _transient);
0664:
0665:                        // patch primary address port to 0 if SSL is required
0666:                        if (poa.isSSLRequired()) {
0667:                            ((ProfileBase) profile).patchPrimaryAddress(null);
0668:                        }
0669:                    }
0670:                }
0671:
0672:                TaggedComponentList multipleComponents = new TaggedComponentList();
0673:                componentMap.put(ObjectUtil
0674:                        .newInteger(TAG_MULTIPLE_COMPONENTS.value),
0675:                        multipleComponents);
0676:
0677:                // invoke IOR interceptors
0678:                if ((interceptor_manager != null)
0679:                        && interceptor_manager.hasIORInterceptors()) {
0680:                    IORInfoImpl info = new IORInfoImpl(this , poa, componentMap,
0681:                            policy_overrides, profiles);
0682:                    interceptor_manager.setProfileTags(profileTags);
0683:                    try {
0684:                        interceptor_manager.getIORIterator().iterate(info);
0685:                    } catch (Exception e) {
0686:                        if (logger.isErrorEnabled()) {
0687:                            logger.error(e.getMessage());
0688:                        }
0689:                    }
0690:                }
0691:
0692:                // add GIOP 1.0 profile if necessary
0693:
0694:                IIOPProfile iiopProfile = findIIOPProfile(profiles);
0695:                if ((iiopProfile != null)
0696:                        && (this .giopMinorVersion == 0 || this .giopAdd_1_0_Profiles)) {
0697:                    Profile profile_1_0 = iiopProfile.to_GIOP_1_0();
0698:                    profiles.add(profile_1_0);
0699:
0700:                    // shuffle all components over into the multiple components profile
0701:                    TaggedComponentList iiopComponents = (TaggedComponentList) componentMap
0702:                            .get(ObjectUtil.newInteger(TAG_INTERNET_IOP.value));
0703:
0704:                    multipleComponents.addAll(iiopProfile.getComponents());
0705:                    multipleComponents.addAll(iiopComponents);
0706:
0707:                    // if we only want GIOP 1.0, remove the other profile
0708:                    if (giopMinorVersion == 0) {
0709:                        profiles.remove(iiopProfile);
0710:                    }
0711:                }
0712:
0713:                // marshal the profiles into the IOR and return
0714:                TaggedProfile[] tps = null;
0715:                if (multipleComponents.isEmpty()) {
0716:                    tps = new TaggedProfile[profiles.size()];
0717:                } else {
0718:                    tps = new TaggedProfile[profiles.size() + 1];
0719:                    tps[tps.length - 1] = createMultipleComponentsProfile(multipleComponents);
0720:                }
0721:
0722:                TaggedProfileHolder tp = new TaggedProfileHolder();
0723:                TaggedComponentSeqHolder tc = new TaggedComponentSeqHolder();
0724:                for (int i = 0; i < profiles.size(); i++) {
0725:                    Profile p = (Profile) profiles.get(i);
0726:                    TaggedComponentList c = (TaggedComponentList) componentMap
0727:                            .get(ObjectUtil.newInteger(p.tag()));
0728:                    tc.value = c.asArray();
0729:                    p.marshal(tp, tc);
0730:                    tps[i] = tp.value;
0731:                }
0732:
0733:                return new IOR(repId, tps);
0734:            }
0735:
0736:            private TaggedProfile createMultipleComponentsProfile(
0737:                    TaggedComponentList components) {
0738:                CDROutputStream out = new CDROutputStream(this );
0739:                out.beginEncapsulatedArray();
0740:                MultipleComponentProfileHelper.write(out, components.asArray());
0741:                return new TaggedProfile(TAG_MULTIPLE_COMPONENTS.value, out
0742:                        .getBufferCopy());
0743:            }
0744:
0745:            /**
0746:             * Finds the first IIOPProfile in the given List of Profiles,
0747:             * and returns it.  If no such profile is found, this method
0748:             * returns null.
0749:             */
0750:            private IIOPProfile findIIOPProfile(List profiles) {
0751:                for (Iterator i = profiles.iterator(); i.hasNext();) {
0752:                    Profile p = (Profile) i.next();
0753:                    if (p instanceof  IIOPProfile) {
0754:                        return (IIOPProfile) p;
0755:                    }
0756:                }
0757:                return null;
0758:            }
0759:
0760:            public org.omg.CORBA.Context get_default_context() {
0761:                throw new org.omg.CORBA.NO_IMPLEMENT();
0762:            }
0763:
0764:            /**
0765:             * used from the POA
0766:             * @return the basic adapter used by this ORB instance
0767:             */
0768:            public org.jacorb.orb.BasicAdapter getBasicAdapter() {
0769:                if (basicAdapter == null) {
0770:                    throw new INITIALIZE(
0771:                            "Adapters not initialized; resolve RootPOA.");
0772:                }
0773:                return basicAdapter;
0774:            }
0775:
0776:            /**
0777:             * getPOACurrent
0778:             */
0779:
0780:            public synchronized org.jacorb.poa.Current getPOACurrent() {
0781:                if (poaCurrent == null) {
0782:                    poaCurrent = new org.jacorb.poa.Current();
0783:                }
0784:                return poaCurrent;
0785:            }
0786:
0787:            /**
0788:             * called by POA to create an IOR
0789:             *
0790:             * @param poa the calling POA
0791:             * @param object_key
0792:             * @param rep_id
0793:             * @param _transient is the new reference transient or persistent
0794:             * @return a new CORBA Object reference
0795:             */
0796:            public org.omg.CORBA.Object getReference(org.jacorb.poa.POA poa,
0797:                    byte[] object_key, String rep_id, boolean _transient) {
0798:                org.omg.IOP.IOR ior = createIOR(
0799:                        (rep_id == null ? "IDL:omg.org/CORBA/Object:1.0"
0800:                                : rep_id), object_key, _transient, poa, null);
0801:
0802:                if (ior == null) {
0803:                    if (logger.isErrorEnabled()) {
0804:                        logger.error("Interal error: createIOR returns null");
0805:                    }
0806:                }
0807:
0808:                Delegate d = new Delegate(this , ior);
0809:                try {
0810:                    d.configure(configuration);
0811:                } catch (ConfigurationException ce) {
0812:                    logger.error("configuration exception", ce);
0813:                }
0814:                return d.getReference(poa);
0815:            }
0816:
0817:            public synchronized org.jacorb.poa.POA getRootPOA()
0818:                    throws org.omg.CORBA.INITIALIZE {
0819:                if (rootpoa == null) {
0820:                    rootpoa = org.jacorb.poa.POA._POA_init(this );
0821:
0822:                    basicAdapter = new BasicAdapter(this , rootpoa,
0823:                            getTransportManager(), getGIOPConnectionManager());
0824:
0825:                    try {
0826:                        rootpoa.configure(configuration);
0827:                        basicAdapter.configure(configuration);
0828:                    } catch (ConfigurationException ce) {
0829:                        throw new org.omg.CORBA.INITIALIZE(
0830:                                "ConfigurationException: " + ce.toString());
0831:                    }
0832:                    rootpoa._addPOAEventListener(this );
0833:
0834:                }
0835:                return rootpoa;
0836:            }
0837:
0838:            public String[] list_initial_services() {
0839:                final List list = new ArrayList(initial_references.size()
0840:                        + services.length);
0841:
0842:                list.addAll(Arrays.asList(services));
0843:
0844:                for (Iterator i = initial_references.keySet().iterator(); i
0845:                        .hasNext();) {
0846:                    list.add(i.next());
0847:                }
0848:
0849:                return (String[]) list.toArray(new String[list.size()]);
0850:            }
0851:
0852:            /**
0853:             * An operation from the POAListener interface. Whenever a new POA is
0854:             * created, the ORB is notified.
0855:             */
0856:            public void poaCreated(org.jacorb.poa.POA poa) {
0857:                /*
0858:                 * Add this orb as the child poa's event listener. This means that the
0859:                 * ORB is always a listener to all poa events!
0860:                 */
0861:                poa._addPOAEventListener(this );
0862:
0863:                /* If the new POA has a persistent lifetime policy, it is registered
0864:                 * with the implementation repository if there is one and the
0865:                 * use_imr policy is set via the "jacorb.orb.use_imr" property
0866:                 */
0867:
0868:                if (poa.isPersistent()) {
0869:                    persistentPOACount++;
0870:
0871:                    getImR();
0872:
0873:                    if (imr != null) {
0874:                        /* Register the POA */
0875:                        String server_name = implName;
0876:                        ProtocolAddressBase sep = getServerAddress();
0877:                        if (sep instanceof  IIOPAddress) {
0878:                            String sep_host = ((IIOPAddress) sep).getHostname();
0879:                            int sep_port = ((IIOPAddress) sep).getPort();
0880:
0881:                            imr.registerPOA(server_name + "/"
0882:                                    + poa._getQualifiedName(), server_name, // logical server name
0883:                                    sep_host, sep_port);
0884:                        }
0885:                    }
0886:                }
0887:            }
0888:
0889:            private synchronized void getImR() {
0890:                /* Lookup the implementation repository */
0891:                if (imr == null && useIMR) {
0892:                    try {
0893:                        imr = ImRAccessImpl.connect(this );
0894:                    } catch (Exception e) {
0895:                        // If we failed to resolve the IMR set the reference to null.
0896:                        if (logger.isWarnEnabled()) {
0897:                            logger
0898:                                    .warn("Error: No connection to ImplementationRepository");
0899:                        }
0900:                        if (logger.isDebugEnabled()) {
0901:                            logger.debug(e.getMessage());
0902:                        }
0903:
0904:                        if (e instanceof  org.omg.CORBA.INTERNAL) {
0905:                            throw new org.omg.CORBA.OBJ_ADAPTER(
0906:                                    "Unable to resolve ImR");
0907:                        } else if (e instanceof  org.omg.CORBA.TRANSIENT) {
0908:                            throw (org.omg.CORBA.TRANSIENT) e;
0909:                        } else {
0910:                            throw new org.omg.CORBA.OBJ_ADAPTER(e.toString());
0911:                        }
0912:                    }
0913:                }
0914:            }
0915:
0916:            /**
0917:             * Replace the server address in profile with a proxy address if necessary.
0918:             */
0919:            private void patchAddress(ProfileBase profile, String repId,
0920:                    boolean _transient) {
0921:                if ("IDL:org/jacorb/imr/ImplementationRepository:1.0"
0922:                        .equals(repId)) {
0923:                    profile.patchPrimaryAddress(imrProxyAddress);
0924:                } else if (!_transient && useIMR) {
0925:                    getImR();
0926:
0927:                    // The double call to patchPrimaryAddress ensures that either the
0928:                    // actual imr address or the environment values are patched into the
0929:                    // address, giving precedence to the latter.
0930:                    profile.patchPrimaryAddress(imr.getImRAddress());
0931:                    profile.patchPrimaryAddress(imrProxyAddress);
0932:                } else {
0933:                    profile.patchPrimaryAddress(iorProxyAddress);
0934:                }
0935:            }
0936:
0937:            /**
0938:             * Creates an ORB_TYPE_ID tagged component for JacORB.
0939:             */
0940:            private TaggedComponent create_ORB_TYPE_ID() {
0941:                final CDROutputStream out = new CDROutputStream(this );
0942:
0943:                try {
0944:                    out.beginEncapsulatedArray();
0945:                    out.write_long(ORBConstants.JACORB_ORB_ID);
0946:
0947:                    return new TaggedComponent(TAG_ORB_TYPE.value, out
0948:                            .getBufferCopy());
0949:                } finally {
0950:                    out.close();
0951:                }
0952:            }
0953:
0954:            /**
0955:             * <code>getServerAddress</code> returns the address to use to
0956:             * locate the server.  Note that this address will be overwritten
0957:             * by the ImR address in the IOR of persistent servers if the
0958:             * use_imr and use_imr_endpoint properties are switched on
0959:             *
0960:             * @return a <code>String</code>, the address for the server.
0961:             */
0962:            private synchronized ProtocolAddressBase getServerAddress() {
0963:                ProtocolAddressBase address = iorProxyAddress;
0964:
0965:                if (address == null) {
0966:                    //property not set
0967:
0968:                    List eplist = getBasicAdapter().getEndpointProfiles();
0969:                    for (Iterator i = eplist.iterator(); i.hasNext();) {
0970:                        Profile p = (Profile) i.next();
0971:                        if (p instanceof  IIOPProfile) {
0972:                            address = ((IIOPProfile) p).getAddress();
0973:                            break;
0974:                        }
0975:                    }
0976:                } else {
0977:                    if (logger.isInfoEnabled()) {
0978:                        logger.info("Using proxy address " + address.toString()
0979:                                + " in IOR");
0980:                    }
0981:                }
0982:
0983:                return address;
0984:            }
0985:
0986:            public void poaStateChanged(org.jacorb.poa.POA poa, int new_state) {
0987:                if ((new_state == org.jacorb.poa.POAConstants.DESTROYED || new_state == org.jacorb.poa.POAConstants.INACTIVE)
0988:                        && poa.isPersistent() && imr != null) {
0989:                    /* if all persistent POAs in this server have gone down, unregister
0990:                       the server */
0991:                    if (--persistentPOACount == 0) {
0992:                        imr.setServerDown(implName);
0993:                    }
0994:                }
0995:            }
0996:
0997:            public void referenceCreated(org.omg.CORBA.Object o) {
0998:            }
0999:
1000:            public boolean get_service_information(short service_type,
1001:                    org.omg.CORBA.ServiceInformationHolder service_information) {
1002:                //         if (( service_type == org.omg.CORBA.Security.value ) && Environment.supportSSL ()) {
1003:                //             byte options[] = new byte [5]; // ServiceOption[]
1004:                //             options[0] = (byte)org.omg.Security.SecurityLevel1.value;
1005:                //             options[1] = (byte)org.omg.Security.SecurityLevel2.value;
1006:                //             options[2] = (byte)org.omg.Security.ReplaceORBServices.value;
1007:                //             options[3] = (byte)org.omg.Security.ReplaceSecurityServices.value;
1008:                //             options[4] = (byte)org.omg.Security.CommonInteroperabilityLevel0.value;
1009:                //             org.omg.CORBA.ServiceDetail details[] = new org.omg.CORBA.ServiceDetail [2];
1010:                //             details[0].service_detail_type = org.omg.Security.SecureTransportType.value;
1011:                //             details[0].service_detail = org.jacorb.security.ssl.SSLSetup.getMechanismType().getBytes();
1012:                //             details[1].service_detail_type = org.omg.Security.SecureTransportType.value;
1013:                //             details[1].service_detail = "001010011".getBytes(); // AuditId, _PublicId, AccessId
1014:                //             return true;
1015:                //         }
1016:                //         else return false;
1017:                throw new org.omg.CORBA.NO_IMPLEMENT();
1018:            }
1019:
1020:            /**
1021:             * resolve_initial_references
1022:             */
1023:
1024:            public org.omg.CORBA.Object resolve_initial_references(
1025:                    String identifier)
1026:                    throws org.omg.CORBA.ORBPackage.InvalidName {
1027:                if (initial_references.containsKey(identifier)) {
1028:                    return (org.omg.CORBA.Object) initial_references
1029:                            .get(identifier);
1030:                }
1031:
1032:                org.omg.CORBA.Object obj = null;
1033:                String url = null;
1034:
1035:                try {
1036:                    url = configuration
1037:                            .getAttribute("ORBInitRef." + identifier);
1038:                } catch (Exception e) {
1039:                    // ignore
1040:                }
1041:
1042:                if (url != null) {
1043:                    try {
1044:                        obj = this .string_to_object(url);
1045:                    } catch (Exception e) {
1046:                        if (logger.isErrorEnabled()) {
1047:                            logger
1048:                                    .error("Could not create initial reference for \""
1049:                                            + identifier
1050:                                            + "\"\n"
1051:                                            + "Please check property \"ORBInitRef."
1052:                                            + identifier + '\"');
1053:                        }
1054:                        if (logger.isDebugEnabled()) {
1055:                            logger.debug(e.getMessage());
1056:                        }
1057:
1058:                        throw new org.omg.CORBA.ORBPackage.InvalidName();
1059:                    }
1060:                } else if ("RootPOA".equals(identifier)) {
1061:                    return getRootPOA();
1062:                } else if ("POACurrent".equals(identifier)) {
1063:                    return getPOACurrent();
1064:                } else if ("SecurityCurrent".equals(identifier)) {
1065:                    throw new InvalidName(
1066:                            "Level2 SecurityImplementation has been removed");
1067:                } else if ("DynAnyFactory".equals(identifier)) {
1068:                    obj = new org.jacorb.orb.dynany.DynAnyFactoryImpl(this );
1069:                } else if ("PICurrent".equals(identifier)) {
1070:                    return piCurrent;
1071:                } else if ("ORBPolicyManager".equals(identifier)) {
1072:                    if (policyManager == null) {
1073:                        policyManager = new PolicyManager(this 
1074:                                .getConfiguration());
1075:                    }
1076:                    return policyManager;
1077:                } else if ("CodecFactory".equals(identifier)) {
1078:                    obj = new CodecFactoryImpl(this );
1079:                } else if ("RTORB".equals(identifier)) {
1080:                    obj = getRTORB();
1081:                } else {
1082:                    throw new org.omg.CORBA.ORBPackage.InvalidName();
1083:                }
1084:
1085:                if (obj != null) {
1086:                    initial_references.put(identifier, obj);
1087:                }
1088:
1089:                return obj;
1090:            }
1091:
1092:            /**
1093:             * Returns the PolicyManager for ORB-wide policies.  A PolicyManager
1094:             * is only created if it is accessed via resolve_initial_references().
1095:             * If no PolicyManager has been created yet, this method returns null.
1096:             */
1097:
1098:            PolicyManager getPolicyManager() {
1099:                return policyManager;
1100:            }
1101:
1102:            private synchronized org.jacorb.orb.RTORB getRTORB() {
1103:                if (rtORB == null) {
1104:                    rtORB = new org.jacorb.orb.RTORB(this );
1105:                }
1106:                return rtORB;
1107:            }
1108:
1109:            /**
1110:             * Register a reference, that will be returned on subsequent calls
1111:             * to resove_initial_references(id). <br>
1112:             * The references "RootPOA", "POACurrent" and "PICurrent" can be set,
1113:             * but will not be resolved with the passed in references.
1114:             * <p>
1115:             * Overrides  register_initial_reference() in org.omg.CORBA_2_5.ORB
1116:             *
1117:             * @param id The references human-readable id, e.g. "MyService".
1118:             * @param obj The objects reference.
1119:             * @exception InvalidName A reference with id has already been registered.
1120:             */
1121:
1122:            public void register_initial_reference(String id,
1123:                    org.omg.CORBA.Object obj) throws InvalidName {
1124:                if (id == null || id.length() == 0
1125:                        || initial_references.containsKey(id)) {
1126:                    throw new InvalidName();
1127:                }
1128:
1129:                if (logger.isDebugEnabled()) {
1130:                    logger.debug("Registering initial ref " + id);
1131:                }
1132:
1133:                initial_references.put(id, obj);
1134:            }
1135:
1136:            public void run() {
1137:                if (logger.isInfoEnabled()) {
1138:                    logger.info("ORB run");
1139:                }
1140:
1141:                synchronized (runSync) {
1142:                    try {
1143:                        while (run) {
1144:                            runSync.wait();
1145:                        }
1146:                    } catch (InterruptedException ex) {
1147:                    }
1148:                }
1149:
1150:                if (logger.isInfoEnabled()) {
1151:                    logger.info("ORB run, exit");
1152:                }
1153:            }
1154:
1155:            public void send_multiple_requests_oneway(
1156:                    org.omg.CORBA.Request[] req) {
1157:                for (int i = 0; i < req.length; i++) {
1158:                    req[i].send_oneway();
1159:                }
1160:            }
1161:
1162:            public void send_multiple_requests_deferred(
1163:                    org.omg.CORBA.Request[] req) {
1164:                for (int i = 0; i < req.length; i++) {
1165:                    req[i].send_deferred();
1166:                }
1167:            }
1168:
1169:            public boolean poll_next_response() {
1170:                if (requests.size() == 0) {
1171:                    throw new org.omg.CORBA.BAD_INV_ORDER(11,
1172:                            org.omg.CORBA.CompletionStatus.COMPLETED_NO);
1173:                }
1174:
1175:                synchronized (requests) {
1176:                    Request req;
1177:                    Iterator iter = requests.iterator();
1178:                    while (iter.hasNext()) {
1179:                        req = (Request) iter.next();
1180:                        if (req.poll_response()) {
1181:                            request = req;
1182:                            return true;
1183:                        }
1184:                    }
1185:                }
1186:                return false;
1187:            }
1188:
1189:            public org.omg.CORBA.Request get_next_response() {
1190:                if (requests.size() == 0) {
1191:                    throw new org.omg.CORBA.BAD_INV_ORDER(11,
1192:                            org.omg.CORBA.CompletionStatus.COMPLETED_NO);
1193:                }
1194:
1195:                synchronized (requests) {
1196:                    Request req = null;
1197:                    if (request != null) {
1198:                        request.get_response();
1199:                        req = request;
1200:                        request = null;
1201:                        return req;
1202:                    }
1203:
1204:                    Iterator iter;
1205:                    while (true) {
1206:                        iter = requests.iterator();
1207:                        while (iter.hasNext()) {
1208:                            req = (Request) iter.next();
1209:                            if (req.poll_response()) {
1210:                                req.get_response();
1211:                                return req;
1212:                            }
1213:                        }
1214:                    }
1215:                }
1216:            }
1217:
1218:            public void addRequest(org.omg.CORBA.Request req) {
1219:                requests.add(req);
1220:            }
1221:
1222:            public void removeRequest(org.omg.CORBA.Request req) {
1223:                requests.remove(req);
1224:            }
1225:
1226:            /**
1227:             * called from ORB.init(), entry point for initialization.
1228:             */
1229:
1230:            protected void set_parameters(String[] args,
1231:                    java.util.Properties props) {
1232:                try {
1233:                    configure(org.jacorb.config.JacORBConfiguration
1234:                            .getConfiguration(props, this , false)); // no applet support
1235:                } catch (ConfigurationException ce) {
1236:                    if (logger != null && logger.isErrorEnabled()) {
1237:                        logger.error("error during configuration", ce);
1238:                    } else {
1239:                        ce.printStackTrace();
1240:                    }
1241:
1242:                    throw new org.omg.CORBA.INITIALIZE(ce.getMessage());
1243:                }
1244:
1245:                /*
1246:                 * find -ORBInitRef args and add them to Environment
1247:                 * (overwriting existing props).
1248:                 */
1249:
1250:                if (args != null) {
1251:                    _args = args;
1252:                    for (int i = 0; i < args.length; i++) {
1253:                        String arg = args[i].trim();
1254:
1255:                        if (arg.startsWith("-ORBInitRef.")) {
1256:                            //This is the wrong jacorb form -ORBInitRef.<name>=<val>
1257:
1258:                            //get rid of the leading `-'
1259:                            String prop = arg.substring(1);
1260:
1261:                            //find the equals char that separates prop name from
1262:                            //prop value
1263:                            int equals_pos = prop.indexOf('=');
1264:                            if (equals_pos == -1) {
1265:                                throw new org.omg.CORBA.BAD_PARAM(
1266:                                        "InitRef format invalid for " + prop);
1267:                            }
1268:
1269:                            //add the property to environment
1270:                            ((DefaultConfiguration) configuration)
1271:                                    .setAttribute(
1272:                                            prop.substring(0, equals_pos), prop
1273:                                                    .substring(equals_pos + 1));
1274:                        } else if ("-ORBInitRef".equals(arg)) {
1275:                            //This is the compliant form -ORBInitRef <name>=<val>
1276:
1277:                            //Is there a next arg?
1278:                            if ((args.length - 1) < (i + 1)) {
1279:                                logger
1280:                                        .error("WARNING: -ORBInitRef argument without value");
1281:
1282:                                throw new BAD_PARAM(
1283:                                        "-ORBInitRef argument without value");
1284:                            }
1285:
1286:                            String prop = args[++i].trim();
1287:
1288:                            //find the equals char that separates prop name from
1289:                            //prop value
1290:                            int equals_pos = prop.indexOf('=');
1291:                            if (equals_pos == -1) {
1292:                                throw new org.omg.CORBA.BAD_PARAM(
1293:                                        "InitRef format invalid for " + prop);
1294:                            }
1295:
1296:                            //add the property to environment
1297:                            ((DefaultConfiguration) configuration)
1298:                                    .setAttribute("ORBInitRef."
1299:                                            + prop.substring(0, equals_pos),
1300:                                            prop.substring(equals_pos + 1));
1301:                        }
1302:                    }
1303:                }
1304:
1305:                internalInit();
1306:            }
1307:
1308:            /**
1309:             * Initialization method, called from within the super class
1310:             * org.omg.CORBA.ORB
1311:             */
1312:
1313:            protected void set_parameters(java.applet.Applet app,
1314:                    java.util.Properties props) {
1315:                try {
1316:                    configure(org.jacorb.config.JacORBConfiguration
1317:                            .getConfiguration(props, this , true)); //applet support
1318:                } catch (ConfigurationException e) {
1319:                    logger.fatalError(
1320:                            "configuration exception during configure", e);
1321:
1322:                    throw new org.omg.CORBA.INITIALIZE(e.toString());
1323:                }
1324:
1325:                internalInit();
1326:            }
1327:
1328:            private void internalInit() {
1329:                final List orb_initializers = getORBInitializers();
1330:                final ORBInitInfoImpl initInfo = new ORBInitInfoImpl(this );
1331:
1332:                interceptorPreInit(orb_initializers, initInfo);
1333:
1334:                initClientConnectionManager();
1335:
1336:                initKnownReferencesMap();
1337:
1338:                interceptorPostInit(orb_initializers, initInfo);
1339:
1340:                internalInit(initInfo);
1341:            }
1342:
1343:            private void initClientConnectionManager() {
1344:                try {
1345:                    clientConnectionManager = new ClientConnectionManager(this ,
1346:                            getTransportManager(), getGIOPConnectionManager());
1347:                    clientConnectionManager.configure(configuration);
1348:                } catch (ConfigurationException ce) {
1349:                    logger.fatalError("unexpected exception", ce);
1350:                    throw new INTERNAL(ce.toString());
1351:                }
1352:            }
1353:
1354:            private void initKnownReferencesMap() {
1355:                if (logger.isInfoEnabled()) {
1356:                    logger
1357:                            .info("Property \"jacorb.hashtable_class\" is set to: "
1358:                                    + hashTableClassName);
1359:                }
1360:
1361:                try {
1362:                    knownReferences = (Map) ObjectUtil.classForName(
1363:                            hashTableClassName).newInstance();
1364:                } catch (Exception e) {
1365:                    logger.fatalError("unable to create known references map",
1366:                            e);
1367:                    throw new INTERNAL(e.toString());
1368:                }
1369:            }
1370:
1371:            /**
1372:             * configure this ORB with the information collected
1373:             * from the different configured ORBInitializers
1374:             */
1375:            private void internalInit(ORBInitInfoImpl info) {
1376:                // allow no more access to ORBInitInfo from ORBInitializers
1377:                info.setInvalid();
1378:
1379:                List client_interceptors = info.getClientInterceptors();
1380:                List server_interceptors = info.getServerInterceptors();
1381:                List ior_intercept = info.getIORInterceptors();
1382:
1383:                hasClientInterceptors = !client_interceptors.isEmpty();
1384:                hasServerInterceptors = !server_interceptors.isEmpty();
1385:
1386:                if (hasClientInterceptors || hasServerInterceptors
1387:                        || (!ior_intercept.isEmpty())) {
1388:                    interceptor_manager = new InterceptorManager(
1389:                            client_interceptors, server_interceptors,
1390:                            ior_intercept, info.getSlotCount(), this );
1391:                }
1392:
1393:                // add PolicyFactories to ORB
1394:                policy_factories.putAll(info.getPolicyFactories());
1395:            }
1396:
1397:            /**
1398:             * call pre_init on ORBInitializers
1399:             */
1400:            private void interceptorPreInit(List orb_initializers,
1401:                    final ORBInitInfo info) {
1402:                for (Iterator i = orb_initializers.iterator(); i.hasNext();) {
1403:                    final ORBInitializer initializer = (ORBInitializer) i
1404:                            .next();
1405:                    try {
1406:                        initializer.pre_init(info);
1407:                    } catch (Exception e) {
1408:                        if (failOnORBInitializerError) {
1409:                            logger
1410:                                    .error(
1411:                                            initializer.getClass().getName()
1412:                                                    + ": aborting due to error during ORBInitializer::pre_init",
1413:                                            e);
1414:
1415:                            throw new INITIALIZE(e.toString());
1416:                        }
1417:
1418:                        logger
1419:                                .warn(
1420:                                        initializer.getClass().getName()
1421:                                                + ": ignoring error during ORBInitializer::pre_init. the ORBInitializer will be removed from the current configuration",
1422:                                        e);
1423:                        i.remove();
1424:                    }
1425:                }
1426:            }
1427:
1428:            /**
1429:             * call post_init on ORBInitializers
1430:             */
1431:            private void interceptorPostInit(List orb_initializers,
1432:                    ORBInitInfo info) {
1433:                for (Iterator i = orb_initializers.iterator(); i.hasNext();) {
1434:                    ORBInitializer initializer = (ORBInitializer) i.next();
1435:                    try {
1436:                        initializer.post_init(info);
1437:                    } catch (Exception e) {
1438:                        if (failOnORBInitializerError) {
1439:                            logger
1440:                                    .error(
1441:                                            initializer.getClass().getName()
1442:                                                    + ": aborting due to error during ORBInitializer::pre_init",
1443:                                            e);
1444:
1445:                            throw new INITIALIZE(e.toString());
1446:                        }
1447:
1448:                        logger
1449:                                .warn(
1450:                                        initializer.getClass().getName()
1451:                                                + ": ignoring error during ORBInitializer::pre_init. the ORBInitializer will be removed from the current configuration",
1452:                                        e);
1453:                    }
1454:                }
1455:            }
1456:
1457:            /**
1458:             * Collects all properties with prefix "org.omg.PortableInterceptor.ORBInitializerClass."
1459:             * and try to instantiate their values as ORBInitializer-Classes.
1460:             *
1461:             * @return a List containing ORBInitializer instances
1462:             */
1463:            private List getORBInitializers() {
1464:                final List orb_initializers = new ArrayList();
1465:                final String initializer_prefix = "org.omg.PortableInterceptor.ORBInitializerClass.";
1466:                final List prop_names = configuration
1467:                        .getAttributeNamesWithPrefix(initializer_prefix);
1468:
1469:                for (Iterator i = prop_names.iterator(); i.hasNext();) {
1470:                    final String prop_name = (String) i.next();
1471:                    String name = configuration.getAttribute(prop_name, "");
1472:
1473:                    if (name.length() == 0
1474:                            && prop_name.length() > initializer_prefix.length()) {
1475:                        name = prop_name.substring(initializer_prefix.length());
1476:                    }
1477:
1478:                    if (name == null) {
1479:                        continue;
1480:                    }
1481:
1482:                    try {
1483:                        final Object newInstance = ObjectUtil
1484:                                .classForName(name).newInstance();
1485:
1486:                        if (newInstance instanceof  ORBInitializer) {
1487:                            orb_initializers.add(newInstance);
1488:                            if (logger.isDebugEnabled()) {
1489:                                logger.debug("added ORBInitializer: " + name);
1490:                            }
1491:                        } else if (failOnORBInitializerError) {
1492:                            logger
1493:                                    .error("aborting due to wrong configuration for property "
1494:                                            + prop_name
1495:                                            + ": "
1496:                                            + name
1497:                                            + " is not an ORBInitializer");
1498:                            throw new BAD_PARAM(
1499:                                    "Wrong configuration for property "
1500:                                            + prop_name + ": " + name
1501:                                            + " is not an ORBInitializer");
1502:                        } else {
1503:                            logger
1504:                                    .warn("ignoring wrong configuration for property "
1505:                                            + prop_name
1506:                                            + ": "
1507:                                            + name
1508:                                            + " is not an ORBInitializer");
1509:                        }
1510:                    } catch (Exception e) {
1511:                        if (failOnORBInitializerError) {
1512:                            logger.error(
1513:                                    "unable to build ORBInitializer from class "
1514:                                            + name + ": Aborting", e);
1515:
1516:                            throw new INITIALIZE(e.toString());
1517:                        }
1518:
1519:                        logger
1520:                                .warn("unable to build ORBInitializer from class "
1521:                                        + name + ": Ignoring");
1522:                    }
1523:                }
1524:
1525:                return orb_initializers;
1526:            }
1527:
1528:            public void shutdown(boolean wait_for_completion) {
1529:                if (logger.isInfoEnabled()) {
1530:                    logger.info("prepare ORB for shutdown...");
1531:                }
1532:
1533:                synchronized (shutdown_synch) {
1534:                    if (shutdown_in_progress && !wait_for_completion) {
1535:                        if (logger.isDebugEnabled()) {
1536:                            logger.debug("ORB is already shutting down.");
1537:                        }
1538:                        return;
1539:                    }
1540:
1541:                    while (shutdown_in_progress) {
1542:                        try {
1543:                            shutdown_synch.wait();
1544:                        } catch (InterruptedException ie) {
1545:                            // ignore
1546:                        }
1547:                    }
1548:
1549:                    shutdown_in_progress = true;
1550:                }
1551:
1552:                if (!isRunning()) {
1553:                    // ORB is already down.
1554:                    synchronized (shutdown_synch) {
1555:                        shutdown_in_progress = false;
1556:                        shutdown_synch.notifyAll();
1557:                    }
1558:
1559:                    return;
1560:                }
1561:
1562:                logger.info("ORB going down...");
1563:
1564:                if (rootpoa != null) {
1565:                    rootpoa.destroy(true, wait_for_completion);
1566:                    rootpoa = null;
1567:                }
1568:
1569:                if (basicAdapter != null) {
1570:                    basicAdapter.stopListeners();
1571:                }
1572:
1573:                if (giop_connection_manager != null) {
1574:                    giop_connection_manager.shutdown();
1575:                }
1576:
1577:                clientConnectionManager.shutdown();
1578:                knownReferences.clear();
1579:                bufferManager.release();
1580:
1581:                poolManagerFactory.destroy();
1582:
1583:                // notify all threads waiting in orb.run()
1584:                synchronized (runSync) {
1585:                    run = false;
1586:                    runSync.notifyAll();
1587:                }
1588:
1589:                // notify all threads waiting for shutdown to complete
1590:                synchronized (shutdown_synch) {
1591:                    shutdown_in_progress = false;
1592:                    shutdown_synch.notifyAll();
1593:                }
1594:
1595:                if (logger.isInfoEnabled()) {
1596:                    logger.info("ORB shutdown complete");
1597:                }
1598:            }
1599:
1600:            public void destroy() {
1601:                if (destroyed) {
1602:                    throw new org.omg.CORBA.OBJECT_NOT_EXIST();
1603:                }
1604:
1605:                synchronized (runSync) {
1606:                    if (run) {
1607:                        shutdown(true);
1608:                    }
1609:                }
1610:
1611:                if (interceptor_manager != null) {
1612:                    interceptor_manager.destroy();
1613:                }
1614:
1615:                // other clean up possible here ?
1616:                destroyed = true;
1617:            }
1618:
1619:            public org.omg.CORBA.Object string_to_object(String str) {
1620:                perform_work();
1621:
1622:                if (str == null) {
1623:                    return null;
1624:                }
1625:
1626:                try {
1627:                    ParsedIOR pior = new ParsedIOR(this , str);
1628:                    if (pior.isNull()) {
1629:                        return null;
1630:                    }
1631:
1632:                    return _getObject(pior);
1633:                } catch (Exception e) {
1634:                    if (logger.isErrorEnabled()) {
1635:                        logger.error(
1636:                                "Exception while converting string to object",
1637:                                e);
1638:                    }
1639:                    throw new BAD_PARAM(10, CompletionStatus.COMPLETED_NO);
1640:                }
1641:            }
1642:
1643:            /**
1644:             * always return a ValueDef or throw BAD_PARAM if not repid of a value
1645:             */
1646:
1647:            public org.omg.CORBA.Object get_value_def(String repid)
1648:                    throws org.omg.CORBA.BAD_PARAM {
1649:                throw new org.omg.CORBA.NO_IMPLEMENT();
1650:            }
1651:
1652:            /**
1653:             * called by org.jacorb.poa.RequestProcessor
1654:             */
1655:            public void set_delegate(java.lang.Object wrapper) {
1656:                if (!(wrapper instanceof  org.omg.PortableServer.Servant)) {
1657:                    throw new org.omg.CORBA.BAD_PARAM(
1658:                            "Argument must be of type org.omg.PortableServer.Servant");
1659:                }
1660:
1661:                try {
1662:                    ((org.omg.PortableServer.Servant) wrapper)._get_delegate();
1663:                } catch (org.omg.CORBA.BAD_INV_ORDER bio) {
1664:                    // only set the delegate if it has not been set already
1665:                    org.jacorb.orb.ServantDelegate delegate = new org.jacorb.orb.ServantDelegate(
1666:                            this );
1667:                    ((org.omg.PortableServer.Servant) wrapper)
1668:                            ._set_delegate(delegate);
1669:                }
1670:            }
1671:
1672:            public String object_to_string(org.omg.CORBA.Object obj) {
1673:                perform_work();
1674:
1675:                if (obj == null) {
1676:                    return nullIORString;
1677:                }
1678:
1679:                if (obj instanceof  org.omg.CORBA.LocalObject) {
1680:                    throw new org.omg.CORBA.MARSHAL(
1681:                            "Attempt to stringify a local object");
1682:                }
1683:
1684:                Object delegate = ((org.omg.CORBA.portable.ObjectImpl) obj)
1685:                        ._get_delegate();
1686:                if (delegate instanceof  org.jacorb.orb.Delegate) {
1687:                    return delegate.toString();
1688:                }
1689:
1690:                throw new BAD_PARAM("Argument has a delegate whose class is "
1691:                        + delegate.getClass().getName()
1692:                        + ", a org.jacorb.orb.Delegate was expected");
1693:            }
1694:
1695:            public void perform_work() {
1696:                work_pending();
1697:            }
1698:
1699:            public boolean work_pending() {
1700:                if (!isRunning()) {
1701:                    if (logger.isDebugEnabled()) {
1702:                        logger.debug("ORB has been shutdown");
1703:                    }
1704:
1705:                    throw new org.omg.CORBA.BAD_INV_ORDER(4,
1706:                            org.omg.CORBA.CompletionStatus.COMPLETED_NO);
1707:                }
1708:
1709:                return false;
1710:            }
1711:
1712:            public ValueFactory register_value_factory(String id,
1713:                    ValueFactory factory) {
1714:                return (ValueFactory) valueFactories.put(id, factory);
1715:            }
1716:
1717:            public void unregister_value_factory(String id) {
1718:                valueFactories.remove(id);
1719:            }
1720:
1721:            public ValueFactory lookup_value_factory(String id) {
1722:                ValueFactory result = (ValueFactory) valueFactories.get(id);
1723:
1724:                if (result == null && id.startsWith("IDL")) {
1725:                    String valueName = org.jacorb.ir.RepositoryID.className(id,
1726:                            null);
1727:                    result = findValueFactory(valueName);
1728:                    valueFactories.put(id, result);
1729:                }
1730:                return result;
1731:            }
1732:
1733:            /**
1734:             * Finds a ValueFactory for class valueName by trying standard class names.
1735:             */
1736:
1737:            private ValueFactory findValueFactory(String valueName) {
1738:                Class result = findClass(valueName + "DefaultFactory", true);
1739:                if (result != null) {
1740:                    return (ValueFactory) instantiate(result);
1741:                }
1742:
1743:                // Extension of the standard: Handle the common case
1744:                // when the Impl class is its own factory...
1745:                Class clazz = findClass(valueName, false);
1746:                result = findClass(valueName + "Impl", false);
1747:
1748:                if (result != null && clazz.isAssignableFrom(result)) {
1749:                    if (ValueFactory.class.isAssignableFrom(result)) {
1750:                        return (ValueFactory) instantiate(result);
1751:                    }
1752:
1753:                    // ... or create a factory on the fly
1754:                    return new JacORBValueFactory(result);
1755:                }
1756:                return null;
1757:            }
1758:
1759:            /**
1760:             * Internal value factory class.  This can be used for any value
1761:             * implementation that has a no-arg constructor.
1762:             */
1763:            private class JacORBValueFactory implements 
1764:                    org.omg.CORBA.portable.ValueFactory {
1765:                private final Class implementationClass;
1766:
1767:                public JacORBValueFactory(Class clazz) {
1768:                    super ();
1769:
1770:                    implementationClass = clazz;
1771:                }
1772:
1773:                public java.io.Serializable read_value(
1774:                        org.omg.CORBA_2_3.portable.InputStream is) {
1775:                    java.lang.Object implObj = instantiate(implementationClass);
1776:
1777:                    if (implObj instanceof  org.omg.CORBA.portable.Streamable) {
1778:                        StreamableValue value = (StreamableValue) instantiate(implementationClass);
1779:
1780:                        return is.read_value(value);
1781:                    } else if (implObj instanceof  org.omg.CORBA.portable.CustomValue) {
1782:                        ((org.omg.CORBA.portable.CustomValue) implObj)
1783:                                .unmarshal(new DataInputStream(is));
1784:
1785:                        return ((org.omg.CORBA.portable.CustomValue) implObj);
1786:                    } else {
1787:                        throw new MARSHAL("Unknown Value type " + implObj);
1788:                    }
1789:                }
1790:            }
1791:
1792:            /**
1793:             * Returns the class object for `name', if it exists, otherwise
1794:             * returns null.  If `orgomg' is true, and `name' starts with "org.omg",
1795:             * do a double-take using "omg.org" as the prefix.
1796:             */
1797:            private Class findClass(String name, boolean orgomg) {
1798:                Class result = null;
1799:                try {
1800:                    result = ObjectUtil.classForName(name);
1801:                } catch (ClassNotFoundException e) {
1802:                    if (orgomg && name.startsWith("org.omg")) {
1803:                        try {
1804:                            result = ObjectUtil.classForName("omg.org"
1805:                                    + name.substring(7));
1806:                        } catch (ClassNotFoundException x) {
1807:                            // nothing, result is null
1808:                        }
1809:                    }
1810:                }
1811:                return result;
1812:            }
1813:
1814:            /**
1815:             * Instantiates class `clazz' using its no-arg constructor.  Throws a
1816:             * run-time exception if that fails.
1817:             */
1818:            private Object instantiate(Class clazz) {
1819:                try {
1820:                    return clazz.newInstance();
1821:                } catch (IllegalAccessException e) {
1822:                    throw new IllegalArgumentException(
1823:                            "cannot instantiate class " + clazz.getName()
1824:                                    + " (IllegalAccessException)");
1825:                } catch (InstantiationException e) {
1826:                    throw new IllegalArgumentException(
1827:                            "cannot instantiate class " + clazz.getName()
1828:                                    + " (InstantiationException)");
1829:                }
1830:            }
1831:
1832:            /**
1833:             * Returns a BoxedValueHelper for the type specified by repId, or
1834:             * null if no such BoxedValueHelper can be found.  This method uses an
1835:             * internal cache of BoxedValueHelpers so that each class needs only
1836:             * be looked up once.
1837:             *
1838:             * @param repId the repository id of the type for which a BoxedValueHelper
1839:             * should be returned.  It is assumed that repId is the repository id of a
1840:             * boxed value type.  Otherwise, the result will be null.
1841:             * @return an instance of the BoxedValueHelper class that corresponds
1842:             * to repId.
1843:             */
1844:
1845:            public BoxedValueHelper getBoxedValueHelper(String repId) {
1846:                BoxedValueHelper result = (BoxedValueHelper) boxedValueHelpers
1847:                        .get(repId);
1848:                if (result == null) {
1849:                    if (boxedValueHelpers.containsKey(repId)) {
1850:                        return null;
1851:                    }
1852:
1853:                    result = org.jacorb.ir.RepositoryID.createBoxedValueHelper(
1854:                            repId, null);
1855:                    boxedValueHelpers.put(repId, result);
1856:                }
1857:                return result;
1858:            }
1859:
1860:            /**
1861:             * Test, if the ORB has ClientRequestInterceptors <br>
1862:             * Called by Delegate.
1863:             */
1864:
1865:            public boolean hasClientRequestInterceptors() {
1866:                return hasClientInterceptors;
1867:            }
1868:
1869:            /**
1870:             * Test, if the ORB has ServerRequestInterceptors <br>
1871:             * Called by poa.RequestProcessor.
1872:             */
1873:
1874:            public boolean hasServerRequestInterceptors() {
1875:                return hasServerInterceptors;
1876:            }
1877:
1878:            /**
1879:             * Test, if the ORB has client or server side interceptors.
1880:             */
1881:
1882:            public boolean hasRequestInterceptors() {
1883:                return (hasServerInterceptors || hasClientInterceptors);
1884:            }
1885:
1886:            /**
1887:             * Get the InterceptorManager, if present.
1888:             *
1889:             * @return the InterceptorManager, or null, if none is present.
1890:             */
1891:
1892:            public org.jacorb.orb.portableInterceptor.InterceptorManager getInterceptorManager() {
1893:                return interceptor_manager;
1894:            }
1895:
1896:            public synchronized TransportManager getTransportManager() {
1897:                if (transport_manager == null) {
1898:                    transport_manager = new TransportManager(this );
1899:                    try {
1900:                        transport_manager.configure(configuration);
1901:                    } catch (ConfigurationException e) {
1902:                        throw new INITIALIZE(e.toString());
1903:                    }
1904:                }
1905:                return transport_manager;
1906:            }
1907:
1908:            /* DII helper methods */
1909:
1910:            public org.omg.CORBA.ExceptionList create_exception_list() {
1911:                return new org.jacorb.orb.dii.ExceptionList();
1912:            }
1913:
1914:            public org.omg.CORBA.NVList create_list(int count) {
1915:                return new org.jacorb.orb.NVList(this , count);
1916:            }
1917:
1918:            public org.omg.CORBA.NamedValue create_named_value(String name,
1919:                    org.omg.CORBA.Any value, int flags) {
1920:                return new org.jacorb.orb.NamedValue(name, value, flags);
1921:            }
1922:
1923:            public org.omg.CORBA.NVList create_operation_list(
1924:                    org.omg.CORBA.Object obj) {
1925:                org.omg.CORBA.OperationDef oper;
1926:
1927:                if (obj instanceof  org.omg.CORBA.OperationDef) {
1928:                    oper = (org.omg.CORBA.OperationDef) obj;
1929:                } else {
1930:                    throw new org.omg.CORBA.BAD_PARAM(
1931:                            "Argument must be of type org.omg.CORBA.OperationDef");
1932:                }
1933:                return (create_operation_list(oper));
1934:            }
1935:
1936:            /**
1937:             * @deprecated use {@link #create_operation_list (org.omg.CORBA.Object)} instead
1938:             */
1939:            public org.omg.CORBA.NVList create_operation_list(
1940:                    org.omg.CORBA.OperationDef oper) {
1941:                int no = 0;
1942:                final org.omg.CORBA.ParameterDescription[] params = oper
1943:                        .params();
1944:
1945:                if (params != null) {
1946:                    no = params.length;
1947:                }
1948:
1949:                final org.omg.CORBA.NVList list = new org.jacorb.orb.NVList(
1950:                        this , no);
1951:
1952:                for (int i = 0; i < no; i++) {
1953:                    org.omg.CORBA.ParameterDescription param = params[i];
1954:                    org.omg.CORBA.Any any = create_any();
1955:                    any.type(param.type);
1956:                    switch (param.mode.value()) {
1957:                    case org.omg.CORBA.ParameterMode._PARAM_IN: {
1958:                        list.add_value(param.name, any,
1959:                                org.omg.CORBA.ARG_IN.value);
1960:                        break;
1961:                    }
1962:                    case org.omg.CORBA.ParameterMode._PARAM_OUT: {
1963:                        list.add_value(param.name, any,
1964:                                org.omg.CORBA.ARG_OUT.value);
1965:                        break;
1966:                    }
1967:                    case org.omg.CORBA.ParameterMode._PARAM_INOUT: {
1968:                        list.add_value(param.name, any,
1969:                                org.omg.CORBA.ARG_INOUT.value);
1970:                        break;
1971:                    }
1972:                    default: {
1973:                        throw new BAD_PARAM("Invalid value for ParamaterMode");
1974:                    }
1975:                    }
1976:                }
1977:
1978:                return list;
1979:            }
1980:
1981:            /**
1982:             * a helper method supplied to initialize the object key map. This
1983:             * replaces functionality from the defunct Environment class to populate
1984:             * a hash map based on the names starting with "jacorb.orb.ObjectKeyMap"
1985:             */
1986:            private void configureObjectKeyMap(Configuration config) {
1987:                final String prefix = "jacorb.orb.objectKeyMap.";
1988:                final org.jacorb.config.Configuration configuration = (org.jacorb.config.Configuration) config;
1989:                final List names = configuration
1990:                        .getAttributeNamesWithPrefix(prefix);
1991:
1992:                try {
1993:                    for (Iterator i = names.iterator(); i.hasNext();) {
1994:                        String name = (String) i.next();
1995:                        objectKeyMap.put(name.substring(prefix.length()),
1996:                                configuration.getAttribute(name));
1997:                    }
1998:                } catch (ConfigurationException e) {
1999:                    logger.fatalError("unexpected exception", e);
2000:                    throw new INTERNAL(e.toString());
2001:                }
2002:            }
2003:
2004:            /**
2005:             * <code>addObjectKey </code> is a proprietary method that allows the
2006:             * internal objectKeyMap to be altered programmatically. The objectKeyMap
2007:             * allows more readable corbaloc URLs by mapping the actual object key to
2008:             * an arbitary string. See the jacorb.properties file for more information.
2009:             *
2010:             * @param key_name a <code>String</code> value e.g. NameService
2011:             * @param full_path an <code>String</code> value e.g. file:/home/rnc/NameSingleton.ior
2012:             */
2013:            public void addObjectKey(String key_name, String full_path) {
2014:                objectKeyMap.put(key_name, full_path);
2015:            }
2016:
2017:            /**
2018:             * Map an object key to another, as defined by the value
2019:             * of a corresponding configuration property in the properties
2020:             * file, e.g. map "NameService" to "StandardNS/NameServer-POA/_root"
2021:             *
2022:             * @param originalKey a <code>byte[]</code> value containing the original
2023:             * key.
2024:             * @return a <code>byte[]</code> value containing the mapped key, if a
2025:             * mapping is defined, originalKey otherwise.
2026:             */
2027:            public byte[] mapObjectKey(byte[] originalKey) {
2028:                ParsedIOR pIOR = null;
2029:                String found = null;
2030:                String original = null;
2031:
2032:                if (objectKeyMap.size() != 0) {
2033:                    original = new String(originalKey);
2034:                    found = (String) objectKeyMap.get(original);
2035:
2036:                    if (found != null) {
2037:                        if (ParsedIOR.isParsableProtocol(found)) {
2038:                            // We have found a file reference. Use ParsedIOR to get
2039:                            // the byte key.
2040:                            try {
2041:                                pIOR = new ParsedIOR(this , found);
2042:                                return pIOR.get_object_key();
2043:                            } catch (IllegalArgumentException e) {
2044:                                if (logger.isDebugEnabled()) {
2045:                                    logger
2046:                                            .debug("Error - could not read protocol "
2047:                                                    + found);
2048:                                }
2049:                                return originalKey;
2050:                            }
2051:                        }
2052:
2053:                        return org.jacorb.orb.util.CorbaLoc.parseKey(found);
2054:                    }
2055:                }
2056:                // else:
2057:                return originalKey;
2058:            }
2059:
2060:            boolean isRunning() {
2061:                synchronized (runSync) {
2062:                    return run;
2063:                }
2064:            }
2065:
2066:            /**
2067:             * Inner class that implements org.omg.PortableInterceptor.Current
2068:             * by forwarding each invocation to a thread-dependent target.
2069:             */
2070:            private class PICurrent extends org.omg.CORBA.LocalObject implements 
2071:                    org.omg.PortableInterceptor.Current {
2072:                // Helper method that returns the actual
2073:                // target of a PICurrent invocation
2074:                private Current getTarget() {
2075:                    if (interceptor_manager == null) {
2076:                        return InterceptorManager.EMPTY_CURRENT;
2077:                    }
2078:
2079:                    return interceptor_manager.getCurrent();
2080:                }
2081:
2082:                // org.omg.PortableInterceptor.Current implementation ---
2083:
2084:                public org.omg.CORBA.Any get_slot(int id) throws InvalidSlot {
2085:                    return getTarget().get_slot(id);
2086:                }
2087:
2088:                public void set_slot(int id, org.omg.CORBA.Any data)
2089:                        throws InvalidSlot {
2090:                    getTarget().set_slot(id, data);
2091:                }
2092:            }
2093:
2094:            // Even though the methods connect(obj) and disconnect(obj) are
2095:            // deprecated, they are implemented here because the server-side
2096:            // programming model traditionally used by RMI/IIOP strongly relies
2097:            // on them.
2098:
2099:            /**
2100:             * Indicates that the root POA manager was not yet activated.
2101:             */
2102:            private boolean firstConnection = true;
2103:
2104:            /**
2105:             * Associates connected objects to their servants. The servant associated
2106:             * with a connected object is retrieved from this map when disconnect is
2107:             * called on the object.
2108:             */
2109:            private Map connectedObjects = new HashMap();
2110:
2111:            /**
2112:             * Servant class used by connect and disconnect
2113:             */
2114:            static class HandlerWrapper extends org.omg.PortableServer.Servant
2115:                    implements  org.omg.CORBA.portable.InvokeHandler {
2116:                private final org.omg.CORBA.portable.InvokeHandler wrappedHandler;
2117:
2118:                public HandlerWrapper(
2119:                        org.omg.CORBA.portable.ObjectImpl objectImpl) {
2120:                    wrappedHandler = (org.omg.CORBA.portable.InvokeHandler) objectImpl;
2121:                }
2122:
2123:                public String[] _all_interfaces(org.omg.PortableServer.POA poa,
2124:                        byte[] objectID) {
2125:                    return ((org.omg.CORBA.portable.ObjectImpl) wrappedHandler)
2126:                            ._ids();
2127:                }
2128:
2129:                public org.omg.CORBA.portable.OutputStream _invoke(
2130:                        String method,
2131:                        org.omg.CORBA.portable.InputStream input,
2132:                        org.omg.CORBA.portable.ResponseHandler handler)
2133:                        throws org.omg.CORBA.SystemException {
2134:                    return wrappedHandler._invoke(method, input, handler);
2135:                }
2136:
2137:            }
2138:
2139:            public void connect(org.omg.CORBA.Object obj) {
2140:                if (!(obj instanceof  org.omg.CORBA.portable.ObjectImpl)) {
2141:                    throw new BAD_PARAM("connect parameter must extend "
2142:                            + "org.omg.CORBA.portable.ObjectImpl");
2143:                }
2144:
2145:                if (!(obj instanceof  org.omg.CORBA.portable.InvokeHandler)) {
2146:                    throw new BAD_PARAM("connect parameter must implement "
2147:                            + "org.omg.CORBA.portable.InvokeHandler");
2148:                }
2149:
2150:                synchronized (connectedObjects) {
2151:                    if (connectedObjects.containsKey(obj) == false) {
2152:                        org.omg.CORBA.portable.ObjectImpl objectImpl = (org.omg.CORBA.portable.ObjectImpl) obj;
2153:                        org.omg.PortableServer.Servant servant = new HandlerWrapper(
2154:                                objectImpl);
2155:                        org.omg.CORBA.Object ref = servant._this _object(this );
2156:                        objectImpl
2157:                                ._set_delegate(((org.omg.CORBA.portable.ObjectImpl) ref)
2158:                                        ._get_delegate());
2159:                        connectedObjects.put(obj, servant);
2160:                        if (firstConnection) {
2161:                            firstConnection = false;
2162:                            org.omg.PortableServer.POAManager rootPOAManager = getRootPOA()
2163:                                    .the_POAManager();
2164:                            if (rootPOAManager.get_state() == State.HOLDING) {
2165:                                try {
2166:                                    rootPOAManager.activate();
2167:                                } catch (AdapterInactive e) {
2168:                                    // should not happen
2169:                                    logger
2170:                                            .fatalError("unexpected exception",
2171:                                                    e);
2172:                                    throw new INTERNAL(e.toString());
2173:                                }
2174:                            }
2175:                        }
2176:                    }
2177:                }
2178:            }
2179:
2180:            public void disconnect(org.omg.CORBA.Object obj) {
2181:                if (!(obj instanceof  org.omg.CORBA.portable.ObjectImpl)) {
2182:                    throw new BAD_PARAM("disconnect parameter must extend "
2183:                            + "org.omg.CORBA.portable.ObjectImpl");
2184:                }
2185:
2186:                if (!(obj instanceof  org.omg.CORBA.portable.InvokeHandler)) {
2187:                    throw new BAD_PARAM("disconnect parameter must implement "
2188:                            + "org.omg.CORBA.portable.InvokeHandler");
2189:                }
2190:
2191:                synchronized (connectedObjects) {
2192:                    org.omg.PortableServer.Servant servant = (org.omg.PortableServer.Servant) connectedObjects
2193:                            .get(obj);
2194:
2195:                    if (servant != null) {
2196:                        connectedObjects.remove(obj);
2197:                        try {
2198:                            getRootPOA().deactivate_object(
2199:                                    getRootPOA().servant_to_id(servant));
2200:                        } catch (Exception e) {
2201:                            // cannot happen
2202:                            logger.fatalError("unexpected exception", e);
2203:                            throw new INTERNAL(e.toString());
2204:                        }
2205:                    }
2206:                }
2207:            }
2208:
2209:            public String getServerIdString() {
2210:                return serverIdStr;
2211:            }
2212:
2213:            public byte[] getServerId() {
2214:                return serverId;
2215:            }
2216:
2217:            public RPPoolManager newRPPoolManager(boolean isSingleThreaded) {
2218:                return poolManagerFactory.newRPPoolManager(isSingleThreaded);
2219:            }
2220:
2221:            public void notifyTransportListeners(GIOPConnection gc) {
2222:
2223:                transport_manager.notifyTransportListeners(gc);
2224:            }
2225:
2226:            public String getImplName() {
2227:                return implName;
2228:            }
2229:
2230:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.