KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > presentation > rmi > StubFactoryFactoryStaticImpl


1 /*
2  * @(#)StubFactoryFactoryStaticImpl.java 1.10 04/05/25
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.corba.se.impl.presentation.rmi;
9
10 import javax.rmi.CORBA.Util JavaDoc;
11 import javax.rmi.CORBA.Tie JavaDoc ;
12
13 import org.omg.CORBA.CompletionStatus JavaDoc;
14
15 import com.sun.corba.se.spi.presentation.rmi.PresentationManager;
16
17 import com.sun.corba.se.impl.util.PackagePrefixChecker;
18 import com.sun.corba.se.impl.util.Utility;
19
20 import com.sun.corba.se.spi.logging.CORBALogDomains ;
21
22 import com.sun.corba.se.impl.logging.ORBUtilSystemException ;
23
24 public class StubFactoryFactoryStaticImpl extends
25     StubFactoryFactoryBase
26 {
27     private ORBUtilSystemException wrapper = ORBUtilSystemException.get(
28     CORBALogDomains.RPC_PRESENTATION ) ;
29
30     public PresentationManager.StubFactory createStubFactory(
31     String JavaDoc className, boolean isIDLStub, String JavaDoc remoteCodeBase, Class JavaDoc
32     expectedClass, ClassLoader JavaDoc classLoader)
33     {
34     String JavaDoc stubName = null ;
35
36     if (isIDLStub)
37         stubName = Utility.idlStubName( className ) ;
38     else
39         stubName = Utility.stubNameForCompiler( className ) ;
40
41     ClassLoader JavaDoc expectedTypeClassLoader =
42         (expectedClass == null ? classLoader :
43         expectedClass.getClassLoader());
44
45     // The old code was optimized to try to guess which way to load classes
46
// first. The real stub class name could either be className or
47
// "org.omg.stub." + className. We will compute this as follows:
48
// If stubName starts with a "forbidden" package, try the prefixed
49
// version first, otherwise try the non-prefixed version first.
50
// In any case, try both forms if necessary.
51

52     String JavaDoc firstStubName = stubName ;
53     String JavaDoc secondStubName = stubName ;
54
55     if (PackagePrefixChecker.hasOffendingPrefix(stubName))
56         firstStubName = PackagePrefixChecker.packagePrefix() + stubName ;
57     else
58         secondStubName = PackagePrefixChecker.packagePrefix() + stubName ;
59
60     Class JavaDoc clz = null;
61
62     try {
63         clz = Util.loadClass( firstStubName, remoteCodeBase,
64         expectedTypeClassLoader ) ;
65     } catch (ClassNotFoundException JavaDoc e1) {
66         // log only at FINE level
67
wrapper.classNotFound1( CompletionStatus.COMPLETED_MAYBE,
68         e1, firstStubName ) ;
69         try {
70         clz = Util.loadClass( secondStubName, remoteCodeBase,
71             expectedTypeClassLoader ) ;
72         } catch (ClassNotFoundException JavaDoc e2) {
73         throw wrapper.classNotFound2(
74             CompletionStatus.COMPLETED_MAYBE, e2, secondStubName ) ;
75         }
76     }
77
78     // XXX Is this step necessary, or should the Util.loadClass
79
// algorithm always produce a valid class if the setup is correct?
80
// Does the OMG standard algorithm need to be changed to include
81
// this step?
82
if ((clz == null) ||
83         ((expectedClass != null) && !expectedClass.isAssignableFrom(clz))) {
84         try {
85         ClassLoader JavaDoc cl = Thread.currentThread().getContextClassLoader();
86         if (cl == null)
87             cl = ClassLoader.getSystemClassLoader();
88
89         clz = cl.loadClass(className);
90         } catch (Exception JavaDoc exc) {
91         // XXX make this a system exception
92
IllegalStateException JavaDoc ise = new IllegalStateException JavaDoc(
93             "Could not load class " + stubName ) ;
94         ise.initCause( exc ) ;
95         throw ise ;
96         }
97         }
98
99     return new StubFactoryStaticImpl( clz ) ;
100     }
101
102     public Tie JavaDoc getTie( Class JavaDoc cls )
103     {
104     Class JavaDoc tieClass = null ;
105     String JavaDoc className = Utility.tieName(cls.getName());
106
107     // XXX log exceptions at FINE level
108
try {
109         try {
110         //_REVISIT_ The spec does not specify a loadingContext parameter for
111
//the following call. Would it be useful to pass one?
112
tieClass = Utility.loadClassForClass(className, Util.getCodebase(cls),
113             null, cls, cls.getClassLoader());
114         return (Tie JavaDoc) tieClass.newInstance();
115         } catch (Exception JavaDoc err) {
116         tieClass = Utility.loadClassForClass(
117             PackagePrefixChecker.packagePrefix() + className,
118             Util.getCodebase(cls), null, cls, cls.getClassLoader());
119         return (Tie JavaDoc) tieClass.newInstance();
120         }
121         } catch (Exception JavaDoc err) {
122             return null;
123         }
124
125     }
126
127     public boolean createsDynamicStubs()
128     {
129     return false ;
130     }
131 }
132
Popular Tags