1 28 29 package org.coach.reactor; 30 31 import org.objectweb.ccm.visitorIDL3.common.*; 32 33 40 41 public class IDLTranslator 42 { 43 49 55 58 public 59 IDLTranslator() 60 { 61 } 62 63 69 75 78 public java.lang.String 79 toIDL(org.objectweb.ccm.IDL3.TypeRef typeref) 80 { 81 switch(typeref.getTypeKind()) 82 { 83 case org.objectweb.ccm.IDL3.TypeKind._tk_null : 84 return "null"; 85 case org.objectweb.ccm.IDL3.TypeKind._tk_void : 86 return "void"; 87 case org.objectweb.ccm.IDL3.TypeKind._tk_short : 88 return "short"; 89 case org.objectweb.ccm.IDL3.TypeKind._tk_ushort : 90 return "unsigned short"; 91 case org.objectweb.ccm.IDL3.TypeKind._tk_long : 92 return "long"; 93 case org.objectweb.ccm.IDL3.TypeKind._tk_ulong : 94 return "unsigned long"; 95 case org.objectweb.ccm.IDL3.TypeKind._tk_longlong : 96 return "long long"; 97 case org.objectweb.ccm.IDL3.TypeKind._tk_ulonglong : 98 return "unsigned long long"; 99 case org.objectweb.ccm.IDL3.TypeKind._tk_float : 100 return "float"; 101 case org.objectweb.ccm.IDL3.TypeKind._tk_double : 102 return "double"; 103 case org.objectweb.ccm.IDL3.TypeKind._tk_longdouble : 104 return "long double"; 105 case org.objectweb.ccm.IDL3.TypeKind._tk_boolean : 106 return "boolean"; 107 case org.objectweb.ccm.IDL3.TypeKind._tk_char : 108 return "char"; 109 case org.objectweb.ccm.IDL3.TypeKind._tk_wchar : 110 return "wchar"; 111 case org.objectweb.ccm.IDL3.TypeKind._tk_octet : 112 return "octet"; 113 case org.objectweb.ccm.IDL3.TypeKind._tk_any : 114 return "any"; 115 case org.objectweb.ccm.IDL3.TypeKind._tk_Principal : 116 return "::CORBA::Principal"; 117 case org.objectweb.ccm.IDL3.TypeKind._tk_TypeCode : 118 return "::CORBA::TypeCode"; 119 120 case org.objectweb.ccm.IDL3.TypeKind._tk_objref : 121 return "Object"; 122 123 case org.objectweb.ccm.IDL3.TypeKind._tk_struct : 124 case org.objectweb.ccm.IDL3.TypeKind._tk_union : 125 case org.objectweb.ccm.IDL3.TypeKind._tk_enum : 126 case org.objectweb.ccm.IDL3.TypeKind._tk_exception : 127 case org.objectweb.ccm.IDL3.TypeKind._tk_alias : 128 case org.objectweb.ccm.IDL3.TypeKind._tk_value_box : 129 case org.objectweb.ccm.IDL3.TypeKind._tk_value : 130 case org.objectweb.ccm.IDL3.TypeKind._tk_native : 131 case org.objectweb.ccm.IDL3.TypeKind._tk_abstract_interface : 132 case org.objectweb.ccm.IDL3.TypeKind._tk_local_interface : 133 case org.objectweb.ccm.IDL3.TypeKind._tk_interface : 134 case org.objectweb.ccm.IDL3.TypeKind._tk_component : 135 case org.objectweb.ccm.IDL3.TypeKind._tk_event : 136 case org.objectweb.ccm.IDL3.TypeKind._tk_home : 137 org.objectweb.ccm.IDL3.Declaration decl = null; 138 decl = (org.objectweb.ccm.IDL3.Declaration)typeref; 139 return decl.getAbsoluteName(); 140 141 case org.objectweb.ccm.IDL3.TypeKind._tk_string : 142 int l = ((org.objectweb.ccm.IDL3.TypeRefImpl)typeref).getLength(); 143 if (l==0) 144 return "string"; 145 return "string<"+l+">"; 146 case org.objectweb.ccm.IDL3.TypeKind._tk_wstring : 147 l = ((org.objectweb.ccm.IDL3.TypeRefImpl)typeref).getLength(); 148 if (l==0) 149 return "wstring"; 150 return "wstring<"+l+">"; 151 case org.objectweb.ccm.IDL3.TypeKind._tk_sequence : 152 org.objectweb.ccm.IDL3.TypeRefImpl impl= (org.objectweb.ccm.IDL3.TypeRefImpl)typeref; 153 l = impl.getLength(); 154 java.lang.String str = toIDL(impl.getContentType()); 155 if (l==0) 156 return "sequence<"+str+">"; 157 return "sequence<"+str+","+l+">"; 158 case org.objectweb.ccm.IDL3.TypeKind._tk_array : 159 impl = (org.objectweb.ccm.IDL3.TypeRefImpl)typeref; 160 str = toIDL(impl.getContentType()); 161 return str; 162 case org.objectweb.ccm.IDL3.TypeKind._tk_fixed : 163 impl= (org.objectweb.ccm.IDL3.TypeRefImpl)typeref; 164 return "fixed<"+impl.getDigits()+","+impl.getScale()+">"; 165 default : 166 return ""; 167 } 168 } 169 170 173 public java.lang.String 174 toIDLPostfix(org.objectweb.ccm.IDL3.TypeRef typeref) 175 { 176 switch(typeref.getTypeKind()) 177 { 178 case org.objectweb.ccm.IDL3.TypeKind._tk_array : 179 org.objectweb.ccm.IDL3.TypeRefImpl impl = null; 180 impl = (org.objectweb.ccm.IDL3.TypeRefImpl)typeref; 181 java.lang.String str = toIDLPostfix(impl.getContentType()); 182 int l = impl.getLength(); 183 return str+"["+l+"]"; 184 default : 185 return ""; 186 } 187 } 188 189 192 public java.lang.String 193 toString(org.objectweb.ccm.IDL3.AnyValue anyvalue, 194 org.objectweb.ccm.IDL3.TypeRef typeref) 195 { 196 if (anyvalue.isInteger()) 200 return java.lang.String.valueOf(anyvalue.getAsInteger()); 201 else if (anyvalue.isString()) 202 return "\""+anyvalue.getAsString()+"\""; 203 else if (anyvalue.isWString()) 204 return "L\""+anyvalue.getAsWString()+"\""; 205 else if (anyvalue.isChar()) 206 return "\'"+java.lang.String.valueOf(anyvalue.getAsChar())+"\'"; 207 else if (anyvalue.isWChar()) 208 return "L\'"+java.lang.String.valueOf(anyvalue.getAsWChar())+"\'"; 209 else if (anyvalue.isFloating()) 210 return java.lang.String.valueOf(anyvalue.getAsFloating()); 211 else if (anyvalue.isFixed()) 212 return anyvalue.getAsFixed(); 213 else if (anyvalue.isBoolean()) 214 { 215 if (anyvalue.getAsBoolean()) 216 return "TRUE"; 217 218 return "FALSE"; 219 } 220 else if (anyvalue.isEnum()) 221 { 222 java.lang.String abs_name = ((org.objectweb.ccm.IDL3.EnumDecl)typeref).getParent().getAbsoluteName(); 224 return abs_name + "::" + anyvalue.getAsEnum(); 225 } 226 else 227 return ""; 228 } 229 } 230 | Popular Tags |