TOAFactory.java revision 608:7e06bf1dcb09
1/*
2 * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package com.sun.corba.se.impl.oa.toa ;
27
28import java.util.Map ;
29import java.util.HashMap ;
30
31import org.omg.CORBA.INTERNAL ;
32import org.omg.CORBA.CompletionStatus ;
33
34import com.sun.corba.se.spi.oa.ObjectAdapterFactory ;
35import com.sun.corba.se.spi.oa.ObjectAdapter ;
36
37import com.sun.corba.se.spi.orb.ORB ;
38
39import com.sun.corba.se.spi.ior.ObjectAdapterId ;
40
41import com.sun.corba.se.impl.oa.toa.TOAImpl ;
42import com.sun.corba.se.impl.oa.toa.TransientObjectManager ;
43
44import com.sun.corba.se.impl.javax.rmi.CORBA.Util ;
45
46import com.sun.corba.se.impl.ior.ObjectKeyTemplateBase ;
47
48import com.sun.corba.se.spi.logging.CORBALogDomains ;
49import com.sun.corba.se.impl.logging.ORBUtilSystemException ;
50
51public class TOAFactory implements ObjectAdapterFactory
52{
53    private ORB orb ;
54    private ORBUtilSystemException wrapper ;
55
56    private TOAImpl toa ;
57    private Map codebaseToTOA ;
58    private TransientObjectManager tom ;
59
60    public ObjectAdapter find ( ObjectAdapterId oaid )
61    {
62        if (oaid.equals( ObjectKeyTemplateBase.JIDL_OAID )  )
63            // Return the dispatch-only TOA, which can dispatch
64            // request for objects created by any TOA.
65            return getTOA() ;
66        else
67            throw wrapper.badToaOaid() ;
68    }
69
70    public void init( ORB orb )
71    {
72        this.orb = orb ;
73        wrapper = ORBUtilSystemException.get( orb,
74            CORBALogDomains.OA_LIFECYCLE ) ;
75        tom = new TransientObjectManager( orb ) ;
76        codebaseToTOA = new HashMap() ;
77    }
78
79    public void shutdown( boolean waitForCompletion )
80    {
81        if (Util.isInstanceDefined()) {
82            Util.getInstance().unregisterTargetsForORB(orb);
83        }
84    }
85
86    public synchronized TOA getTOA( String codebase )
87    {
88        TOA toa = (TOA)(codebaseToTOA.get( codebase )) ;
89        if (toa == null) {
90            toa = new TOAImpl( orb, tom, codebase ) ;
91
92            codebaseToTOA.put( codebase, toa ) ;
93        }
94
95        return toa ;
96    }
97
98    public synchronized TOA getTOA()
99    {
100        if (toa == null)
101            // The dispatch-only TOA is not used for creating
102            // objrefs, so its codebase can be null (and must
103            // be, since we do not have a servant at this point)
104            toa = new TOAImpl( orb, tom, null ) ;
105
106        return toa ;
107    }
108
109    public ORB getORB()
110    {
111        return orb ;
112    }
113} ;
114