KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)DelegateImpl.java 1.12 04/06/21
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 package com.sun.corba.se.impl.oa.poa;
8
9 import java.util.EmptyStackException JavaDoc;
10
11 import org.omg.PortableServer.*;
12
13 import com.sun.corba.se.spi.orb.ORB ;
14
15 import com.sun.corba.se.spi.logging.CORBALogDomains ;
16
17 import com.sun.corba.se.impl.logging.POASystemException ;
18
19 public class DelegateImpl implements org.omg.PortableServer.portable.Delegate JavaDoc
20 {
21     private ORB orb ;
22     private POASystemException wrapper ;
23     private POAFactory factory;
24
25     public DelegateImpl(ORB orb, POAFactory factory){
26     this.orb = orb ;
27     this.wrapper = POASystemException.get( orb,
28         CORBALogDomains.OA ) ;
29         this.factory = factory;
30     }
31
32     public org.omg.CORBA.ORB JavaDoc orb(Servant self)
33     {
34         return orb;
35     }
36
37     public org.omg.CORBA.Object JavaDoc this_object(Servant self)
38     {
39         byte[] oid;
40         POA poa;
41         try {
42             oid = orb.peekInvocationInfo().id();
43             poa = (POA)orb.peekInvocationInfo().oa();
44         String JavaDoc repId = self._all_interfaces(poa,oid)[0] ;
45         return poa.create_reference_with_id(oid, repId);
46         } catch (EmptyStackException JavaDoc notInInvocationE) {
47             //Not within an invocation context
48
POAImpl defaultPOA = null;
49             try {
50                 defaultPOA = (POAImpl)self._default_POA();
51             } catch (ClassCastException JavaDoc exception){
52         throw wrapper.defaultPoaNotPoaimpl( exception ) ;
53             }
54
55             try {
56                 if (defaultPOA.getPolicies().isImplicitlyActivated() ||
57                     (defaultPOA.getPolicies().isUniqueIds() &&
58              defaultPOA.getPolicies().retainServants())) {
59                     return defaultPOA.servant_to_reference(self);
60                 } else {
61             throw wrapper.wrongPoliciesForThisObject() ;
62         }
63             } catch ( org.omg.PortableServer.POAPackage.ServantNotActive JavaDoc e) {
64         throw wrapper.thisObjectServantNotActive( e ) ;
65             } catch ( org.omg.PortableServer.POAPackage.WrongPolicy JavaDoc e) {
66         throw wrapper.thisObjectWrongPolicy( e ) ;
67             }
68         } catch (ClassCastException JavaDoc e) {
69         throw wrapper.defaultPoaNotPoaimpl( e ) ;
70         }
71     }
72
73     public POA poa(Servant self)
74     {
75         try {
76             return (POA)orb.peekInvocationInfo().oa();
77         } catch (EmptyStackException JavaDoc exception){
78         POA returnValue = factory.lookupPOA(self);
79         if (returnValue != null) {
80         return returnValue;
81         }
82         
83         throw wrapper.noContext( exception ) ;
84         }
85     }
86
87     public byte[] object_id(Servant self)
88     {
89         try{
90             return orb.peekInvocationInfo().id();
91         } catch (EmptyStackException JavaDoc exception){
92         throw wrapper.noContext(exception) ;
93         }
94     }
95
96     public POA default_POA(Servant self)
97     {
98         return factory.getRootPOA();
99     }
100
101     public boolean is_a(Servant self, String JavaDoc repId)
102     {
103         String JavaDoc[] repositoryIds = self._all_interfaces(poa(self),object_id(self));
104     for ( int i=0; i<repositoryIds.length; i++ )
105         if ( repId.equals(repositoryIds[i]) )
106         return true;
107
108         return false;
109     }
110
111     public boolean non_existent(Servant self)
112     {
113         //REVISIT
114
try{
115             byte[] oid = orb.peekInvocationInfo().id();
116             if( oid == null) return true;
117             else return false;
118         } catch (EmptyStackException JavaDoc exception){
119         throw wrapper.noContext(exception) ;
120         }
121     }
122
123     // The get_interface() method has been replaced by get_interface_def()
124

125     public org.omg.CORBA.Object JavaDoc get_interface_def(Servant Self)
126     {
127     throw wrapper.methodNotImplemented() ;
128     }
129 }
130
Popular Tags