POACurrent.java revision 608:7e06bf1dcb09
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
26package com.sun.corba.se.impl.oa.poa;
27
28import java.util.*;
29import org.omg.CORBA.CompletionStatus;
30import org.omg.PortableServer.CurrentPackage.NoContext;
31import org.omg.PortableServer.POA;
32import org.omg.PortableServer.Servant;
33import org.omg.PortableServer.ServantLocatorPackage.CookieHolder;
34
35import com.sun.corba.se.spi.oa.OAInvocationInfo ;
36import com.sun.corba.se.spi.oa.ObjectAdapter ;
37
38import com.sun.corba.se.spi.orb.ORB ;
39
40import com.sun.corba.se.spi.logging.CORBALogDomains ;
41
42import com.sun.corba.se.impl.logging.POASystemException ;
43
44// XXX Needs to be turned into LocalObjectImpl.
45
46public class POACurrent extends org.omg.CORBA.portable.ObjectImpl
47    implements org.omg.PortableServer.Current
48{
49    private ORB orb;
50    private POASystemException wrapper ;
51
52    public POACurrent(ORB orb)
53    {
54        this.orb = orb;
55        wrapper = POASystemException.get( orb,
56            CORBALogDomains.OA_INVOCATION ) ;
57    }
58
59    public String[] _ids()
60    {
61        String[] ids = new String[1];
62        ids[0] = "IDL:omg.org/PortableServer/Current:1.0";
63        return ids;
64    }
65
66    //
67    // Standard OMG operations.
68    //
69
70    public POA get_POA()
71        throws
72            NoContext
73    {
74        POA poa = (POA)(peekThrowNoContext().oa());
75        throwNoContextIfNull(poa);
76        return poa;
77    }
78
79    public byte[] get_object_id()
80        throws
81            NoContext
82    {
83        byte[] objectid = peekThrowNoContext().id();
84        throwNoContextIfNull(objectid);
85        return objectid;
86    }
87
88    //
89    // Implementation operations used by POA package.
90    //
91
92    public ObjectAdapter getOA()
93    {
94        ObjectAdapter oa = peekThrowInternal().oa();
95        throwInternalIfNull(oa);
96        return oa;
97    }
98
99    public byte[] getObjectId()
100    {
101        byte[] objectid = peekThrowInternal().id();
102        throwInternalIfNull(objectid);
103        return objectid;
104    }
105
106    Servant getServant()
107    {
108        Servant servant = (Servant)(peekThrowInternal().getServantContainer());
109        // If is OK for the servant to be null.
110        // This could happen if POAImpl.getServant is called but
111        // POAImpl.internalGetServant throws an exception.
112        return servant;
113    }
114
115    CookieHolder getCookieHolder()
116    {
117        CookieHolder cookieHolder = peekThrowInternal().getCookieHolder();
118        throwInternalIfNull(cookieHolder);
119        return cookieHolder;
120    }
121
122    // This is public so we can test the stack balance.
123    // It is not a security hole since this same info can be obtained from
124    // PortableInterceptors.
125    public String getOperation()
126    {
127        String operation = peekThrowInternal().getOperation();
128        throwInternalIfNull(operation);
129        return operation;
130    }
131
132    void setServant(Servant servant)
133    {
134        peekThrowInternal().setServant( servant );
135    }
136
137    //
138    // Class utilities.
139    //
140
141    private OAInvocationInfo peekThrowNoContext()
142        throws
143            NoContext
144    {
145        OAInvocationInfo invocationInfo = null;
146        try {
147            invocationInfo = orb.peekInvocationInfo() ;
148        } catch (EmptyStackException e) {
149            throw new NoContext();
150        }
151        return invocationInfo;
152    }
153
154    private OAInvocationInfo peekThrowInternal()
155    {
156        OAInvocationInfo invocationInfo = null;
157        try {
158            invocationInfo = orb.peekInvocationInfo() ;
159        } catch (EmptyStackException e) {
160            // The completion status is maybe because this could happen
161            // after the servant has been invoked.
162            throw wrapper.poacurrentUnbalancedStack( e ) ;
163        }
164        return invocationInfo;
165    }
166
167    private void throwNoContextIfNull(Object o)
168        throws
169            NoContext
170    {
171        if ( o == null ) {
172            throw new NoContext();
173        }
174    }
175
176    private void throwInternalIfNull(Object o)
177    {
178        if ( o == null ) {
179            throw wrapper.poacurrentNullField( CompletionStatus.COMPLETED_MAYBE ) ;
180        }
181    }
182}
183