StubFactoryFactoryDynamicBase.java revision 608:7e06bf1dcb09
1/*
2 * Copyright (c) 2004, 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.presentation.rmi;
27
28import java.rmi.Remote ;
29import javax.rmi.CORBA.Tie ;
30
31import javax.rmi.CORBA.Util;
32
33import org.omg.CORBA.CompletionStatus;
34
35import org.omg.CORBA.portable.IDLEntity ;
36
37import com.sun.corba.se.spi.presentation.rmi.PresentationManager;
38import com.sun.corba.se.spi.presentation.rmi.PresentationDefaults;
39
40import com.sun.corba.se.spi.orb.ORB;
41
42import com.sun.corba.se.spi.logging.CORBALogDomains ;
43
44import com.sun.corba.se.impl.logging.ORBUtilSystemException ;
45
46public abstract class StubFactoryFactoryDynamicBase extends
47    StubFactoryFactoryBase
48{
49    protected final ORBUtilSystemException wrapper ;
50
51    public StubFactoryFactoryDynamicBase()
52    {
53        wrapper = ORBUtilSystemException.get(
54            CORBALogDomains.RPC_PRESENTATION ) ;
55    }
56
57    public PresentationManager.StubFactory createStubFactory(
58        String className, boolean isIDLStub, String remoteCodeBase,
59        Class expectedClass, ClassLoader classLoader)
60    {
61        Class cls = null ;
62
63        try {
64            cls = Util.loadClass( className, remoteCodeBase, classLoader ) ;
65        } catch (ClassNotFoundException exc) {
66            throw wrapper.classNotFound3(
67                CompletionStatus.COMPLETED_MAYBE, exc, className ) ;
68        }
69
70        PresentationManager pm = ORB.getPresentationManager() ;
71
72        if (IDLEntity.class.isAssignableFrom( cls ) &&
73            !Remote.class.isAssignableFrom( cls )) {
74            // IDL stubs must always use static factories.
75            PresentationManager.StubFactoryFactory sff =
76                pm.getStubFactoryFactory( false ) ;
77            PresentationManager.StubFactory sf =
78                sff.createStubFactory( className, true, remoteCodeBase,
79                    expectedClass, classLoader ) ;
80            return sf ;
81        } else {
82            PresentationManager.ClassData classData = pm.getClassData( cls ) ;
83            return makeDynamicStubFactory( pm, classData, classLoader ) ;
84        }
85    }
86
87    public abstract PresentationManager.StubFactory makeDynamicStubFactory(
88        PresentationManager pm, PresentationManager.ClassData classData,
89        ClassLoader classLoader ) ;
90
91    public Tie getTie( Class cls )
92    {
93        PresentationManager pm = ORB.getPresentationManager() ;
94        return new ReflectiveTie( pm, wrapper ) ;
95    }
96
97    public boolean createsDynamicStubs()
98    {
99        return true ;
100    }
101}
102