1 26 27 package org.objectweb.ccm.IDL3; 28 29 37 38 public class OperationDeclImpl 39 extends DeclarationImpl 40 implements OperationDecl 41 { 42 48 51 private org.omg.CORBA.OperationDef operation_def_; 52 53 56 protected int mode_; 57 58 61 protected TypeRef result_; 62 63 66 protected ParameterListImpl parameters_; 67 68 71 protected ExceptionListImpl exceptions_; 72 73 76 private org.objectweb.ccm.util.Vector contexts_; 77 78 84 89 protected 90 OperationDeclImpl(Repository rep, ScopeImpl parent) 91 { 92 super(rep, parent); 94 95 operation_def_ = null; 97 mode_ = OperationDecl.OP_NORMAL; 98 result_ = null; 99 parameters_ = new ParameterListImpl(); 100 exceptions_ = new ExceptionListImpl(); 101 contexts_ = new org.objectweb.ccm.util.Vector(); 102 the_declaration_kind_ = DeclarationKind._dk_operation; 103 } 104 105 111 118 protected void 119 addParam(String name, 120 TypeRef type, 121 org.omg.CORBA.ParameterMode mode) 122 { 123 parameters_.addParam(name, type, mode.value()); 124 } 125 126 131 protected void 132 load(org.omg.CORBA.Contained contained) 133 { 134 operation_def_ = org.omg.CORBA.OperationDefHelper.narrow(contained); 135 mode_ = operation_def_.mode().value(); 136 setResultType(getRepository().getAsTypeRef(operation_def_.result_def())); 137 org.omg.CORBA.ParameterDescription [] params = operation_def_.params(); 138 for (int i=0;i<params.length;i++) 139 { 140 addParam(params[i].name, 141 getRepository().getAsTypeRef(params[i].type_def), 142 params[i].mode); 143 } 144 org.omg.CORBA.ExceptionDef [] exc = operation_def_.exceptions(); 145 for (int i=0;i<exc.length;i++) 146 { 147 exceptions_.add((ExceptionRef)getRepository().lookupId(exc[i].id())); 148 } 149 String [] contexts = operation_def_.contexts(); 150 for (int i=0;i<contexts.length;i++) 151 addContext(contexts[i]); 152 153 super.load(contained); 154 } 155 156 161 protected void 162 loadAsMapping(org.omg.CORBA.Contained contained) 163 { 164 operation_def_ = org.omg.CORBA.OperationDefHelper.narrow(contained); 165 mode_ = operation_def_.mode().value(); 166 setResultType(getRepository().getAsMappedTypeRef(operation_def_.result_def())); 167 org.omg.CORBA.ParameterDescription [] params = operation_def_.params(); 168 for (int i=0;i<params.length;i++) 169 { 170 addParam(params[i].name, 171 getRepository().getAsMappedTypeRef(params[i].type_def), 172 params[i].mode); 173 } 174 org.omg.CORBA.ExceptionDef [] exc = operation_def_.exceptions(); 175 for (int i=0;i<exc.length;i++) 176 { 177 exceptions_.add((ExceptionRef)getRepository().lookupMappedId(exc[i].id())); 178 } 179 String [] contexts = operation_def_.contexts(); 180 for (int i=0;i<contexts.length;i++) 181 addContext(contexts[i]); 182 183 super.loadAsMapping(contained); 184 } 185 186 192 195 public void 196 create() 197 { 198 String [] contexts = new String [contexts_.size()]; 199 for(int i=0; i<contexts.length; i++) 200 contexts[i] = (String )(contexts_.get(i)); 201 202 operation_def_ = the_parent_.createOperation(this, 203 result_.getIDLType(), 204 org.omg.CORBA.OperationMode.from_int(mode_), 205 parameters_.getParameterDescs(), 206 exceptions_.getExceptionDefs(), 207 contexts); 208 } 209 210 217 public Declaration[] 218 getDependencies() 219 { 220 if (dependencies_!=null) 221 return dependencies_; 222 223 org.objectweb.ccm.util.Vector op_depend = new org.objectweb.ccm.util.Vector(); 224 Declaration[] depend = null; 225 226 if (getType().isDeclaration()) 228 op_depend.add(getType()); 229 230 depend = getType().getDependencies(); 231 for (int i=0;i<depend.length;i++) 232 op_depend.add(depend[i]); 233 234 ExceptionDecl[] excs = getExceptions(); 236 for (int i=0;i<excs.length;i++) 237 { 238 op_depend.add(excs[i]); 239 depend = excs[i].getDependencies(); 240 for (int j=0;j<depend.length;j++) 241 { 242 if (op_depend.indexOf(depend[j])==-1) 243 op_depend.add(depend[j]); 244 } 245 } 246 247 TypeRef[] param_types = getParameters().getParamTypes(); 249 for (int i=0;i<param_types.length;i++) 250 { 251 if (param_types[i].isDeclaration()) 252 op_depend.add(param_types[i]); 253 254 depend = param_types[i].getDependencies(); 255 for (int j=0;j<depend.length;j++) 256 { 257 if (op_depend.indexOf(depend[j])==-1) 258 op_depend.add(depend[j]); 259 } 260 } 261 262 dependencies_ = (Declaration[])op_depend.toArray(new Declaration[0]); 263 return dependencies_; 264 } 265 266 267 268 274 280 public void 281 addInParam(String name, 282 TypeRef type) 283 { 284 addParam(name, type, org.omg.CORBA.ParameterMode.PARAM_IN); 285 } 286 287 293 296 public void 297 setNormal() 298 { 299 mode_ = OperationDecl.OP_NORMAL; 300 } 301 302 305 public void 306 setOneway() 307 { 308 mode_ = OperationDecl.OP_ONEWAY; 309 } 310 311 316 public void 317 setResultType(TypeRef type) 318 { 319 if(type != null) 320 { 321 result_ = type; 322 result_.addRef(); 323 } 324 } 325 326 332 public void 333 addOutParam(String name, 334 TypeRef type) 335 { 336 addParam(name, type, org.omg.CORBA.ParameterMode.PARAM_OUT); 337 } 338 339 345 public void 346 addInOutParam(String name, 347 TypeRef type) 348 { 349 addParam(name, type, org.omg.CORBA.ParameterMode.PARAM_INOUT); 350 } 351 352 357 public void 358 addContext(String name) 359 { 360 contexts_.add(name); 361 } 362 363 366 public boolean 367 isOneway() 368 { 369 return mode_==OperationDecl.OP_ONEWAY; 370 } 371 372 375 public TypeRef 376 getType() 377 { 378 return result_; 379 } 380 381 384 public ExceptionList 385 getExceptionList() 386 { 387 return exceptions_; 388 } 389 390 393 public ExceptionDecl[] 394 getExceptions() 395 { 396 return exceptions_.getExceptions(); 397 } 398 399 402 public ParameterList 403 getParameters() 404 { 405 return parameters_; 406 } 407 408 411 public String [] 412 getContexts() 413 { 414 String [] result = new String [contexts_.size()]; 415 for (int i=0;i<result.length;i++) 416 { 417 result[i] = (String )contexts_.get(i); 418 } 419 return result; 420 } 421 422 428 431 public void 432 destroy() 433 { 434 if (result_!=null) 435 result_.removeRef(); 436 437 exceptions_.destroy(); 438 parameters_.destroy(); 439 super.destroy(); 440 } 441 442 448 protected org.omg.CORBA.Contained 449 getContained() 450 { 451 return operation_def_; 452 } 453 } 454 | Popular Tags |