001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.iiop.rmi.ir;
023:
024: import org.omg.CORBA.Any;
025: import org.omg.CORBA.TypeCode;
026: import org.omg.CORBA.IDLType;
027: import org.omg.CORBA.IDLTypeHelper;
028: import org.omg.CORBA.TCKind;
029: import org.omg.CORBA.IRObject;
030: import org.omg.CORBA.DefinitionKind;
031: import org.omg.CORBA.OperationMode;
032: import org.omg.CORBA.ParameterMode;
033: import org.omg.CORBA.ParameterDescription;
034: import org.omg.CORBA.OperationDescription;
035: import org.omg.CORBA.OperationDescriptionHelper;
036: import org.omg.CORBA.OperationDef;
037: import org.omg.CORBA.OperationDefOperations;
038: import org.omg.CORBA.OperationDefHelper;
039: import org.omg.CORBA.OperationDefPOATie;
040: import org.omg.CORBA.ExceptionDef;
041: import org.omg.CORBA.ExceptionDescription;
042: import org.omg.CORBA.ExceptionDescriptionHelper;
043: import org.omg.CORBA.ContainedOperations;
044: import org.omg.CORBA.ContainedPackage.Description;
045: import org.omg.CORBA.BAD_INV_ORDER;
046:
047: import java.util.Map;
048: import java.util.HashMap;
049:
050: /**
051: * OperationDef IR object.
052: *
053: * @author <a href="mailto:osh@sparre.dk">Ole Husgaard</a>
054: * @version $Revision: 57194 $
055: */
056: class OperationDefImpl extends ContainedImpl implements
057: OperationDefOperations {
058: // Constants -----------------------------------------------------
059:
060: // Attributes ----------------------------------------------------
061:
062: // Static --------------------------------------------------------
063:
064: // Constructors --------------------------------------------------
065:
066: OperationDefImpl(String id, String name, String version,
067: LocalContainer defined_in, TypeCode typeCode,
068: ParameterDescription[] params, ExceptionDef[] exceptions,
069: RepositoryImpl repository) {
070: super (id, name, version, defined_in,
071: DefinitionKind.dk_Operation, repository);
072:
073: this .typeCode = typeCode;
074: this .params = params;
075: this .exceptions = exceptions;
076: }
077:
078: // Public --------------------------------------------------------
079:
080: // LocalIRObject implementation ---------------------------------
081:
082: public IRObject getReference() {
083: if (ref == null) {
084: ref = org.omg.CORBA.OperationDefHelper
085: .narrow(servantToReference(new OperationDefPOATie(
086: this )));
087: }
088: return ref;
089: }
090:
091: public void allDone() throws IRConstructionException {
092: // Get my return type definition: It should have been created now.
093: type_def = IDLTypeImpl.getIDLType(typeCode, repository);
094:
095: // resolve parameter type definitions
096: for (int i = 0; i < params.length; ++i) {
097: LocalIDLType lit = IDLTypeImpl.getIDLType(params[i].type,
098: repository);
099: if (lit == null)
100: throw new RuntimeException("???????????1?");
101: params[i].type_def = IDLTypeHelper.narrow(lit
102: .getReference());
103: if (params[i].type_def == null)
104: throw new RuntimeException("???????????2?");
105: }
106:
107: getReference();
108: }
109:
110: // OperationDefOperations implementation ----------------------------
111:
112: public TypeCode result() {
113: return typeCode;
114: }
115:
116: public IDLType result_def() {
117: return IDLTypeHelper.narrow(type_def.getReference());
118: }
119:
120: public void result_def(IDLType arg) {
121: throw new BAD_INV_ORDER("Cannot change RMI/IIOP mapping.");
122: }
123:
124: public ParameterDescription[] params() {
125: return params;
126: }
127:
128: public void params(ParameterDescription[] arg) {
129: throw new BAD_INV_ORDER("Cannot change RMI/IIOP mapping.");
130: }
131:
132: public OperationMode mode() {
133: // RMI/IIOP never map to oneway operations.
134: return OperationMode.OP_NORMAL;
135: }
136:
137: public void mode(OperationMode arg) {
138: throw new BAD_INV_ORDER("Cannot change RMI/IIOP mapping.");
139: }
140:
141: public String[] contexts() {
142: // TODO
143: return new String[0];
144: }
145:
146: public void contexts(String[] arg) {
147: throw new BAD_INV_ORDER("Cannot change RMI/IIOP mapping.");
148: }
149:
150: public ExceptionDef[] exceptions() {
151: return exceptions;
152: }
153:
154: public void exceptions(ExceptionDef[] arg) {
155: throw new BAD_INV_ORDER("Cannot change RMI/IIOP mapping.");
156: }
157:
158: // ContainedImpl implementation ----------------------------------
159:
160: public Description describe() {
161: String defined_in_id = "IR";
162:
163: if (defined_in instanceof ContainedOperations)
164: defined_in_id = ((ContainedOperations) defined_in).id();
165:
166: ExceptionDescription[] exds;
167: exds = new ExceptionDescription[exceptions.length];
168: for (int i = 0; i < exceptions.length; ++i) {
169: Description d = exceptions[i].describe();
170: exds[i] = ExceptionDescriptionHelper.extract(d.value);
171: }
172:
173: OperationDescription od;
174: od = new OperationDescription(name, id, defined_in_id, version,
175: typeCode, mode(), contexts(), params(), exds);
176:
177: Any any = getORB().create_any();
178:
179: OperationDescriptionHelper.insert(any, od);
180:
181: return new Description(DefinitionKind.dk_Operation, any);
182: }
183:
184: // Package protected ---------------------------------------------
185:
186: // Private -------------------------------------------------------
187:
188: /**
189: * My CORBA reference.
190: */
191: private OperationDef ref = null;
192:
193: /**
194: * My result TypeCode.
195: */
196: private TypeCode typeCode;
197:
198: /**
199: * My result type definition.
200: */
201: private LocalIDLType type_def;
202:
203: /**
204: * My parameter description.
205: */
206: private ParameterDescription[] params;
207:
208: /**
209: * My exceptions.
210: */
211: private ExceptionDef[] exceptions;
212:
213: }
|