KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > SOFAnode > Made > CodeGen > IDLMapping


1 /* $Id: IDLMapping.java,v 1.2 2004/05/20 14:23:51 bures Exp $ */
2 package SOFA.SOFAnode.Made.CodeGen;
3
4 import SOFA.SOFAnode.Made.TIR.CDLRepository;
5 import SOFA.SOFAnode.Made.TIR.CDLType;
6 import SOFA.SOFAnode.Made.TIR.Contained;
7 import SOFA.SOFAnode.Made.TIR.Identification;
8 import SOFA.SOFAnode.Made.TIR.PrimitiveDef;
9 import SOFA.SOFAnode.Made.TIR.PrimitiveKind;
10
11 /** Mapping of CDL types to IDL.
12   *
13   * @author Petr Hnetynka
14   */

15 public class IDLMapping implements Mapping {
16   /** Returns name of the type in IDL.
17     * @param type cdl type (TIR object)
18     * @return string with type name or null
19     */

20   public String JavaDoc getImplTypeName(CDLType type) {
21     try {
22       if (type instanceof PrimitiveDef) {
23         int primKind = ((PrimitiveDef) type).kind().value();
24         switch (primKind) {
25           case PrimitiveKind.pk_void:
26             return "void";
27           case PrimitiveKind.pk_ushort:
28             return "unsigned short";
29           case PrimitiveKind.pk_short:
30             return "short";
31           case PrimitiveKind.pk_ulong:
32             return "unsigned long";
33           case PrimitiveKind.pk_long:
34             return "long";
35           case PrimitiveKind.pk_ulonglong:
36             return "unsigned long long";
37           case PrimitiveKind.pk_longlong:
38             return "long long";
39           case PrimitiveKind.pk_float:
40             return "float";
41           case PrimitiveKind.pk_double:
42             return "double";
43           case PrimitiveKind.pk_longdouble:
44             return "long double";
45           case PrimitiveKind.pk_boolean:
46             return "boolean";
47           case PrimitiveKind.pk_wchar:
48             return "wchar";
49           case PrimitiveKind.pk_char:
50             return "char";
51           case PrimitiveKind.pk_octet:
52             return "octet";
53           case PrimitiveKind.pk_wstring:
54             return "wstring";
55           case PrimitiveKind.pk_string:
56             return "string";
57           case PrimitiveKind.pk_any:
58             return "any";
59           case PrimitiveKind.pk_object:
60             return "object";
61         }
62       } else {
63         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
64         Contained cnt = (Contained) type;
65         while (! (cnt instanceof CDLRepository)) {
66           Identification id = cnt.get_identification();
67           String JavaDoc version = id.version();
68           String JavaDoc name = id.name();
69           if (sb.length() == 0) {
70             sb.append(name);
71           } else {
72             sb.insert(0,".");
73             sb.insert(0,name);
74           }
75           cnt = (Contained) cnt.get_defined_in();
76         }
77         return sb.toString();
78       }
79     } catch (java.rmi.RemoteException JavaDoc e) {
80       return null;
81     }
82     return null;
83   }
84 }
85
Popular Tags