KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > iiop > rmi > ir > OperationDefImpl


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.iiop.rmi.ir;
23
24 import org.omg.CORBA.Any JavaDoc;
25 import org.omg.CORBA.TypeCode JavaDoc;
26 import org.omg.CORBA.IDLType JavaDoc;
27 import org.omg.CORBA.IDLTypeHelper JavaDoc;
28 import org.omg.CORBA.IRObject JavaDoc;
29 import org.omg.CORBA.DefinitionKind JavaDoc;
30 import org.omg.CORBA.OperationMode JavaDoc;
31 import org.omg.CORBA.ParameterDescription JavaDoc;
32 import org.omg.CORBA.OperationDescription JavaDoc;
33 import org.omg.CORBA.OperationDescriptionHelper;
34 import org.omg.CORBA.OperationDef JavaDoc;
35 import org.omg.CORBA.OperationDefOperations JavaDoc;
36 import org.omg.CORBA.OperationDefPOATie;
37 import org.omg.CORBA.ExceptionDef JavaDoc;
38 import org.omg.CORBA.ExceptionDescription JavaDoc;
39 import org.omg.CORBA.ExceptionDescriptionHelper;
40 import org.omg.CORBA.ContainedOperations JavaDoc;
41 import org.omg.CORBA.ContainedPackage.Description;
42 import org.omg.CORBA.BAD_INV_ORDER JavaDoc;
43
44 /**
45  * OperationDef IR object.
46  *
47  * @author <a HREF="mailto:osh@sparre.dk">Ole Husgaard</a>
48  * @version $Revision: 37459 $
49  */

50 class OperationDefImpl
51    extends ContainedImpl
52    implements OperationDefOperations JavaDoc
53 {
54    // Constants -----------------------------------------------------
55

56    // Attributes ----------------------------------------------------
57

58    // Static --------------------------------------------------------
59

60    // Constructors --------------------------------------------------
61

62    OperationDefImpl(String JavaDoc id, String JavaDoc name, String JavaDoc version,
63                     LocalContainer defined_in,
64                     TypeCode JavaDoc typeCode,
65                     ParameterDescription JavaDoc[] params,
66                     ExceptionDef JavaDoc[] exceptions,
67                     RepositoryImpl repository)
68    {
69       super(id, name, version, defined_in,
70             DefinitionKind.dk_Operation, repository);
71
72       this.typeCode = typeCode;
73       this.params = params;
74       this.exceptions = exceptions;
75    }
76
77    // Public --------------------------------------------------------
78

79
80    // LocalIRObject implementation ---------------------------------
81

82    public IRObject JavaDoc getReference()
83    {
84       if (ref == null) {
85          ref = org.omg.CORBA.OperationDefHelper.narrow(
86                             servantToReference(new OperationDefPOATie(this)) );
87       }
88       return ref;
89    }
90
91    public void allDone()
92       throws IRConstructionException
93    {
94       // Get my return type definition: It should have been created now.
95
type_def = IDLTypeImpl.getIDLType(typeCode, repository);
96
97       // resolve parameter type definitions
98
for (int i = 0; i < params.length; ++i) {
99          LocalIDLType lit = IDLTypeImpl.getIDLType(params[i].type, repository);
100 if (lit==null)
101   throw new RuntimeException JavaDoc("???????????1?");
102          params[i].type_def = IDLTypeHelper.narrow(lit.getReference());
103 if (params[i].type_def==null)
104   throw new RuntimeException JavaDoc("???????????2?");
105       }
106  
107       getReference();
108    }
109  
110
111    // OperationDefOperations implementation ----------------------------
112

113    public TypeCode JavaDoc result()
114    {
115       return typeCode;
116    }
117
118    public IDLType JavaDoc result_def()
119    {
120       return IDLTypeHelper.narrow(type_def.getReference());
121    }
122
123    public void result_def(IDLType JavaDoc arg)
124    {
125       throw new BAD_INV_ORDER JavaDoc("Cannot change RMI/IIOP mapping.");
126    }
127
128    public ParameterDescription JavaDoc[] params()
129    {
130       return params;
131    }
132
133    public void params(ParameterDescription JavaDoc[] arg)
134    {
135       throw new BAD_INV_ORDER JavaDoc("Cannot change RMI/IIOP mapping.");
136    }
137
138    public OperationMode JavaDoc mode()
139    {
140       // RMI/IIOP never map to oneway operations.
141
return OperationMode.OP_NORMAL;
142    }
143
144    public void mode(OperationMode JavaDoc arg)
145    {
146       throw new BAD_INV_ORDER JavaDoc("Cannot change RMI/IIOP mapping.");
147    }
148
149    public String JavaDoc[] contexts()
150    {
151       // TODO
152
return new String JavaDoc[0];
153    }
154
155    public void contexts(String JavaDoc[] arg)
156    {
157       throw new BAD_INV_ORDER JavaDoc("Cannot change RMI/IIOP mapping.");
158    }
159
160    public ExceptionDef JavaDoc[] exceptions()
161    {
162       return exceptions;
163    }
164
165    public void exceptions(ExceptionDef JavaDoc[] arg)
166    {
167       throw new BAD_INV_ORDER JavaDoc("Cannot change RMI/IIOP mapping.");
168    }
169
170    // ContainedImpl implementation ----------------------------------
171

172    public Description JavaDoc describe()
173    {
174       String JavaDoc defined_in_id = "IR";
175  
176       if (defined_in instanceof ContainedOperations JavaDoc)
177          defined_in_id = ((ContainedOperations JavaDoc)defined_in).id();
178  
179       ExceptionDescription JavaDoc[] exds;
180       exds = new ExceptionDescription JavaDoc[exceptions.length];
181       for (int i = 0; i < exceptions.length; ++i) {
182         Description JavaDoc d = exceptions[i].describe();
183         exds[i] = ExceptionDescriptionHelper.extract(d.value);
184       }
185
186       OperationDescription JavaDoc od;
187       od = new OperationDescription JavaDoc(name, id, defined_in_id, version, typeCode,
188                                     mode(), contexts(), params(), exds);
189  
190       Any JavaDoc any = getORB().create_any();
191  
192       OperationDescriptionHelper.insert(any, od);
193  
194       return new Description JavaDoc(DefinitionKind.dk_Operation, any);
195    }
196
197
198    // Package protected ---------------------------------------------
199

200    // Private -------------------------------------------------------
201

202    /**
203     * My CORBA reference.
204     */

205    private OperationDef JavaDoc ref = null;
206
207    /**
208     * My result TypeCode.
209     */

210    private TypeCode JavaDoc typeCode;
211  
212    /**
213     * My result type definition.
214     */

215    private LocalIDLType type_def;
216
217    /**
218     * My parameter description.
219     */

220    private ParameterDescription JavaDoc[] params;
221
222    /**
223     * My exceptions.
224     */

225    private ExceptionDef JavaDoc[] exceptions;
226  
227 }
228
229
Popular Tags