ohair@286: /* ohair@286: * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. ohair@286: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. ohair@286: * ohair@286: * This code is free software; you can redistribute it and/or modify it ohair@286: * under the terms of the GNU General Public License version 2 only, as ohair@286: * published by the Free Software Foundation. Oracle designates this ohair@286: * particular file as subject to the "Classpath" exception as provided ohair@286: * by Oracle in the LICENSE file that accompanied this code. ohair@286: * ohair@286: * This code is distributed in the hope that it will be useful, but WITHOUT ohair@286: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ohair@286: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ohair@286: * version 2 for more details (a copy is included in the LICENSE file that ohair@286: * accompanied this code). ohair@286: * ohair@286: * You should have received a copy of the GNU General Public License version ohair@286: * 2 along with this work; if not, write to the Free Software Foundation, ohair@286: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. ohair@286: * ohair@286: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@286: * or visit www.oracle.com if you need additional information or have any ohair@286: * questions. ohair@286: */ ohair@286: ohair@286: package com.sun.xml.internal.ws.client; ohair@286: ohair@286: import com.sun.xml.internal.ws.api.handler.MessageHandler; ohair@286: import com.sun.xml.internal.ws.handler.HandlerException; ohair@286: ohair@286: import javax.xml.namespace.QName; ohair@286: import javax.xml.ws.handler.Handler; ohair@286: import javax.xml.ws.handler.LogicalHandler; ohair@286: import javax.xml.ws.handler.soap.SOAPHandler; ohair@286: import java.util.*; ohair@286: ohair@286: /** ohair@286: * This class holds the handler information and roles on the Binding (mutable info in the binding). ohair@286: * ohair@286: * HandlerConfiguration is immutable, and a new object is created when the BindingImpl is created or User calls ohair@286: * Binding.setHandlerChain() or SOAPBinding.setRoles(). ohair@286: * ohair@286: * During invocation in Stub.process(), snapshot of the handler configuration is set in Packet.handlerConfig. The ohair@286: * information in the HandlerConfiguration is used by MUPipe and HandlerTube implementations. ohair@286: * ohair@286: * @author Rama Pulavarthi ohair@286: */ ohair@286: public class HandlerConfiguration { ohair@286: private final Set roles; ohair@286: /** ohair@286: * This chain may contain both soap and logical handlers. ohair@286: */ ohair@286: private final List handlerChain; ohair@286: private final List logicalHandlers; ohair@286: private final List soapHandlers; ohair@286: private final List messageHandlers; ohair@286: private Set handlerKnownHeaders; ohair@286: ohair@286: /** ohair@286: * @param roles This contains the roles assumed by the Binding implementation. ohair@286: * @param handlerChain This contains the handler chain set on the Binding ohair@286: */ ohair@286: public HandlerConfiguration(Set roles, List handlerChain) { ohair@286: this.roles = roles; ohair@286: this.handlerChain = handlerChain; ohair@286: logicalHandlers = new ArrayList(); ohair@286: soapHandlers = new ArrayList(); ohair@286: messageHandlers = new ArrayList(); ohair@286: handlerKnownHeaders = new HashSet(); ohair@286: ohair@286: for (Handler handler : handlerChain) { ohair@286: if (handler instanceof LogicalHandler) { ohair@286: logicalHandlers.add((LogicalHandler) handler); ohair@286: } else if (handler instanceof SOAPHandler) { ohair@286: soapHandlers.add((SOAPHandler) handler); ohair@286: Set headers = ((SOAPHandler) handler).getHeaders(); ohair@286: if (headers != null) { ohair@286: handlerKnownHeaders.addAll(headers); ohair@286: } ohair@286: } else if (handler instanceof MessageHandler) { ohair@286: messageHandlers.add((MessageHandler) handler); ohair@286: Set headers = ((MessageHandler) handler).getHeaders(); ohair@286: if (headers != null) { ohair@286: handlerKnownHeaders.addAll(headers); ohair@286: } ohair@286: }else { ohair@286: throw new HandlerException("handler.not.valid.type", ohair@286: handler.getClass()); ohair@286: } ohair@286: } ohair@286: } ohair@286: ohair@286: /** ohair@286: * This is called when roles as reset on binding using SOAPBinding#setRoles(), to save reparsing the handlers again. ohair@286: * @param roles ohair@286: * @param oldConfig ohair@286: */ ohair@286: public HandlerConfiguration(Set roles, HandlerConfiguration oldConfig) { ohair@286: this.roles = roles; ohair@286: this.handlerChain = oldConfig.handlerChain; ohair@286: this.logicalHandlers = oldConfig.logicalHandlers; ohair@286: this.soapHandlers = oldConfig.soapHandlers; ohair@286: this.messageHandlers = oldConfig.messageHandlers; ohair@286: this.handlerKnownHeaders = oldConfig.handlerKnownHeaders; ohair@286: } ohair@286: ohair@286: public Set getRoles() { ohair@286: return roles; ohair@286: } ohair@286: ohair@286: /** ohair@286: * ohair@286: * @return return a copy of handler chain ohair@286: */ ohair@286: public List getHandlerChain() { ohair@286: if(handlerChain == null) ohair@286: return Collections.emptyList(); ohair@286: return new ArrayList(handlerChain); ohair@286: ohair@286: } ohair@286: ohair@286: public List getLogicalHandlers() { ohair@286: return logicalHandlers; ohair@286: } ohair@286: ohair@286: public List getSoapHandlers() { ohair@286: return soapHandlers; ohair@286: } ohair@286: ohair@286: public List getMessageHandlers() { ohair@286: return messageHandlers; ohair@286: } ohair@286: ohair@286: public Set getHandlerKnownHeaders() { ohair@286: return handlerKnownHeaders; ohair@286: } ohair@286: ohair@286: }