KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > protocol > SpecialMethod


1 /*
2  * @(#)SpecialMethod.java 1.25 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.protocol ;
9
10 import javax.rmi.CORBA.Tie JavaDoc;
11
12 import org.omg.CORBA.SystemException JavaDoc ;
13 import org.omg.CORBA.NO_IMPLEMENT JavaDoc ;
14 import org.omg.CORBA.OBJECT_NOT_EXIST JavaDoc ;
15 import org.omg.CORBA.CompletionStatus JavaDoc ;
16 import org.omg.CORBA.portable.InputStream JavaDoc;
17 import org.omg.CORBA.portable.OutputStream JavaDoc;
18
19 import com.sun.corba.se.spi.oa.ObjectAdapter;
20 import com.sun.corba.se.spi.orb.ORB;
21
22 import com.sun.corba.se.spi.protocol.CorbaMessageMediator;
23
24 import com.sun.corba.se.spi.logging.CORBALogDomains;
25
26 import com.sun.corba.se.impl.logging.ORBUtilSystemException;
27
28 import com.sun.corba.se.spi.oa.NullServant ;
29
30 public abstract class SpecialMethod {
31     public abstract boolean isNonExistentMethod() ;
32     public abstract String JavaDoc getName();
33     public abstract CorbaMessageMediator invoke(java.lang.Object JavaDoc servant,
34                         CorbaMessageMediator request,
35                         byte[] objectId,
36                         ObjectAdapter objectAdapter);
37
38     public static final SpecialMethod getSpecialMethod(String JavaDoc operation) {
39     for(int i = 0; i < methods.length; i++)
40         if (methods[i].getName().equals(operation))
41         return methods[i];
42     return null;
43     }
44
45     static SpecialMethod[] methods = {
46     new IsA(),
47     new GetInterface(),
48     new NonExistent(),
49     new NotExistent()
50     };
51 }
52
53 class NonExistent extends SpecialMethod {
54     public boolean isNonExistentMethod()
55     {
56     return true ;
57     }
58
59     public String JavaDoc getName() { // _non_existent
60
return "_non_existent";
61     }
62
63     public CorbaMessageMediator invoke(java.lang.Object JavaDoc servant,
64                        CorbaMessageMediator request,
65                        byte[] objectId,
66                        ObjectAdapter objectAdapter)
67     {
68     boolean result = (servant == null) || (servant instanceof NullServant) ;
69     CorbaMessageMediator response =
70         request.getProtocolHandler().createResponse(request, null);
71     ((OutputStream JavaDoc)response.getOutputObject()).write_boolean(result);
72     return response;
73     }
74 }
75
76 class NotExistent extends NonExistent {
77     public String JavaDoc getName() { // _not_existent
78
return "_not_existent";
79     }
80 }
81
82 class IsA extends SpecialMethod { // _is_a
83
public boolean isNonExistentMethod()
84     {
85     return false ;
86     }
87
88     public String JavaDoc getName() {
89     return "_is_a";
90     }
91     public CorbaMessageMediator invoke(java.lang.Object JavaDoc servant,
92                        CorbaMessageMediator request,
93                        byte[] objectId,
94                        ObjectAdapter objectAdapter)
95     {
96     if ((servant == null) || (servant instanceof NullServant)) {
97         ORB orb = (ORB)request.getBroker() ;
98         ORBUtilSystemException wrapper = ORBUtilSystemException.get( orb,
99         CORBALogDomains.OA_INVOCATION ) ;
100
101         return request.getProtocolHandler().createSystemExceptionResponse(
102         request, wrapper.badSkeleton(), null);
103     }
104     
105     String JavaDoc[] ids = objectAdapter.getInterfaces( servant, objectId );
106     String JavaDoc clientId =
107         ((InputStream JavaDoc)request.getInputObject()).read_string();
108     boolean answer = false;
109     for(int i = 0; i < ids.length; i++)
110         if (ids[i].equals(clientId)) {
111             answer = true;
112             break;
113         }
114         
115     CorbaMessageMediator response =
116         request.getProtocolHandler().createResponse(request, null);
117     ((OutputStream JavaDoc)response.getOutputObject()).write_boolean(answer);
118     return response;
119     }
120 }
121
122 class GetInterface extends SpecialMethod { // _get_interface
123
public boolean isNonExistentMethod()
124     {
125     return false ;
126     }
127
128     public String JavaDoc getName() {
129     return "_interface";
130     }
131     public CorbaMessageMediator invoke(java.lang.Object JavaDoc servant,
132                        CorbaMessageMediator request,
133                        byte[] objectId,
134                        ObjectAdapter objectAdapter)
135     {
136     ORB orb = (ORB)request.getBroker() ;
137     ORBUtilSystemException wrapper = ORBUtilSystemException.get( orb,
138         CORBALogDomains.OA_INVOCATION ) ;
139
140     if ((servant == null) || (servant instanceof NullServant)) {
141         return request.getProtocolHandler().createSystemExceptionResponse(
142         request, wrapper.badSkeleton(), null);
143     } else {
144         return request.getProtocolHandler().createSystemExceptionResponse(
145         request, wrapper.getinterfaceNotImplemented(), null);
146     }
147     }
148 }
149
150 // End of file.
151

152
Popular Tags