1 22 package org.jboss.iiop.rmi.ir; 23 24 import org.omg.CORBA.ContainerOperations ; 25 import org.omg.CORBA.Contained ; 26 import org.omg.CORBA.ContainedHelper; 27 import org.omg.CORBA.Container ; 28 import org.omg.CORBA.ContainerPackage.Description; 29 import org.omg.CORBA.IDLType ; 30 import org.omg.CORBA.DefinitionKind ; 31 import org.omg.CORBA.StructMember ; 32 import org.omg.CORBA.UnionMember ; 33 import org.omg.CORBA.InterfaceDef ; 34 import org.omg.CORBA.EnumDef ; 35 import org.omg.CORBA.ValueDef ; 36 import org.omg.CORBA.StructDef ; 37 import org.omg.CORBA.UnionDef ; 38 import org.omg.CORBA.ConstantDef ; 39 import org.omg.CORBA.ModuleDef ; 40 import org.omg.CORBA.ValueBoxDef ; 41 import org.omg.CORBA.Initializer ; 42 import org.omg.CORBA.AliasDef ; 43 import org.omg.CORBA.NativeDef ; 44 import org.omg.CORBA.ExceptionDef ; 45 import org.omg.CORBA.BAD_INV_ORDER ; 46 47 import java.util.Map ; 48 import java.util.HashMap ; 49 import java.util.Collection ; 50 import java.util.ArrayList ; 51 52 58 class ContainerImplDelegate 59 implements ContainerOperations 60 { 61 63 65 67 private static final org.jboss.logging.Logger logger = 68 org.jboss.logging.Logger.getLogger(ContainerImplDelegate.class); 69 70 72 75 ContainerImplDelegate(LocalContainer delegateFor) 76 { 77 this.delegateFor = delegateFor; 78 } 79 80 82 84 public LocalContained _lookup(String search_name) 85 { 86 logger.debug("ContainerImplDelegate._lookup(\"" + search_name + 87 "\") entered."); 88 if (search_name.startsWith("::")) 89 return delegateFor.getRepository()._lookup(search_name.substring(2)); 90 91 int idx = search_name.indexOf("::"); 92 if (idx > 0) { 93 String first = search_name.substring(0, idx); 94 logger.debug("ContainerImplDelegate._lookup(\"" + search_name + 95 "\") looking for \"" + first + "\"."); 96 Object o = contMap.get(first); 97 98 if (o == null || !(o instanceof LocalContainer)) 99 return null; 100 else { 101 LocalContainer next = (LocalContainer)o; 102 String rest = search_name.substring(idx + 2); 103 104 return next._lookup(rest); 105 } 106 } else 107 return (LocalContained)contMap.get(search_name); 108 } 109 110 public LocalContained[] _contents(DefinitionKind limit_type, 111 boolean exclude_inherited) 112 { 113 int target = limit_type.value(); 114 Collection found; 115 116 if (target == DefinitionKind._dk_all) 117 found = cont; 118 else { 119 found = new ArrayList (); 120 for (int i = 0; i < cont.size(); ++i) { 121 LocalContained val = (LocalContained)cont.get(i); 122 123 if (target == val.def_kind().value()) { 124 if (!exclude_inherited || val.defined_in() == delegateFor) 125 found.add(val); 126 } 127 } 128 } 129 130 LocalContained[] res = new LocalContained[found.size()]; 131 res = (LocalContained[])found.toArray(res); 132 133 return res; 134 } 135 136 public LocalContained[] _lookup_name(String search_name, 137 int levels_to_search, 138 DefinitionKind limit_type, 139 boolean exclude_inherited) 140 { 141 if (levels_to_search == 0) 142 return null; 143 144 if (levels_to_search == -1) 145 ++levels_to_search; 147 Collection found = new ArrayList (); 148 LocalContained[] here = _contents(limit_type, exclude_inherited); 149 150 for (int i = 0; i < here.length; ++i) 151 if (here[i].name().equals(search_name)) 152 found.add(here[i]); 153 154 if (levels_to_search >= 0) { 155 for (int i = 0; i < here.length; ++i) { 157 if (here[i] instanceof Container ) { LocalContainer container = (LocalContainer)here[i]; 159 160 LocalContained[] c; 161 c = container._lookup_name(search_name, levels_to_search - 1, 162 limit_type, exclude_inherited); 163 if (c != null) 164 for (int j = 0; j < c.length; ++j) 165 found.add(c[j]); 166 167 } 168 } 169 170 } 171 172 LocalContained[] res = new LocalContained[found.size()]; 173 res = (LocalContained[])found.toArray(res); 174 175 return res; 176 } 177 178 public void shutdown() 179 { 180 for (int i = 0; i < cont.size(); ++i) 181 ((LocalContained)cont.get(i)).shutdown(); 182 } 183 184 186 public Contained lookup(String search_name) 187 { 188 LocalContained c = _lookup(search_name); 189 190 if (c == null) 191 return null; 192 else 193 return ContainedHelper.narrow(c.getReference()); 194 } 195 196 public Contained [] contents(DefinitionKind limit_type, 197 boolean exclude_inherited) 198 { 199 LocalContained[] c = _contents(limit_type, exclude_inherited); 200 Contained [] res = new Contained [c.length]; 201 202 for (int i = 0; i < c.length; ++i) 203 res[i] = ContainedHelper.narrow(c[i].getReference()); 204 205 return res; 206 } 207 208 public Contained [] lookup_name(String search_name, int levels_to_search, 209 DefinitionKind limit_type, 210 boolean exclude_inherited) 211 { 212 LocalContained[] c = _lookup_name(search_name, levels_to_search, 213 limit_type, exclude_inherited); 214 Contained [] res = new Contained [c.length]; 215 216 for (int i = 0; i < c.length; ++i) 217 res[i] = ContainedHelper.narrow(c[i].getReference()); 218 219 return res; 220 } 221 222 public Description[] describe_contents(DefinitionKind limit_type, 223 boolean exclude_inherited, 224 int max_returned_objs) 225 { 226 Contained [] c = contents(limit_type, exclude_inherited); 227 int returnSize; 228 229 if (max_returned_objs != -1 && c.length > max_returned_objs) 230 returnSize = max_returned_objs; 231 else 232 returnSize = c.length; 233 234 Description[] ret = new Description[returnSize]; 235 236 for (int i = 0; i < returnSize; ++i) { 237 org.omg.CORBA.ContainedPackage.Description d = c[i].describe(); 238 239 ret[i] = new Description(c[i], d.kind, d.value); 240 } 241 242 return ret; 243 } 244 245 public ModuleDef create_module(String id, String name, String version) 246 { 247 throw new BAD_INV_ORDER ("Cannot change RMI/IIOP mapping."); 248 } 249 250 public ConstantDef create_constant(String id, String name, String version, 251 IDLType type, org.omg.CORBA.Any value) 252 { 253 throw new BAD_INV_ORDER ("Cannot change RMI/IIOP mapping."); 254 } 255 256 public StructDef create_struct(String id, String name, String version, 257 StructMember [] members) 258 { 259 throw new BAD_INV_ORDER ("Cannot change RMI/IIOP mapping."); 260 } 261 262 public UnionDef create_union(String id, String name, String version, 263 IDLType discriminator_type, 264 UnionMember [] members) 265 { 266 throw new BAD_INV_ORDER ("Cannot change RMI/IIOP mapping."); 267 } 268 269 public EnumDef create_enum(String id, String name, String version, 270 String [] members) 271 { 272 throw new BAD_INV_ORDER ("Cannot change RMI/IIOP mapping."); 273 } 274 275 public AliasDef create_alias(String id, String name, String version, 276 IDLType original_type) 277 { 278 throw new BAD_INV_ORDER ("Cannot change RMI/IIOP mapping."); 279 } 280 281 public InterfaceDef create_interface(String id, String name, String version, 282 InterfaceDef [] base_interfaces, 283 boolean is_abstract) 284 { 285 throw new BAD_INV_ORDER ("Cannot change RMI/IIOP mapping."); 286 } 287 288 public ValueDef create_value(String id, String name, String version, 289 boolean is_custom, boolean is_abstract, 290 ValueDef base_value, boolean is_truncatable, 291 ValueDef [] abstract_base_values, 292 InterfaceDef [] supported_interfaces, 293 Initializer [] initializers) 294 { 295 throw new BAD_INV_ORDER ("Cannot change RMI/IIOP mapping."); 296 } 297 298 public ValueBoxDef create_value_box(String id, String name, String version, 299 IDLType original_type_def) 300 { 301 throw new BAD_INV_ORDER ("Cannot change RMI/IIOP mapping."); 302 } 303 304 public ExceptionDef create_exception(String id, String name, String version, 305 StructMember [] members) 306 { 307 throw new BAD_INV_ORDER ("Cannot change RMI/IIOP mapping."); 308 } 309 310 public NativeDef create_native(String id, String name, String version) 311 { 312 throw new BAD_INV_ORDER ("Cannot change RMI/IIOP mapping."); 313 } 314 315 316 318 public DefinitionKind def_kind() 319 { 320 throw new RuntimeException ("Should not be called."); 321 } 322 323 public void destroy() 324 { 325 throw new RuntimeException ("Should not be called."); 326 } 327 328 329 331 void add(String name, LocalContained contained) 332 throws IRConstructionException 333 { 334 if (contained.getRepository() != delegateFor.getRepository()) 335 throw new IRConstructionException("Wrong repository"); 336 if (contMap.get(name) != null) 337 throw new IRConstructionException("Duplicate name: " + name); 338 cont.add(contained); 339 contMap.put(name, contained); 340 logger.debug("ContainerDelegateImpl.add() added \"" + name + "\"."); 341 } 342 343 346 void allDone() 347 throws IRConstructionException 348 { 349 logger.debug("ContainerDelegateImpl.allDone() entered "); 350 for (int i = 0; i < cont.size(); ++i) { 351 LocalContained item = (LocalContained)cont.get(i); 352 353 logger.debug("Container[" + item.id() + "].allDone() calling [" + 354 item.id() + "].allDone()"); 355 item.allDone(); 356 } 357 logger.debug("ContainerDelegateImpl.allDone() done "); 358 } 359 360 362 364 367 private ArrayList cont = new ArrayList (); 368 369 372 private Map contMap = new HashMap (); 373 374 377 private LocalContainer delegateFor; 378 379 380 } 382 | Popular Tags |