FileDocCategorySizeDatePackage
HandlerChainImpl.javaAPI DocApache Axis 1.48632Sat Apr 22 18:57:28 BST 2006org.apache.axis.handlers

HandlerChainImpl

public class HandlerChainImpl extends ArrayList implements javax.xml.rpc.handler.HandlerChain
Implementation of HandlerChain

Fields Summary
protected static Log
log
public static final String
JAXRPC_METHOD_INFO
private String[]
_roles
private int
falseIndex
protected List
handlerInfos
Constructors Summary
public HandlerChainImpl()


      
    
public HandlerChainImpl(List handlerInfos)

        this.handlerInfos = handlerInfos;
        for (int i = 0; i < handlerInfos.size(); i++) {
            add(newHandler(getHandlerInfo(i)));
        }
    
Methods Summary
public voidaddNewHandler(java.lang.String className, java.util.Map config)

        try {
            HandlerInfo handlerInfo =
                new HandlerInfo(ClassUtils.forName(className), config, null);
            handlerInfos.add(handlerInfo);
            add(newHandler(handlerInfo));
        } catch (Exception ex) {
            String messageText =
                    Messages.getMessage("NoJAXRPCHandler00", className);
            throw new JAXRPCException(messageText, ex);
        }
    
public voiddestroy()

        int endIdx = size() - 1;
        if (falseIndex != -1) {
            endIdx = falseIndex;
        }
        for (int i = endIdx; i >= 0; i--) {
            getHandlerInstance(i).destroy();
        }
        falseIndex = -1;
        clear();
    
private javax.xml.rpc.handler.HandlerInfogetHandlerInfo(int index)

        return (HandlerInfo)handlerInfos.get(index);
    
private javax.xml.rpc.handler.HandlergetHandlerInstance(int index)

        return (Handler)get(index);
    
public java.util.ArrayListgetMessageInfo(javax.xml.soap.SOAPMessage message)

        ArrayList list = new ArrayList();
        try {
            if(message == null || message.getSOAPPart() == null)
                return list;
            SOAPEnvelope env = message.getSOAPPart().getEnvelope();
            SOAPBody body = env.getBody();
            Iterator it = body.getChildElements();
            SOAPElement operation = (SOAPElement)it.next();
            list.add(operation.getElementName().toString());
            for (Iterator i = operation.getChildElements(); i.hasNext();) {
                SOAPElement elt = (SOAPElement)i.next();
                list.add(elt.getElementName().toString());
            }
        } catch (Exception e) {
            log.debug("Exception in getMessageInfo : ", e);
        }
        return list;
    
public java.lang.String[]getRoles()


       
        return _roles;
    
public booleanhandleFault(javax.xml.rpc.handler.MessageContext _context)

        SOAPMessageContext context = (SOAPMessageContext)_context;
        preInvoke(context);
        try {
            int endIdx = size() - 1;
            if (falseIndex != -1) {
                endIdx = falseIndex;
            }
            for (int i = endIdx; i >= 0; i--) {
                if (getHandlerInstance(i).handleFault(context) == false) {
                    return false;
                }
            }
            return true;
        } finally {
            postInvoke(context);
        }
    
public booleanhandleRequest(javax.xml.rpc.handler.MessageContext _context)

        org.apache.axis.MessageContext actx =
                (org.apache.axis.MessageContext)_context;
        actx.setRoles(getRoles());
        SOAPMessageContext context = (SOAPMessageContext)_context;
        preInvoke(context);
        try {
            for (int i = 0; i < size(); i++) {
                Handler currentHandler = getHandlerInstance(i);
                try {
                    if (currentHandler.handleRequest(context) == false) {
                        falseIndex = i;
                        return false;
                    }
                } catch (SOAPFaultException sfe) {
                    falseIndex = i;
                    throw sfe;
                }
            }
            return true;
        } finally {
            postInvoke(context);
        }
    
public booleanhandleResponse(javax.xml.rpc.handler.MessageContext context)

        SOAPMessageContext scontext = (SOAPMessageContext)context;
        preInvoke(scontext);
        try {
            int endIdx = size() - 1;
            if (falseIndex != -1) {
                endIdx = falseIndex;
            }
            for (int i = endIdx; i >= 0; i--) {
                if (getHandlerInstance(i).handleResponse(context) == false) {
                    return false;
                }
            }
            return true;
        } finally {
            postInvoke(scontext);
        }
    
public voidinit(java.util.Map map)

        // DO SOMETHING WITH THIS
    
private javax.xml.rpc.handler.HandlernewHandler(javax.xml.rpc.handler.HandlerInfo handlerInfo)

        try {
            Handler handler = (Handler)handlerInfo.getHandlerClass()
                            .newInstance();
            handler.init(handlerInfo);
            return handler;
        } catch (Exception ex) {
            String messageText =
                    Messages.getMessage("NoJAXRPCHandler00",
                    handlerInfo.getHandlerClass().toString());
            throw new JAXRPCException(messageText, ex);
        }
    
private voidpostInvoke(javax.xml.rpc.handler.soap.SOAPMessageContext msgContext)

        Boolean propFormOptimization = (Boolean)msgContext.getProperty(org.apache.axis.SOAPPart.ALLOW_FORM_OPTIMIZATION);
        if (propFormOptimization != null && !propFormOptimization.booleanValue()) {
            msgContext.setProperty(org.apache.axis.SOAPPart.ALLOW_FORM_OPTIMIZATION,
                    Boolean.TRUE);
            SOAPMessage message = msgContext.getMessage();
            ArrayList oldList =
                    (ArrayList)msgContext.getProperty(JAXRPC_METHOD_INFO);
            if (oldList != null) {
                if (!Arrays.equals(oldList.toArray(), getMessageInfo(message)
                                .toArray())) {
                    throw new RuntimeException(Messages.getMessage("invocationArgumentsModified00"));
                }
            }
            try {
                if (message != null) {
                    message.saveChanges();
                }
            } catch (SOAPException e) {
                log.debug("Exception in postInvoke : ", e);
                throw new RuntimeException("Exception in postInvoke : " + e.toString());
            }
        }
    
private voidpreInvoke(javax.xml.rpc.handler.soap.SOAPMessageContext msgContext)

        try {
            SOAPMessage message = msgContext.getMessage();
            // Ensure that message is already in the form we want 
            if(message != null && message.getSOAPPart() != null)
                message.getSOAPPart().getEnvelope();
            msgContext.setProperty(org.apache.axis.SOAPPart.ALLOW_FORM_OPTIMIZATION,
                    Boolean.FALSE);
            msgContext.setProperty(JAXRPC_METHOD_INFO, getMessageInfo(message));
        } catch (Exception e) {
            log.debug("Exception in preInvoke : ", e);
            throw new RuntimeException("Exception in preInvoke : " + e.toString());
        }
    
public voidsetRoles(java.lang.String[] roles)

        if (roles != null) {
            // use clone for cheap array copy
            _roles = (String[])roles.clone();
        }