1 55 56 package org.jboss.axis.handlers; 57 58 import org.jboss.axis.utils.ClassUtils; 59 import org.jboss.axis.utils.Messages; 60 61 import javax.xml.rpc.JAXRPCException ; 62 import javax.xml.rpc.handler.Handler ; 63 import javax.xml.rpc.handler.HandlerInfo ; 64 import javax.xml.rpc.handler.MessageContext ; 65 import javax.xml.rpc.handler.soap.SOAPMessageContext ; 66 import javax.xml.rpc.soap.SOAPFaultException ; 67 import java.util.ArrayList ; 68 import java.util.List ; 69 import java.util.Map ; 70 71 74 public class HandlerChainImpl extends ArrayList implements javax.xml.rpc.handler.HandlerChain 75 { 76 77 private String [] _roles; 78 79 private int falseIndex = -1; 80 81 public String [] getRoles() 82 { 83 return _roles; 84 } 85 86 public void setRoles(String [] roles) 87 { 88 _roles = roles; 89 } 90 91 public void init(Map map) 92 { 93 } 95 96 protected List handlerInfos = new ArrayList (); 97 String [] roles = null; 98 99 public HandlerChainImpl() 100 { 101 } 102 103 public HandlerChainImpl(List handlerInfos) 104 { 105 this.handlerInfos = handlerInfos; 106 for (int i = 0; i < handlerInfos.size(); i++) 107 { 108 add(newHandler(getHandlerInfo(i))); 109 } 110 } 111 112 public void addNewHandler(String className, Map config) 113 { 114 try 115 { 116 HandlerInfo handlerInfo = new HandlerInfo (ClassUtils.forName(className), 117 config, 118 null); 119 handlerInfos.add(handlerInfo); 120 add(newHandler(handlerInfo)); 121 } 122 catch (Exception ex) 123 { 124 String messageText = Messages.getMessage("NoJAXRPCHandler00", className); 125 throw new JAXRPCException (messageText, ex); 126 } 127 } 128 129 public boolean handleFault(MessageContext _context) 130 { 131 SOAPMessageContext context = (SOAPMessageContext )_context; 132 133 for (int i = size() - 1; i >= 0; i--) 134 { 135 if (getHandlerInstance(i).handleFault(context) == false) 136 { 137 return false; 138 } 139 } 140 return true; 141 } 142 143 public boolean handleRequest(MessageContext _context) 144 { 145 SOAPMessageContext context = (SOAPMessageContext )_context; 146 147 falseIndex = -1; 148 for (int i = 0; i < size(); i++) 149 { 150 Handler currentHandler = getHandlerInstance(i); 151 try 152 { 153 if (currentHandler.handleRequest(context) == false) 154 { 155 falseIndex = i; 156 return false; 157 } 158 } 159 catch (SOAPFaultException sfe) 160 { 161 throw sfe; 162 } 163 } 164 return true; 165 } 166 167 public boolean handleResponse(MessageContext context) 168 { 169 int endIdx = size() - 1; 170 if (falseIndex != -1) 171 { 172 endIdx = falseIndex; 173 } 174 for (int i = endIdx; i >= 0; i--) 175 { 176 if (getHandlerInstance(i).handleResponse(context) == false) 177 { 178 return false; 179 } 180 } 181 return true; 182 } 183 184 public void destroy() 185 { 186 for (int i = 0; i < size(); i++) 187 { 188 getHandlerInstance(i).destroy(); 189 } 190 clear(); 191 } 192 193 private Handler getHandlerInstance(int index) 194 { 195 return (Handler )get(index); 196 } 197 198 private HandlerInfo getHandlerInfo(int index) 199 { 200 return (HandlerInfo )handlerInfos.get(index); 201 } 202 203 private Handler newHandler(HandlerInfo handlerInfo) 204 { 205 try 206 { 207 Handler handler = 208 (Handler )handlerInfo.getHandlerClass().newInstance(); 209 handler.init(handlerInfo); 210 return handler; 211 } 212 catch (Exception ex) 213 { 214 String messageText = Messages.getMessage("NoJAXRPCHandler00", handlerInfo.getHandlerClass().toString()); 215 throw new JAXRPCException (messageText, ex); 216 } 217 } 218 } 219 220 | Popular Tags |