KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > io > FVDCodeBaseImpl


1 /*
2  * @(#)FVDCodeBaseImpl.java 1.17 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 /*
8  * Licensed Materials - Property of IBM
9  * RMI-IIOP v1.0
10  * Copyright IBM Corp. 1998 1999 All Rights Reserved
11  *
12  * US Government Users Restricted Rights - Use, duplication or
13  * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
14  */

15
16 package com.sun.corba.se.impl.io;
17
18 import org.omg.CORBA.ORB JavaDoc;
19 import java.util.Properties JavaDoc;
20 import javax.rmi.CORBA.Util JavaDoc;
21 import javax.rmi.CORBA.ValueHandler JavaDoc;
22 import java.util.Hashtable JavaDoc;
23 import java.util.Stack JavaDoc;
24
25 import com.sun.org.omg.CORBA.ValueDefPackage.FullValueDescription;
26 import com.sun.org.omg.SendingContext._CodeBaseImplBase;
27 import com.sun.org.omg.SendingContext.CodeBase;
28 import com.sun.org.omg.SendingContext.CodeBaseHelper;
29 import org.omg.CORBA.CompletionStatus JavaDoc;
30 import org.omg.CORBA.ORB JavaDoc;
31
32 import com.sun.corba.se.impl.logging.OMGSystemException;
33 import com.sun.corba.se.spi.logging.CORBALogDomains;
34
35 /**
36  * This class acts as the remote interface to receivers wishing to retrieve
37  * the information of a remote Class.
38  */

39 public class FVDCodeBaseImpl extends _CodeBaseImplBase
40 {
41     // Contains rep. ids as keys to FullValueDescriptions
42
private static Hashtable JavaDoc fvds = new Hashtable JavaDoc();
43
44     // Private ORBSingleton used when we need an ORB while not
45
// having a delegate set.
46
private transient ORB JavaDoc orb = null;
47
48     private transient OMGSystemException wrapper = OMGSystemException.get(
49     CORBALogDomains.RPC_ENCODING ) ;
50
51     // backward compatability so that appropriate rep-id calculations
52
// can take place
53
// this needs to be transient to prevent serialization during
54
// marshalling/unmarshalling
55
private transient ValueHandlerImpl vhandler = null;
56
57     void setValueHandler(ValueHandler JavaDoc vh)
58     {
59         vhandler = (com.sun.corba.se.impl.io.ValueHandlerImpl) vh;
60     }
61
62     // Operation to obtain the IR from the sending context
63
public com.sun.org.omg.CORBA.Repository get_ir (){
64     return null;
65     }
66
67     // Operations to obtain a URL to the implementation code
68
public String JavaDoc implementation (String JavaDoc x){
69     try{
70         // default to using the current ORB version in case the
71
// vhandler is not set
72
if (vhandler == null) {
73             vhandler = new ValueHandlerImpl(false);
74         }
75
76             // Util.getCodebase may return null which would
77
// cause a BAD_PARAM exception.
78
String JavaDoc result = Util.getCodebase(vhandler.getClassFromType(x));
79             if (result == null)
80                 return "";
81             else
82                 return result;
83     } catch(ClassNotFoundException JavaDoc cnfe){
84         throw wrapper.missingLocalValueImpl( CompletionStatus.COMPLETED_MAYBE,
85         cnfe ) ;
86     }
87     }
88
89     public String JavaDoc[] implementations (String JavaDoc[] x){
90     String JavaDoc result[] = new String JavaDoc[x.length];
91
92     for (int i = 0; i < x.length; i++)
93         result[i] = implementation(x[i]);
94
95     return result;
96     }
97
98     // the same information
99
public FullValueDescription meta (String JavaDoc x){
100     try{
101         FullValueDescription result = (FullValueDescription)fvds.get(x);
102
103         if (result == null) {
104             // default to using the current ORB version in case the
105
// vhandler is not set
106
if (vhandler == null) {
107                 vhandler = new ValueHandlerImpl(false);
108             }
109
110         try{
111             result = ValueUtility.translate(_orb(),
112             ObjectStreamClass.lookup(vhandler.getAnyClassFromType(x)), vhandler);
113         } catch(Throwable JavaDoc t){
114             if (orb == null)
115             orb = ORB.init(); //d11638
116
result = ValueUtility.translate(orb,
117             ObjectStreamClass.lookup(vhandler.getAnyClassFromType(x)), vhandler);
118         }
119
120         if (result != null){
121             fvds.put(x, result);
122         } else {
123             throw wrapper.missingLocalValueImpl( CompletionStatus.COMPLETED_MAYBE);
124         }
125         }
126                 
127         return result;
128     } catch(Throwable JavaDoc t){
129         throw wrapper.incompatibleValueImpl(CompletionStatus.COMPLETED_MAYBE,t);
130     }
131     }
132
133     public FullValueDescription[] metas (String JavaDoc[] x){
134     FullValueDescription descriptions[] = new FullValueDescription[x.length];
135
136     for (int i = 0; i < x.length; i++)
137         descriptions[i] = meta(x[i]);
138
139     return descriptions;
140     }
141
142     // information
143
public String JavaDoc[] bases (String JavaDoc x){
144     try {
145         // default to using the current ORB version in case the
146
// vhandler is not set
147
if (vhandler == null) {
148             vhandler = new ValueHandlerImpl(false);
149         }
150
151         Stack JavaDoc repIds = new Stack JavaDoc();
152         Class JavaDoc parent = ObjectStreamClass.lookup(vhandler.getClassFromType(x)).forClass().getSuperclass();
153
154         while (!parent.equals(java.lang.Object JavaDoc.class)) {
155         repIds.push(vhandler.createForAnyType(parent));
156         parent = parent.getSuperclass();
157         }
158
159         String JavaDoc result[] = new String JavaDoc[repIds.size()];
160         for (int i = result.length - 1; i >= 0; i++)
161         result[i] = (String JavaDoc)repIds.pop();
162
163         return result;
164     } catch (Throwable JavaDoc t) {
165         throw wrapper.missingLocalValueImpl( CompletionStatus.COMPLETED_MAYBE, t );
166     }
167     }
168 }
169
Popular Tags