1 16 package org.apache.axis2.phaseresolver; 17 18 import org.apache.axis2.description.*; 19 import org.apache.axis2.engine.AxisConfiguration; 20 import org.apache.axis2.engine.AxisConfigurationImpl; 21 import org.apache.axis2.engine.AxisFault; 22 import org.apache.axis2.engine.Phase; 23 import org.apache.axis2.phaseresolver.util.PhaseValidator; 24 25 import javax.xml.namespace.QName ; 26 import java.util.ArrayList ; 27 import java.util.Collection ; 28 import java.util.HashMap ; 29 import java.util.Iterator ; 30 31 34 public class PhaseResolver { 35 38 private AxisConfiguration axisConfig; 39 40 43 private ServiceDescription axisService; 44 45 46 49 private PhaseHolder phaseHolder; 50 51 public PhaseResolver() { 52 } 53 54 59 public PhaseResolver(AxisConfiguration engineConfig) { 60 this.axisConfig = engineConfig; 61 } 62 63 69 public PhaseResolver(AxisConfiguration axisConfig, 70 ServiceDescription serviceContext) { 71 this.axisConfig = axisConfig; 72 this.axisService = serviceContext; 73 } 74 75 81 public void buildchains() throws PhaseException, AxisFault { 82 HashMap operations = axisService.getOperations(); 83 Collection col = operations.values(); 84 for (Iterator iterator = col.iterator(); iterator.hasNext();) { 85 OperationDescription operation = (OperationDescription) iterator.next(); 86 for (int i = 1; i < 5; i++) { 87 buildExcutionChains(i, operation); 88 } 89 } 90 } 91 92 103 private void buildExcutionChains(int type, OperationDescription operation) 104 throws AxisFault, PhaseException { 105 int flowtype = type; 106 ArrayList allHandlers = new ArrayList (); 107 ModuleDescription module; 108 Flow flow = null; 109 ArrayList modulqnames = (ArrayList ) ((AxisConfigurationImpl) axisConfig).getEngadgedModules(); 112 for (int i = 0; i < modulqnames.size(); i++) { 113 QName modulename = (QName ) modulqnames.get(i); 114 module = axisConfig.getModule(modulename); 115 if (module != null) { 116 switch (flowtype) { 117 case PhaseMetadata.IN_FLOW: 118 { 119 flow = module.getInFlow(); 120 break; 121 } 122 case PhaseMetadata.OUT_FLOW: 123 { 124 flow = module.getOutFlow(); 125 break; 126 } 127 case PhaseMetadata.FAULT_IN_FLOW: 128 { 129 flow = module.getFaultInFlow(); 130 break; 131 } 132 case PhaseMetadata.FAULT_OUT_FLOW: 133 { 134 flow = module.getFaultOutFlow(); 135 break; 136 } 137 } 138 axisService.addToEngagModuleList(module); 139 operation.addToEngageModuleList(module); 140 } else { 141 throw new PhaseException("referance to invalid module " + modulename.getLocalPart() + " by axis2.xml"); 142 } 143 144 if (flow != null) { 145 for (int j = 0; j < flow.getHandlerCount(); j++) { 146 HandlerDescription metadata = flow.getHandler(j); 147 148 if (!PhaseValidator.isSystemPhases(metadata.getRules().getPhaseName())) { 149 allHandlers.add(metadata); 150 } else { 151 156 continue; 157 } 158 } 159 } 160 161 } 162 163 switch (flowtype) { 166 case PhaseMetadata.IN_FLOW: 167 { 168 flow = axisService.getInFlow(); 169 break; 170 } 171 case PhaseMetadata.OUT_FLOW: 172 { 173 flow = axisService.getOutFlow(); 174 break; 175 } 176 case PhaseMetadata.FAULT_IN_FLOW: 177 { 178 flow = axisService.getFaultInFlow(); 179 break; 180 } 181 case PhaseMetadata.FAULT_OUT_FLOW: 182 { 183 flow = axisService.getFaultOutFlow(); 184 break; 185 } 186 } 187 if (flow != null) { 188 for (int j = 0; j < flow.getHandlerCount(); j++) { 189 HandlerDescription metadata = flow.getHandler(j); 190 191 if (metadata.getRules().getPhaseName().equals("")) { 193 throw new PhaseException("Phase dose not specified"); 194 } 195 allHandlers.add(metadata); 196 } 197 } 198 switch (flowtype) { 199 case PhaseMetadata.IN_FLOW: 200 { 201 phaseHolder = new PhaseHolder(operation.getRemainingPhasesInFlow()); 202 break; 203 } 204 case PhaseMetadata.OUT_FLOW: 205 { 206 phaseHolder = new PhaseHolder(operation.getPhasesOutFlow()); 207 break; 208 } 209 case PhaseMetadata.FAULT_IN_FLOW: 210 { 211 phaseHolder = new PhaseHolder(operation.getPhasesInFaultFlow()); 212 break; 213 } 214 case PhaseMetadata.FAULT_OUT_FLOW: 215 { 216 phaseHolder = new PhaseHolder(operation.getPhasesOutFaultFlow()); 217 break; 218 } 219 } 220 for (int i = 0; i < allHandlers.size(); i++) { 221 HandlerDescription handlerMetaData = 222 (HandlerDescription) allHandlers.get(i); 223 phaseHolder.addHandler(handlerMetaData); 224 } 225 } 226 227 232 public void buildTranspotsChains() throws PhaseException { 233 HashMap axisTransportIn = axisConfig.getTransportsIn(); 234 HashMap axisTransportOut = axisConfig.getTransportsOut(); 235 236 Collection colintrnsport = axisTransportIn.values(); 237 for (Iterator iterator = colintrnsport.iterator(); 238 iterator.hasNext();) { 239 TransportInDescription transport = (TransportInDescription) iterator.next(); 240 buildINTransportChains(transport); 241 } 242 243 Collection colouttrnsport = axisTransportOut.values(); 244 for (Iterator iterator = colouttrnsport.iterator(); 245 iterator.hasNext();) { 246 TransportOutDescription transport = (TransportOutDescription) iterator.next(); 247 buildOutTransportChains(transport); 248 } 249 } 250 251 252 private void buildINTransportChains(TransportInDescription transport) 253 throws PhaseException { 254 Flow flow = null; 255 Phase phase = null; 256 for (int type = 1; type < 4; type++) { 257 switch (type) { 258 case PhaseMetadata.IN_FLOW: 259 { 260 flow = transport.getInFlow(); 261 phase = transport.getInPhase(); 262 break; 263 } 264 case PhaseMetadata.FAULT_IN_FLOW: 265 { 266 flow = transport.getFaultFlow(); 267 phase = transport.getFaultPhase(); 268 break; 269 } 270 } 271 if (flow != null) { 272 ArrayList handlers = new ArrayList (); 273 for (int j = 0; j < flow.getHandlerCount(); j++) { 274 HandlerDescription metadata = flow.getHandler(j); 275 metadata.getRules().setPhaseName(PhaseMetadata.TRANSPORT_PHASE); 276 handlers.add(metadata); 277 } 278 new PhaseHolder().buildTransportHandlerChain(phase, handlers); 279 }else { 280 continue; 281 } 282 } 283 } 284 285 286 292 private void buildOutTransportChains(TransportOutDescription transport) 293 throws PhaseException { 294 Flow flow = null; 295 Phase phase = null; 296 for (int type = 1; type < 5; type++) { 297 switch (type) { 298 case PhaseMetadata.OUT_FLOW: 299 { 300 flow = transport.getOutFlow(); 301 phase = transport.getOutPhase(); 302 break; 303 } 304 case PhaseMetadata.FAULT_OUT_FLOW: 305 { 306 flow = transport.getFaultFlow(); 307 phase = transport.getFaultPhase(); 308 break; 309 } 310 } 311 if (flow != null) { 312 ArrayList handlers = new ArrayList (); 313 for (int j = 0; j < flow.getHandlerCount(); j++) { 314 HandlerDescription metadata = flow.getHandler(j); 315 metadata.getRules().setPhaseName(PhaseMetadata.TRANSPORT_PHASE); 316 handlers.add(metadata); 317 } 318 new PhaseHolder().buildTransportHandlerChain(phase, handlers); 319 }else { 320 continue; 321 } 322 } 323 } 324 325 326 public void engageModuleGlobally(ModuleDescription module) throws AxisFault { 327 enageToGlobalChain(module); 328 HashMap services = axisConfig.getServices(); 329 Collection serviceCol = services.values(); 330 for (Iterator iterator = serviceCol.iterator(); iterator.hasNext();) { 331 ServiceDescription serviceDescription = (ServiceDescription) iterator.next(); 332 serviceDescription.addModuleOperations(module); 333 engageModuleToServiceFromGlobal(serviceDescription, module); 334 serviceDescription.addToEngagModuleList(module); 335 } 336 } 337 338 345 public void engageModuleToServiceFromGlobal(ServiceDescription service, ModuleDescription module) throws PhaseException { 346 HashMap opeartions = service.getOperations(); 347 Collection opCol = opeartions.values(); 348 boolean engaged = false; 349 for (Iterator iterator = opCol.iterator(); iterator.hasNext();) { 350 OperationDescription opDesc = (OperationDescription) iterator.next(); 351 Collection modules = opDesc.getModules(); 352 for (Iterator iterator1 = modules.iterator(); iterator1.hasNext();) { 353 ModuleDescription description = (ModuleDescription) iterator1.next(); 354 if(description.getName().equals(module.getName())){ 355 engaged = true; 356 break; 357 } 358 } 359 if (engaged) { 360 continue; 361 } 362 Flow flow = null; 363 for (int type = 1; type < 5; type++) { 364 switch (type) { 365 case PhaseMetadata.IN_FLOW: 366 { 367 phaseHolder = new PhaseHolder(opDesc.getRemainingPhasesInFlow()); 368 break; 369 } 370 case PhaseMetadata.OUT_FLOW: 371 { 372 phaseHolder = new PhaseHolder(opDesc.getPhasesOutFlow()); 373 break; 374 } 375 case PhaseMetadata.FAULT_IN_FLOW: 376 { 377 phaseHolder = new PhaseHolder(opDesc.getPhasesInFaultFlow()); 378 break; 379 } 380 case PhaseMetadata.FAULT_OUT_FLOW: 381 { 382 phaseHolder = new PhaseHolder(opDesc.getPhasesOutFaultFlow()); 383 break; 384 } 385 } 386 switch (type) { 390 case PhaseMetadata.IN_FLOW: 391 { 392 flow = module.getInFlow(); 393 break; 394 } 395 case PhaseMetadata.OUT_FLOW: 396 { 397 flow = module.getOutFlow(); 398 break; 399 } 400 case PhaseMetadata.FAULT_IN_FLOW: 401 { 402 flow = module.getFaultInFlow(); 403 break; 404 } 405 case PhaseMetadata.FAULT_OUT_FLOW: 406 { 407 flow = module.getFaultOutFlow(); 408 break; 409 } 410 } 411 if (flow != null) { 412 for (int j = 0; j < flow.getHandlerCount(); j++) { 413 HandlerDescription metadata = flow.getHandler(j); 414 if (!PhaseValidator.isSystemPhases(metadata.getRules().getPhaseName())) { 415 phaseHolder.addHandler(metadata); 416 } else { 417 continue; 418 } 419 } 420 } 421 } 422 opDesc.addToEngageModuleList(module); 423 } 424 } 425 426 427 private void enageToGlobalChain(ModuleDescription module) throws PhaseException { 428 Flow flow = null; 429 for (int type = 1; type < 5; type++) { 430 switch (type) { 431 case PhaseMetadata.IN_FLOW: 432 { 433 phaseHolder = new PhaseHolder(((AxisConfigurationImpl) axisConfig).getInPhasesUptoAndIncludingPostDispatch()); 434 break; 435 } 436 case PhaseMetadata.OUT_FLOW: 437 { 438 phaseHolder = new PhaseHolder(((AxisConfigurationImpl) axisConfig).getOutFlow()); 439 break; 440 } 441 case PhaseMetadata.FAULT_IN_FLOW: 442 { 443 phaseHolder = new PhaseHolder(((AxisConfigurationImpl) axisConfig).getInFaultFlow()); 444 break; 445 } 446 case PhaseMetadata.FAULT_OUT_FLOW: 447 { 448 phaseHolder = new PhaseHolder(((AxisConfigurationImpl) axisConfig).getOutFaultFlow()); 449 break; 450 } 451 } 452 switch (type) { 456 case PhaseMetadata.IN_FLOW: 457 { 458 flow = module.getInFlow(); 459 break; 460 } 461 case PhaseMetadata.OUT_FLOW: 462 { 463 flow = module.getOutFlow(); 464 break; 465 } 466 case PhaseMetadata.FAULT_IN_FLOW: 467 { 468 flow = module.getFaultInFlow(); 469 break; 470 } 471 case PhaseMetadata.FAULT_OUT_FLOW: 472 { 473 flow = module.getFaultOutFlow(); 474 break; 475 } 476 } 477 if (flow != null) { 478 for (int j = 0; j < flow.getHandlerCount(); j++) { 479 HandlerDescription metadata = flow.getHandler(j); 480 if (PhaseValidator.isSystemPhases(metadata.getRules().getPhaseName())) { 481 phaseHolder.addHandler(metadata); 482 } else { 483 489 continue; 490 } 491 } 492 } 493 } 494 } 495 496 497 public void engageModuleToService(ServiceDescription service, ModuleDescription module) throws PhaseException { 498 HashMap opeartions = service.getOperations(); 499 Collection opCol = opeartions.values(); 500 boolean engaged = false; 501 for (Iterator iterator = opCol.iterator(); iterator.hasNext();) { 502 OperationDescription opDesc = (OperationDescription) iterator.next(); 503 Collection modules = opDesc.getModules(); 504 for (Iterator iterator1 = modules.iterator(); iterator1.hasNext();) { 505 ModuleDescription description = (ModuleDescription) iterator1.next(); 506 if(description.getName().equals(module.getName())){ 507 engaged = true; 508 break; 509 } 510 } 511 if (!engaged) { 512 engageModuleToOperation(opDesc,module); 513 opDesc.addToEngageModuleList(module); 514 } 515 } 516 service.addModuleOperations(module); 517 } 518 519 520 public void engageModuleToOperation(OperationDescription operation, ModuleDescription module) throws PhaseException { 521 OperationDescription opDesc = operation; 522 Flow flow = null; 523 for (int type = 1; type < 5; type++) { 524 switch (type) { 525 case PhaseMetadata.IN_FLOW: 526 { 527 phaseHolder = new PhaseHolder(opDesc.getRemainingPhasesInFlow()); 528 break; 529 } 530 case PhaseMetadata.OUT_FLOW: 531 { 532 phaseHolder = new PhaseHolder(opDesc.getPhasesOutFlow()); 533 break; 534 } 535 case PhaseMetadata.FAULT_IN_FLOW: 536 { 537 phaseHolder = new PhaseHolder(opDesc.getPhasesInFaultFlow()); 538 break; 539 } 540 case PhaseMetadata.FAULT_OUT_FLOW: 541 { 542 phaseHolder = new PhaseHolder(opDesc.getPhasesOutFaultFlow()); 543 break; 544 } 545 } 546 547 switch (type) { 548 case PhaseMetadata.IN_FLOW: 549 { 550 flow = module.getInFlow(); 551 break; 552 } 553 case PhaseMetadata.OUT_FLOW: 554 { 555 flow = module.getOutFlow(); 556 break; 557 } 558 case PhaseMetadata.FAULT_IN_FLOW: 559 { 560 flow = module.getFaultInFlow(); 561 break; 562 } 563 case PhaseMetadata.FAULT_OUT_FLOW: 564 { 565 flow = module.getFaultOutFlow(); 566 break; 567 } 568 } 569 if (flow != null) { 570 for (int j = 0; j < flow.getHandlerCount(); j++) { 571 HandlerDescription metadata = flow.getHandler(j); 572 if (!PhaseValidator.isSystemPhases(metadata.getRules().getPhaseName())) { 573 phaseHolder.addHandler(metadata); 574 } else { 575 throw new PhaseException("Service specific module can not refer system pre defined phases : " 576 + metadata.getRules().getPhaseName()); 577 } 578 } 579 } 580 } 581 } 582 } 583 | Popular Tags |