Wed, 26 Feb 2014 14:43:56 -0800
Added tag jdk8u20-b03 for changeset 9059a1c85704
1 /*
2 * Copyright (c) 1997, 2003, 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 package org.omg.PortableServer;
27 import org.omg.CORBA.ORB;
28 import org.omg.PortableServer.portable.Delegate;
30 /**
31 * Defines the native <code>Servant</code> type. In Java, the
32 * <code>Servant</code> type is mapped to the Java
33 * <code>org.omg.PortableServer.Servant</code> class.
34 * It serves as the base class for all POA servant
35 * implementations and provides a number of methods that may
36 * be invoked by the application programmer, as well as methods
37 * which are invoked by the POA itself and may be overridden by
38 * the user to control aspects of servant behavior.
39 * Based on IDL to Java spec. (CORBA V2.3.1) ptc/00-01-08.pdf.
40 */
42 abstract public class Servant {
44 private transient Delegate _delegate = null;
45 /**
46 * Gets the ORB vendor-specific implementation of
47 * <code>PortableServer::Servant</code>.
48 * @return <code>_delegate</code> the ORB vendor-specific
49 * implementation of <code>PortableServer::Servant</code>.
50 */
51 final public Delegate _get_delegate() {
52 if (_delegate == null) {
53 throw
54 new
55 org.omg.CORBA.BAD_INV_ORDER
56 ("The Servant has not been associated with an ORB instance");
57 }
58 return _delegate;
59 }
61 /**
62 * Supports the Java ORB portability
63 * interfaces by providing a method for classes that support
64 * ORB portability through delegation to set their delegate.
65 * @param delegate ORB vendor-specific implementation of
66 * the <code>PortableServer::Servant</code>.
67 */
68 final public void _set_delegate(Delegate delegate) {
69 _delegate = delegate;
70 }
72 /**
73 * Allows the servant to obtain the object reference for
74 * the target CORBA object it is incarnating for that request.
75 * @return <code>this_object</code> <code>Object</code> reference
76 * associated with the request.
77 */
78 final public org.omg.CORBA.Object _this_object() {
79 return _get_delegate().this_object(this);
80 }
82 /**
83 * Allows the servant to obtain the object reference for
84 * the target CORBA Object it is incarnating for that request.
85 * @param orb ORB with which the servant is associated.
86 * @return <code>_this_object</code> reference associated with the request.
87 */
88 final public org.omg.CORBA.Object _this_object(ORB orb) {
89 try {
90 ((org.omg.CORBA_2_3.ORB)orb).set_delegate(this);
91 }
92 catch(ClassCastException e) {
93 throw
94 new
95 org.omg.CORBA.BAD_PARAM
96 ("POA Servant requires an instance of org.omg.CORBA_2_3.ORB");
97 }
98 return _this_object();
99 }
101 /**
102 * Returns the instance of the ORB
103 * currently associated with the <code>Servant</code> (convenience method).
104 * @return <code>orb</code> the instance of the ORB currently
105 * associated with the <code>Servant</code>.
106 */
107 final public ORB _orb() {
108 return _get_delegate().orb(this);
109 }
111 /**
112 * Allows easy execution of common methods, equivalent to
113 * <code>PortableServer::Current:get_POA</code>.
114 * @return <code>poa</code> POA associated with the servant.
115 */
116 final public POA _poa() {
117 return _get_delegate().poa(this);
118 }
120 /**
121 * Allows easy execution of
122 * common methods, equivalent
123 * to calling <code>PortableServer::Current::get_object_id</code>.
124 * @return <code>object_id</code> the <code>Object</code> ID associated
125 * with this servant.
126 */
127 final public byte[] _object_id() {
128 return _get_delegate().object_id(this);
129 }
131 /**
132 * Returns the
133 * root POA from the ORB instance associated with the servant.
134 * Subclasses may override this method to return a different POA.
135 * @return <code>default_POA</code> the POA associated with the
136 * <code>Servant</code>.
137 */
138 public POA _default_POA() {
139 return _get_delegate().default_POA(this);
140 }
142 /**
143 * Checks to see if the specified <code>repository_id</code> is present
144 * on the list returned by <code>_all_interfaces()</code> or is the
145 * <code>repository_id</code> for the generic CORBA Object.
146 * @param repository_id the <code>repository_id</code>
147 * to be checked in the repository list or against the id
148 * of generic CORBA objects.
149 * @return <code>is_a</code> boolean indicating whether the specified
150 * <code>repository_id</code> is
151 * in the repository list or is same as a generic CORBA
152 * object.
153 */
154 public boolean _is_a(String repository_id) {
155 return _get_delegate().is_a(this, repository_id);
156 }
158 /**
159 * Checks for the existence of an
160 * <code>Object</code>.
161 * The <code>Servant</code> provides a default implementation of
162 * <code>_non_existent()</code> that can be overridden by derived servants.
163 * @return <code>non_existent</code> <code>true</code> if that object does
164 * not exist, <code>false</code> otherwise.
165 */
166 public boolean _non_existent() {
167 return _get_delegate().non_existent(this);
168 }
170 // Ken and Simon will ask about editorial changes
171 // needed in IDL to Java mapping to the following
172 // signature.
173 /**
174 * Returns an object in the Interface Repository
175 * which provides type information that may be useful to a program.
176 * <code>Servant</code> provides a default implementation of
177 * <code>_get_interface()</code>
178 * that can be overridden by derived servants if the default
179 * behavior is not adequate.
180 * @return <code>get_interface</code> type information that corresponds to this servant.
181 */
182 /*
183 public org.omg.CORBA.Object _get_interface() {
184 return _get_delegate().get_interface(this);
185 }
186 */
188 // _get_interface_def() replaces the _get_interface() method
190 /**
191 * Returns an <code>InterfaceDef</code> object as a
192 * <code>CORBA::Object</code> that defines the runtime type of the
193 * <code>CORBA::Object</code> implemented by the <code>Servant</code>.
194 * The invoker of <code>_get_interface_def</code>
195 * must narrow the result to an <code>InterfaceDef</code> in order
196 * to use it.
197 * <P>This default implementation of <code>_get_interface_def()</code>
198 * can be overridden
199 * by derived servants if the default behavior is not adequate.
200 * As defined in the CORBA 2.3.1 specification, section 11.3.1, the
201 * default behavior of <code>_get_interface_def()</code> is to use
202 * the most derived
203 * interface of a static servant or the most derived interface retrieved
204 * from a dynamic servant to obtain the <code>InterfaceDef</code>.
205 * This behavior must
206 * be supported by the <code>Delegate</code> that implements the
207 * <code>Servant</code>.
208 * @return <code>get_interface_def</code> an <code>InterfaceDef</code>
209 * object as a
210 * <code>CORBA::Object</code> that defines the runtime type of the
211 * <code>CORBA::Object</code> implemented by the <code>Servant</code>.
212 */
213 public org.omg.CORBA.Object _get_interface_def()
214 {
215 // First try to call the delegate implementation class's
216 // "Object get_interface_def(..)" method (will work for ORBs
217 // whose delegates implement this method).
218 // Else call the delegate implementation class's
219 // "InterfaceDef get_interface(..)" method using reflection
220 // (will work for ORBs that were built using an older version
221 // of the Delegate interface with a get_interface method
222 // but not a get_interface_def method).
224 org.omg.PortableServer.portable.Delegate delegate = _get_delegate();
225 try {
226 // If the ORB's delegate class does not implement
227 // "Object get_interface_def(..)", this will throw
228 // an AbstractMethodError.
229 return delegate.get_interface_def(this);
230 } catch( AbstractMethodError aex ) {
231 // Call "InterfaceDef get_interface(..)" method using reflection.
232 try {
233 Class[] argc = { org.omg.PortableServer.Servant.class };
234 java.lang.reflect.Method meth =
235 delegate.getClass().getMethod("get_interface", argc);
236 Object[] argx = { this };
237 return (org.omg.CORBA.Object)meth.invoke(delegate, argx);
238 } catch( java.lang.reflect.InvocationTargetException exs ) {
239 Throwable t = exs.getTargetException();
240 if (t instanceof Error) {
241 throw (Error) t;
242 } else if (t instanceof RuntimeException) {
243 throw (RuntimeException) t;
244 } else {
245 throw new org.omg.CORBA.NO_IMPLEMENT();
246 }
247 } catch( RuntimeException rex ) {
248 throw rex;
249 } catch( Exception exr ) {
250 throw new org.omg.CORBA.NO_IMPLEMENT();
251 }
252 }
253 }
255 // methods for which the user must provide an
256 // implementation
257 /**
258 * Used by the ORB to obtain complete type
259 * information from the servant.
260 * @param poa POA with which the servant is associated.
261 * @param objectId is the id corresponding to the object
262 * associated with this servant.
263 * @return list of type information for the object.
264 */
265 abstract public String[] _all_interfaces( POA poa, byte[] objectId);
266 }