FVDCodeBaseImpl.java revision 608:7e06bf1dcb09
1/*
2 * Copyright (c) 1999, 2011, 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/*
26 * Licensed Materials - Property of IBM
27 * RMI-IIOP v1.0
28 * Copyright IBM Corp. 1998 1999  All Rights Reserved
29 *
30 */
31
32package com.sun.corba.se.impl.io;
33
34import org.omg.CORBA.ORB;
35import java.util.Properties;
36import javax.rmi.CORBA.Util;
37import javax.rmi.CORBA.ValueHandler;
38import java.util.Hashtable;
39import java.util.Stack;
40
41import com.sun.org.omg.CORBA.ValueDefPackage.FullValueDescription;
42import com.sun.org.omg.SendingContext._CodeBaseImplBase;
43import com.sun.org.omg.SendingContext.CodeBase;
44import com.sun.org.omg.SendingContext.CodeBaseHelper;
45import org.omg.CORBA.CompletionStatus;
46import org.omg.CORBA.ORB;
47
48import com.sun.corba.se.impl.logging.OMGSystemException;
49import com.sun.corba.se.spi.logging.CORBALogDomains;
50
51/**
52 * This class acts as the remote interface to receivers wishing to retrieve
53 * the information of a remote Class.
54 */
55public class FVDCodeBaseImpl extends _CodeBaseImplBase
56{
57    // Contains rep. ids as keys to FullValueDescriptions
58    private static Hashtable fvds = new Hashtable();
59
60    // Private ORBSingleton used when we need an ORB while not
61    // having a delegate set.
62    private transient ORB orb = null;
63
64    private transient OMGSystemException wrapper = OMGSystemException.get(
65        CORBALogDomains.RPC_ENCODING ) ;
66
67    // backward compatability so that appropriate rep-id calculations
68    // can take place
69    // this needs to be transient to prevent serialization during
70    // marshalling/unmarshalling
71    private transient ValueHandlerImpl vhandler = null;
72
73    void setValueHandler(ValueHandler vh)
74    {
75        vhandler = (com.sun.corba.se.impl.io.ValueHandlerImpl) vh;
76    }
77
78    // Operation to obtain the IR from the sending context
79    public com.sun.org.omg.CORBA.Repository get_ir (){
80        return null;
81    }
82
83    // Operations to obtain a URL to the implementation code
84    public String implementation (String x){
85        try{
86            // default to using the current ORB version in case the
87            // vhandler is not set
88            if (vhandler == null) {
89                vhandler = ValueHandlerImpl.getInstance(false);
90            }
91
92            // Util.getCodebase may return null which would
93            // cause a BAD_PARAM exception.
94            String result = Util.getCodebase(vhandler.getClassFromType(x));
95            if (result == null)
96                return "";
97            else
98                return result;
99        } catch(ClassNotFoundException cnfe){
100            throw wrapper.missingLocalValueImpl( CompletionStatus.COMPLETED_MAYBE,
101                cnfe ) ;
102        }
103    }
104
105    public String[] implementations (String[] x){
106        String result[] = new String[x.length];
107
108        for (int i = 0; i < x.length; i++)
109            result[i] = implementation(x[i]);
110
111        return result;
112    }
113
114    // the same information
115    public FullValueDescription meta (String x){
116        try{
117            FullValueDescription result = (FullValueDescription)fvds.get(x);
118
119            if (result == null) {
120                // default to using the current ORB version in case the
121                // vhandler is not set
122                if (vhandler == null) {
123                    vhandler = ValueHandlerImpl.getInstance(false);
124                }
125
126                try{
127                    result = ValueUtility.translate(_orb(),
128                        ObjectStreamClass.lookup(vhandler.getAnyClassFromType(x)), vhandler);
129                } catch(Throwable t){
130                    if (orb == null)
131                        orb = ORB.init(); //d11638
132                    result = ValueUtility.translate(orb,
133                        ObjectStreamClass.lookup(vhandler.getAnyClassFromType(x)), vhandler);
134                }
135
136                if (result != null){
137                    fvds.put(x, result);
138                } else {
139                    throw wrapper.missingLocalValueImpl( CompletionStatus.COMPLETED_MAYBE);
140                }
141            }
142
143            return result;
144        } catch(Throwable t){
145            throw wrapper.incompatibleValueImpl(CompletionStatus.COMPLETED_MAYBE,t);
146        }
147    }
148
149    public FullValueDescription[] metas (String[] x){
150        FullValueDescription descriptions[] = new FullValueDescription[x.length];
151
152        for (int i = 0; i < x.length; i++)
153            descriptions[i] = meta(x[i]);
154
155        return descriptions;
156    }
157
158    // information
159    public String[] bases (String x){
160        try {
161            // default to using the current ORB version in case the
162            // vhandler is not set
163            if (vhandler == null) {
164                vhandler = ValueHandlerImpl.getInstance(false);
165            }
166
167            Stack repIds = new Stack();
168            Class parent = ObjectStreamClass.lookup(vhandler.getClassFromType(x)).forClass().getSuperclass();
169
170            while (!parent.equals(java.lang.Object.class)) {
171                repIds.push(vhandler.createForAnyType(parent));
172                parent = parent.getSuperclass();
173            }
174
175            String result[] = new String[repIds.size()];
176            for (int i = result.length - 1; i >= 0; i++)
177                result[i] = (String)repIds.pop();
178
179            return result;
180        } catch (Throwable t) {
181            throw wrapper.missingLocalValueImpl( CompletionStatus.COMPLETED_MAYBE, t );
182        }
183    }
184}
185