KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)DynamicStubImpl.java 1.5 04/06/21
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 java.io.ObjectInputStream JavaDoc ;
11 import java.io.ObjectOutputStream JavaDoc ;
12 import java.io.IOException JavaDoc ;
13 import java.io.Serializable JavaDoc ;
14
15 import java.rmi.RemoteException JavaDoc ;
16
17 import javax.rmi.CORBA.Tie JavaDoc ;
18
19 import org.omg.CORBA_2_3.portable.ObjectImpl JavaDoc ;
20
21 import org.omg.CORBA.portable.Delegate JavaDoc ;
22 import org.omg.CORBA.portable.OutputStream JavaDoc ;
23
24 import org.omg.CORBA.SystemException JavaDoc ;
25 import org.omg.CORBA.ORB JavaDoc ;
26
27 import com.sun.corba.se.spi.orbutil.proxy.InvocationHandlerFactory ;
28 import com.sun.corba.se.spi.presentation.rmi.PresentationManager ;
29 import com.sun.corba.se.spi.presentation.rmi.StubAdapter ;
30 import com.sun.corba.se.spi.presentation.rmi.DynamicStub ;
31 import com.sun.corba.se.impl.presentation.rmi.StubConnectImpl ;
32 import com.sun.corba.se.spi.logging.CORBALogDomains ;
33 import com.sun.corba.se.impl.logging.UtilSystemException ;
34 import com.sun.corba.se.impl.ior.StubIORImpl ;
35 import com.sun.corba.se.impl.util.RepositoryId ;
36 import com.sun.corba.se.impl.util.JDKBridge ;
37 import com.sun.corba.se.impl.util.Utility ;
38
39 // XXX Do we need _get_codebase?
40
public class DynamicStubImpl extends ObjectImpl JavaDoc
41     implements DynamicStub, Serializable JavaDoc
42 {
43     private static final long serialVersionUID = 4852612040012087675L;
44
45     private String JavaDoc[] typeIds ;
46     private StubIORImpl ior ;
47     private DynamicStub self = null ; // The actual DynamicProxy for this stub.
48

49     public void setSelf( DynamicStub self )
50     {
51     // XXX Should probably only allow this once.
52
this.self = self ;
53     }
54
55     public DynamicStub getSelf()
56     {
57     return self ;
58     }
59
60     public DynamicStubImpl( String JavaDoc[] typeIds )
61     {
62     this.typeIds = typeIds ;
63     ior = null ;
64     }
65
66     public void setDelegate( Delegate JavaDoc delegate )
67     {
68     _set_delegate( delegate ) ;
69     }
70
71     public Delegate JavaDoc getDelegate()
72     {
73     return _get_delegate() ;
74     }
75
76     public ORB JavaDoc getORB()
77     {
78     return (ORB JavaDoc)_orb() ;
79     }
80
81     public String JavaDoc[] _ids()
82     {
83     return typeIds ;
84     }
85
86     public String JavaDoc[] getTypeIds()
87     {
88     return _ids() ;
89     }
90
91     public void connect( ORB JavaDoc orb ) throws RemoteException JavaDoc
92     {
93     ior = StubConnectImpl.connect( ior, self, this, orb ) ;
94     }
95
96     public boolean isLocal()
97     {
98     return _is_local() ;
99     }
100
101     public OutputStream JavaDoc request( String JavaDoc operation,
102     boolean responseExpected )
103     {
104     return _request( operation, responseExpected ) ;
105     }
106     
107     private void readObject( ObjectInputStream JavaDoc stream ) throws
108     IOException JavaDoc, ClassNotFoundException JavaDoc
109     {
110     ior = new StubIORImpl() ;
111     ior.doRead( stream ) ;
112     }
113
114     private void writeObject( ObjectOutputStream JavaDoc stream ) throws
115     IOException JavaDoc
116     {
117     if (ior == null)
118         ior = new StubIORImpl( this ) ;
119     ior.doWrite( stream ) ;
120     }
121
122     public Object JavaDoc readResolve()
123     {
124     String JavaDoc repositoryId = ior.getRepositoryId() ;
125     String JavaDoc cname = RepositoryId.cache.getId( repositoryId ).getClassName() ;
126
127     Class JavaDoc cls = null ;
128
129     try {
130         cls = JDKBridge.loadClass( cname, null, null ) ;
131     } catch (ClassNotFoundException JavaDoc exc) {
132         // XXX log this
133
}
134
135     PresentationManager pm =
136         com.sun.corba.se.spi.orb.ORB.getPresentationManager() ;
137     PresentationManager.ClassData classData = pm.getClassData( cls ) ;
138     InvocationHandlerFactoryImpl ihfactory =
139         (InvocationHandlerFactoryImpl)classData.getInvocationHandlerFactory() ;
140     return ihfactory.getInvocationHandler( this ) ;
141     }
142 }
143
Popular Tags