KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > oa > poa > POACurrent


1 /*
2  * @(#)POACurrent.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 package com.sun.corba.se.impl.oa.poa;
9
10 import java.util.*;
11 import org.omg.CORBA.CompletionStatus JavaDoc;
12 import org.omg.PortableServer.CurrentPackage.NoContext JavaDoc;
13 import org.omg.PortableServer.POA JavaDoc;
14 import org.omg.PortableServer.Servant JavaDoc;
15 import org.omg.PortableServer.ServantLocatorPackage.CookieHolder JavaDoc;
16
17 import com.sun.corba.se.spi.oa.OAInvocationInfo ;
18 import com.sun.corba.se.spi.oa.ObjectAdapter ;
19
20 import com.sun.corba.se.spi.orb.ORB ;
21
22 import com.sun.corba.se.spi.logging.CORBALogDomains ;
23
24 import com.sun.corba.se.impl.logging.POASystemException ;
25
26 // XXX Needs to be turned into LocalObjectImpl.
27

28 public class POACurrent extends org.omg.CORBA.portable.ObjectImpl JavaDoc
29     implements org.omg.PortableServer.Current JavaDoc
30 {
31     private ORB orb;
32     private POASystemException wrapper ;
33
34     public POACurrent(ORB orb)
35     {
36     this.orb = orb;
37     wrapper = POASystemException.get( orb,
38         CORBALogDomains.OA_INVOCATION ) ;
39     }
40
41     public String JavaDoc[] _ids()
42     {
43         String JavaDoc[] ids = new String JavaDoc[1];
44         ids[0] = "IDL:omg.org/PortableServer/Current:1.0";
45         return ids;
46     }
47
48     //
49
// Standard OMG operations.
50
//
51

52     public POA JavaDoc get_POA()
53         throws
54         NoContext JavaDoc
55     {
56         POA JavaDoc poa = (POA JavaDoc)(peekThrowNoContext().oa());
57     throwNoContextIfNull(poa);
58     return poa;
59     }
60
61     public byte[] get_object_id()
62         throws
63         NoContext JavaDoc
64     {
65     byte[] objectid = peekThrowNoContext().id();
66     throwNoContextIfNull(objectid);
67     return objectid;
68     }
69
70     //
71
// Implementation operations used by POA package.
72
//
73

74     public ObjectAdapter getOA()
75     {
76         ObjectAdapter oa = peekThrowInternal().oa();
77     throwInternalIfNull(oa);
78     return oa;
79     }
80
81     public byte[] getObjectId()
82     {
83     byte[] objectid = peekThrowInternal().id();
84     throwInternalIfNull(objectid);
85     return objectid;
86     }
87
88     Servant JavaDoc getServant()
89     {
90     Servant JavaDoc servant = (Servant JavaDoc)(peekThrowInternal().getServantContainer());
91     // If is OK for the servant to be null.
92
// This could happen if POAImpl.getServant is called but
93
// POAImpl.internalGetServant throws an exception.
94
return servant;
95     }
96
97     CookieHolder JavaDoc getCookieHolder()
98     {
99     CookieHolder JavaDoc cookieHolder = peekThrowInternal().getCookieHolder();
100     throwInternalIfNull(cookieHolder);
101     return cookieHolder;
102     }
103
104     // This is public so we can test the stack balance.
105
// It is not a security hole since this same info can be obtained from
106
// PortableInterceptors.
107
public String JavaDoc getOperation()
108     {
109     String JavaDoc operation = peekThrowInternal().getOperation();
110     throwInternalIfNull(operation);
111     return operation;
112     }
113
114     void setServant(Servant JavaDoc servant)
115     {
116     peekThrowInternal().setServant( servant );
117     }
118
119     //
120
// Class utilities.
121
//
122

123     private OAInvocationInfo peekThrowNoContext()
124     throws
125         NoContext JavaDoc
126     {
127     OAInvocationInfo invocationInfo = null;
128     try {
129         invocationInfo = orb.peekInvocationInfo() ;
130     } catch (EmptyStackException e) {
131         throw new NoContext JavaDoc();
132     }
133     return invocationInfo;
134     }
135
136     private OAInvocationInfo peekThrowInternal()
137     {
138     OAInvocationInfo invocationInfo = null;
139     try {
140         invocationInfo = orb.peekInvocationInfo() ;
141     } catch (EmptyStackException e) {
142         // The completion status is maybe because this could happen
143
// after the servant has been invoked.
144
throw wrapper.poacurrentUnbalancedStack( e ) ;
145     }
146     return invocationInfo;
147     }
148
149     private void throwNoContextIfNull(Object JavaDoc o)
150     throws
151         NoContext JavaDoc
152     {
153     if ( o == null ) {
154         throw new NoContext JavaDoc();
155     }
156     }
157
158     private void throwInternalIfNull(Object JavaDoc o)
159     {
160     if ( o == null ) {
161         throw wrapper.poacurrentNullField( CompletionStatus.COMPLETED_MAYBE ) ;
162     }
163     }
164 }
165
Popular Tags