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.InterfaceDefOperations;
025: import org.omg.CORBA.InterfaceDefPOATie;
026: import org.omg.CORBA.InterfaceDefHelper;
027: import org.omg.CORBA.Any;
028: import org.omg.CORBA.TypeCode;
029: import org.omg.CORBA.IRObject;
030: import org.omg.CORBA.Contained;
031: import org.omg.CORBA.ContainedPackage.Description;
032: import org.omg.CORBA.Container;
033: import org.omg.CORBA.DefinitionKind;
034: import org.omg.CORBA.IDLType;
035: import org.omg.CORBA.StructMember;
036: import org.omg.CORBA.UnionMember;
037: import org.omg.CORBA.InterfaceDef;
038: import org.omg.CORBA.ConstantDef;
039: import org.omg.CORBA.EnumDef;
040: import org.omg.CORBA.ValueDef;
041: import org.omg.CORBA.ValueBoxDef;
042: import org.omg.CORBA.Initializer;
043: import org.omg.CORBA.StructDef;
044: import org.omg.CORBA.UnionDef;
045: import org.omg.CORBA.ModuleDef;
046: import org.omg.CORBA.AliasDef;
047: import org.omg.CORBA.NativeDef;
048: import org.omg.CORBA.OperationDef;
049: import org.omg.CORBA.OperationMode;
050: import org.omg.CORBA.ParameterDescription;
051: import org.omg.CORBA.AttributeDef;
052: import org.omg.CORBA.AttributeMode;
053: import org.omg.CORBA.ExceptionDef;
054: import org.omg.CORBA.OperationDescription;
055: import org.omg.CORBA.AttributeDescription;
056: import org.omg.CORBA.InterfaceDescription;
057: import org.omg.CORBA.InterfaceDescriptionHelper;
058: import org.omg.CORBA.BAD_INV_ORDER;
059: import org.omg.PortableServer.POA;
060: import org.omg.CORBA.InterfaceDefPackage.FullInterfaceDescription;
061:
062: /**
063: * Interface IR object.
064: *
065: * @author <a href="mailto:osh@sparre.dk">Ole Husgaard</a>
066: * @version $Revision: 57194 $
067: */
068: class InterfaceDefImpl extends ContainedImpl implements
069: InterfaceDefOperations, LocalContainer {
070: // Constants -----------------------------------------------------
071:
072: // Attributes ----------------------------------------------------
073:
074: // Static --------------------------------------------------------
075:
076: private static final org.jboss.logging.Logger logger = org.jboss.logging.Logger
077: .getLogger(InterfaceDefImpl.class);
078:
079: // Constructors --------------------------------------------------
080:
081: InterfaceDefImpl(String id, String name, String version,
082: LocalContainer defined_in, String[] base_interfaces,
083: RepositoryImpl repository) {
084: super (id, name, version, defined_in,
085: DefinitionKind.dk_Interface, repository);
086:
087: this .base_interfaces = base_interfaces;
088: this .delegate = new ContainerImplDelegate(this );
089: }
090:
091: // Public --------------------------------------------------------
092:
093: // LocalContainer implementation ---------------------------------
094:
095: public LocalContained _lookup(String search_name) {
096: return delegate._lookup(search_name);
097: }
098:
099: public LocalContained[] _contents(DefinitionKind limit_type,
100: boolean exclude_inherited) {
101: return delegate._contents(limit_type, exclude_inherited);
102: }
103:
104: public LocalContained[] _lookup_name(String search_name,
105: int levels_to_search, DefinitionKind limit_type,
106: boolean exclude_inherited) {
107: return delegate._lookup_name(search_name, levels_to_search,
108: limit_type, exclude_inherited);
109: }
110:
111: public void add(String name, LocalContained contained)
112: throws IRConstructionException {
113: delegate.add(name, contained);
114: }
115:
116: // LocalIRObject implementation ---------------------------------
117:
118: public IRObject getReference() {
119: if (ref == null) {
120: ref = org.omg.CORBA.InterfaceDefHelper
121: .narrow(servantToReference(new InterfaceDefPOATie(
122: this )));
123: }
124: return ref;
125: }
126:
127: public void allDone() throws IRConstructionException {
128: getReference();
129: delegate.allDone();
130: }
131:
132: public void shutdown() {
133: delegate.shutdown();
134: super .shutdown();
135: }
136:
137: // ContainerOperations implementation ----------------------------
138:
139: public Contained lookup(String search_name) {
140: logger.debug("InterfaceDefImpl.lookup(\"" + search_name
141: + "\") entered.");
142: Contained res = delegate.lookup(search_name);
143: logger.debug("InterfaceDefImpl.lookup(\"" + search_name
144: + "\") returning "
145: + ((res == null) ? "null" : "non-null"));
146: return res;
147: //return delegate.lookup(search_name);
148: }
149:
150: public Contained[] contents(DefinitionKind limit_type,
151: boolean exclude_inherited) {
152: logger.debug("InterfaceDefImpl.contents() entered.");
153: Contained[] res = delegate.contents(limit_type,
154: exclude_inherited);
155: logger.debug("InterfaceDefImpl.contents() " + res.length
156: + " contained to return.");
157: for (int i = 0; i < res.length; ++i)
158: logger.debug(" InterfaceDefImpl.contents() [" + i + "]: "
159: + res[i].id());
160: return res;
161: //return delegate.contents(limit_type, exclude_inherited);
162: }
163:
164: public Contained[] lookup_name(String search_name,
165: int levels_to_search, DefinitionKind limit_type,
166: boolean exclude_inherited) {
167: return delegate.lookup_name(search_name, levels_to_search,
168: limit_type, exclude_inherited);
169: }
170:
171: public org.omg.CORBA.ContainerPackage.Description[] describe_contents(
172: DefinitionKind limit_type, boolean exclude_inherited,
173: int max_returned_objs) {
174: return delegate.describe_contents(limit_type,
175: exclude_inherited, max_returned_objs);
176: }
177:
178: public ModuleDef create_module(String id, String name,
179: String version) {
180: return delegate.create_module(id, name, version);
181: }
182:
183: public ConstantDef create_constant(String id, String name,
184: String version, IDLType type, Any value) {
185: return delegate.create_constant(id, name, version, type, value);
186: }
187:
188: public StructDef create_struct(String id, String name,
189: String version, StructMember[] members) {
190: return delegate.create_struct(id, name, version, members);
191: }
192:
193: public UnionDef create_union(String id, String name,
194: String version, IDLType discriminator_type,
195: UnionMember[] members) {
196: return delegate.create_union(id, name, version,
197: discriminator_type, members);
198: }
199:
200: public EnumDef create_enum(String id, String name, String version,
201: String[] members) {
202: return delegate.create_enum(id, name, version, members);
203: }
204:
205: public AliasDef create_alias(String id, String name,
206: String version, IDLType original_type) {
207: return delegate.create_alias(id, name, version, original_type);
208: }
209:
210: public InterfaceDef create_interface(String id, String name,
211: String version, InterfaceDef[] base_interfaces,
212: boolean is_abstract) {
213: return delegate.create_interface(id, name, version,
214: base_interfaces, is_abstract);
215: }
216:
217: public ValueDef create_value(String id, String name,
218: String version, boolean is_custom, boolean is_abstract,
219: ValueDef base_value, boolean is_truncatable,
220: ValueDef[] abstract_base_values,
221: InterfaceDef[] supported_interfaces,
222: Initializer[] initializers) {
223: return delegate.create_value(id, name, version, is_custom,
224: is_abstract, base_value, is_truncatable,
225: abstract_base_values, supported_interfaces,
226: initializers);
227: }
228:
229: public ValueBoxDef create_value_box(String id, String name,
230: String version, IDLType original_type_def) {
231: return delegate.create_value_box(id, name, version,
232: original_type_def);
233: }
234:
235: public ExceptionDef create_exception(String id, String name,
236: String version, StructMember[] members) {
237: return delegate.create_exception(id, name, version, members);
238: }
239:
240: public NativeDef create_native(String id, String name,
241: String version) {
242: return delegate.create_native(id, name, version);
243: }
244:
245: // InterfaceDefOperations implementation -------------------------
246:
247: public InterfaceDef[] base_interfaces() {
248: if (base_interfaces_ref == null) {
249: base_interfaces_ref = new InterfaceDef[base_interfaces.length];
250: for (int i = 0; i < base_interfaces_ref.length; ++i) {
251: logger.debug("InterfaceDefImpl.base_interfaces(): "
252: + "looking up \"" + base_interfaces[i] + "\".");
253: Contained c = repository.lookup_id(base_interfaces[i]);
254: logger.debug("InterfaceDefImpl.base_interfaces(): "
255: + "Got: " + ((c == null) ? "null" : c.id()));
256: base_interfaces_ref[i] = InterfaceDefHelper.narrow(c);
257: logger
258: .debug("InterfaceDefImpl.base_interfaces(): "
259: + "ref: "
260: + ((c == null) ? "null" : "not null"));
261: }
262: }
263:
264: return base_interfaces_ref;
265: }
266:
267: public void base_interfaces(org.omg.CORBA.InterfaceDef[] arg) {
268: throw new BAD_INV_ORDER("Cannot change RMI/IIOP mapping.");
269: }
270:
271: public boolean is_abstract() {
272: return false;
273: }
274:
275: public void is_abstract(boolean arg) {
276: throw new BAD_INV_ORDER("Cannot change RMI/IIOP mapping.");
277: }
278:
279: public boolean is_a(java.lang.String interface_id) {
280: // TODO
281: return false;
282: }
283:
284: public FullInterfaceDescription describe_interface() {
285: if (fullInterfaceDescription != null)
286: return fullInterfaceDescription;
287:
288: // Has to create the FullInterfaceDescription
289:
290: // TODO
291: OperationDescription[] operations = new OperationDescription[0];
292: AttributeDescription[] attributes = new AttributeDescription[0];
293:
294: String defined_in_id = "IDL:Global:1.0";
295: if (defined_in instanceof org.omg.CORBA.ContainedOperations)
296: defined_in_id = ((org.omg.CORBA.ContainedOperations) defined_in)
297: .id();
298:
299: fullInterfaceDescription = new FullInterfaceDescription(name,
300: id, defined_in_id, version, operations, attributes,
301: base_interfaces, type(), is_abstract);
302:
303: return fullInterfaceDescription;
304: }
305:
306: public AttributeDef create_attribute(String id, String name,
307: String version, IDLType type, AttributeMode mode) {
308: throw new BAD_INV_ORDER("Cannot change RMI/IIOP mapping.");
309: }
310:
311: public OperationDef create_operation(String id, String name,
312: String version, IDLType result, OperationMode mode,
313: ParameterDescription[] params, ExceptionDef[] exceptions,
314: String[] contexts) {
315: throw new BAD_INV_ORDER("Cannot change RMI/IIOP mapping.");
316: }
317:
318: // IDLTypeOperations implementation ------------------------------
319:
320: public TypeCode type() {
321: if (typeCode == null)
322: typeCode = getORB().create_interface_tc(id, name);
323:
324: return typeCode;
325: }
326:
327: // ContainedImpl implementation ----------------------------------
328:
329: public Description describe() {
330: String defined_in_id = "IR";
331:
332: if (defined_in instanceof org.omg.CORBA.ContainedOperations)
333: defined_in_id = ((org.omg.CORBA.ContainedOperations) defined_in)
334: .id();
335:
336: org.omg.CORBA.InterfaceDescription md = new InterfaceDescription(
337: name, id, defined_in_id, version, base_interfaces,
338: false);
339:
340: Any any = getORB().create_any();
341:
342: InterfaceDescriptionHelper.insert(any, md);
343:
344: return new Description(DefinitionKind.dk_Interface, any);
345: }
346:
347: // Y overrides ---------------------------------------------------
348:
349: // Package protected ---------------------------------------------
350:
351: // Protected -----------------------------------------------------
352:
353: /**
354: * My CORBA reference.
355: */
356: protected InterfaceDef ref = null;
357:
358: /**
359: * My cached TypeCode.
360: */
361: protected TypeCode typeCode;
362:
363: // Private -------------------------------------------------------
364:
365: /**
366: * My delegate for Container functionality.
367: */
368: private ContainerImplDelegate delegate;
369:
370: /**
371: * Flag that I am abstract.
372: */
373: private boolean is_abstract;
374:
375: /**
376: * IDs of my superinterfaces.
377: */
378: private String[] base_interfaces;
379:
380: /**
381: * CORBA references of my superinterfaces.
382: */
383: private InterfaceDef[] base_interfaces_ref;
384:
385: /**
386: * My cached FullInterfaceDescription.
387: */
388: private FullInterfaceDescription fullInterfaceDescription;
389:
390: // Inner classes -------------------------------------------------
391: }
|