1 16 package org.apache.axis2.phaseresolver; 17 18 import org.apache.axis2.description.HandlerDescription; 19 import org.apache.axis2.engine.Handler; 20 import org.apache.axis2.engine.Phase; 21 22 import java.util.ArrayList ; 23 24 25 28 public class PhaseHolder { 29 30 31 private ArrayList phaseList; 32 33 public PhaseHolder(ArrayList phases) { 34 this.phaseList = phases; 35 } 36 37 public PhaseHolder() { 38 } 39 40 46 private boolean isPhaseExist(String phaseName) { 47 for (int i = 0; i < phaseList.size(); i++) { 48 Phase phase = (Phase) phaseList.get(i); 49 if (phase.getPhaseName().equals(phaseName)) { 50 return true; 51 } 52 } 53 return false; 54 } 55 56 62 public void addHandler(HandlerDescription handler) throws PhaseException { 63 String phaseName = handler.getRules().getPhaseName(); 64 if (isPhaseExist(phaseName)) { 65 getPhase(phaseName).addHandler(handler); 66 } else { 67 throw new PhaseException("Invalid Phase ," + phaseName 68 + "for the handler " 69 + handler.getName() 70 + " dose not exit in axis2.xml or refering to phase in diffrent flow"); 71 } 72 } 73 74 80 private Phase getPhase(String phaseName) { 81 for (int i = 0; i < phaseList.size(); i++) { 82 Phase phase = (Phase) phaseList.get(i); 83 if (phase.getPhaseName().equals(phaseName)) { 84 return phase; 85 } 86 } 87 return null; 88 } 89 90 97 public void buildTransportHandlerChain(Phase phase, ArrayList handlers) throws PhaseException { 98 try { 99 Class handlerClass = null; 100 Handler handler; 101 for (int i = 0; i < handlers.size(); i++) { 102 HandlerDescription description = (HandlerDescription) handlers.get(i); 103 handlerClass = Class.forName(description.getClassName(), true, 104 Thread.currentThread().getContextClassLoader()); 105 handler = 106 (Handler) handlerClass.newInstance(); 107 handler.init(description); 108 description.setHandler(handler); 109 phase.addHandler(description.getHandler()); 110 } 111 } catch (ClassNotFoundException e) { 112 throw new PhaseException(e); 113 } catch (InstantiationException e) { 114 throw new PhaseException(e); 115 } catch (IllegalAccessException e) { 116 throw new PhaseException(e); 117 } 118 } 119 120 } 121 | Popular Tags |