1 26 27 package org.objectweb.openccm.ast.lib; 28 29 30 import org.objectweb.openccm.ast.api.TypeRef; 31 32 33 import org.objectweb.openccm.ast.api.DeclarationKind; 34 35 36 import org.objectweb.openccm.ast.api.Declaration; 37 38 39 import org.objectweb.openccm.ast.api.ExceptionDecl; 40 41 42 import org.objectweb.openccm.ast.api.StringList; 43 44 45 import org.objectweb.openccm.ast.api.Parameter; 46 47 48 import org.omg.CORBA.OperationDef ; 49 import org.omg.CORBA.OperationDefHelper; 50 51 52 import org.omg.CORBA.OperationMode ; 53 54 55 import org.omg.CORBA.ExceptionDef ; 56 57 58 import org.omg.CORBA.ParameterDescription ; 59 60 85 86 public class OperationDeclImpl 87 extends OperationBaseImpl 88 implements org.objectweb.openccm.ast.api.OperationDecl 89 { 90 96 97 private OperationDef operation_def_; 98 99 102 protected OperationMode mode_; 103 104 105 private StringListImpl contexts_; 106 107 113 119 protected 120 OperationDeclImpl(Repository rep, 121 ScopeImpl parent) 122 { 123 super(rep, parent); 125 126 operation_def_ = null; 128 mode_ = OperationMode.OP_NORMAL; 129 contexts_ = new StringListImpl(); 130 } 131 132 138 144 149 protected void 150 load(org.omg.CORBA.Contained contained) 151 { 152 operation_def_ = OperationDefHelper.narrow(contained); 153 mode_ = operation_def_.mode(); 154 setType(getRepository(). 155 getAsTypeRef(operation_def_.result_def())); 156 ParameterDescription [] params = operation_def_.params(); 157 for (int i=0; i<params.length; i++) 158 { 159 parameters_.addParam(params[i].name, 160 getRepository().getAsTypeRef(params[i].type_def), 161 params[i].mode); 162 } 163 ExceptionDef [] exc = operation_def_.exceptions(); 164 for (int i=0; i<exc.length; i++) 165 { 166 exceptions_.add((ExceptionDecl)getRepository(). 167 lookupId(exc[i].id())); 168 } 169 String [] contexts = operation_def_.contexts(); 170 for (int i=0; i<contexts.length; i++) 171 contexts_.add(contexts[i]); 172 173 super.load(contained); 174 } 175 176 181 protected void 182 loadAsMapping(org.omg.CORBA.Contained contained) 183 { 184 operation_def_ = OperationDefHelper.narrow(contained); 185 mode_ = operation_def_.mode(); 186 setType(getRepository(). 187 getAsMappedTypeRef(operation_def_.result_def())); 188 189 ParameterDescription [] params = operation_def_.params(); 190 for (int i=0; i<params.length; i++) 191 { 192 parameters_.addParam(params[i].name, 193 getRepository().getAsMappedTypeRef(params[i].type_def), 194 params[i].mode); 195 } 196 197 ExceptionDef [] exc = operation_def_.exceptions(); 198 for (int i=0; i<exc.length; i++) 199 { 200 exceptions_.add((ExceptionDecl)getRepository(). 201 lookupMappedId(exc[i].id())); 202 } 203 204 String [] contexts = operation_def_.contexts(); 205 for (int i=0; i<contexts.length; i++) 206 contexts_.add(contexts[i]); 207 208 super.loadAsMapping(contained); 209 } 210 211 217 protected org.omg.CORBA.Contained 218 getContained() 219 { 220 return operation_def_; 221 } 222 223 229 235 243 public Declaration[] 244 getDependencies() 245 { 246 if (dependencies_!=null) 247 return dependencies_; 248 249 java.util.List op_depend = new java.util.ArrayList (); 250 Declaration[] depend = null; 251 252 if (getType().isDeclaration()) 254 op_depend.add(getType()); 255 256 depend = getType().getDependencies(); 257 for (int i=0; i<depend.length; i++) 258 op_depend.add(depend[i]); 259 260 ExceptionDecl[] excs = exceptions_.getExceptions(); 262 for (int i=0; i<excs.length; i++) 263 { 264 op_depend.add(excs[i]); 265 depend = excs[i].getDependencies(); 266 for (int j=0; j<depend.length; j++) 267 { 268 if (op_depend.indexOf(depend[j])==-1) 269 op_depend.add(depend[j]); 270 } 271 } 272 273 Parameter[] parameters = parameters_.getParameters(); 275 for (int i=0;i<parameters.length;i++) 276 { 277 TypeRef param_type = parameters[i].getType(); 278 if (param_type.isDeclaration()) 279 op_depend.add(param_type); 280 281 depend = param_type.getDependencies(); 282 for (int j=0;j<depend.length;j++) 283 { 284 if (op_depend.indexOf(depend[j])==-1) 285 op_depend.add(depend[j]); 286 } 287 } 288 289 dependencies_ = (Declaration[])op_depend.toArray(new Declaration[0]); 290 return dependencies_; 294 } 295 296 302 307 public long 308 getDeclKind() 309 { 310 return DeclarationKind.dk_operation; 311 } 312 313 316 public void 317 create() 318 { 319 operation_def_ = the_parent_. 320 createOperation(this, 321 getIDLType(), 322 mode_, 323 parameters_.getParameterDescriptionSeq(), 324 exceptions_.getExceptionDefSeq(), 325 contexts_.getStrings()); 326 } 327 328 334 340 343 public void 344 setOneway() 345 { 346 mode_ = OperationMode.OP_ONEWAY; 347 } 348 349 354 public boolean 355 isOneway() 356 { 357 return mode_ == OperationMode.OP_ONEWAY; 358 } 359 360 363 public void 364 setNormal() 365 { 366 mode_ = OperationMode.OP_NORMAL; 367 } 368 369 374 public boolean 375 isNormal() 376 { 377 return mode_ == OperationMode.OP_NORMAL; 378 } 379 380 385 public StringList 386 getContextList() 387 { 388 return contexts_; 389 } 390 } 391 | Popular Tags |