src/share/jaxws_classes/com/sun/xml/internal/ws/client/HandlerConfiguration.java

changeset 286
f50545b5e2f1
child 368
0989ad8c0860
equal deleted inserted replaced
284:88b85470e72c 286:f50545b5e2f1
1 /*
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.xml.internal.ws.client;
27
28 import com.sun.xml.internal.ws.api.handler.MessageHandler;
29 import com.sun.xml.internal.ws.handler.HandlerException;
30
31 import javax.xml.namespace.QName;
32 import javax.xml.ws.handler.Handler;
33 import javax.xml.ws.handler.LogicalHandler;
34 import javax.xml.ws.handler.soap.SOAPHandler;
35 import java.util.*;
36
37 /**
38 * This class holds the handler information and roles on the Binding (mutable info in the binding).
39 *
40 * HandlerConfiguration is immutable, and a new object is created when the BindingImpl is created or User calls
41 * Binding.setHandlerChain() or SOAPBinding.setRoles().
42 *
43 * During invocation in Stub.process(), snapshot of the handler configuration is set in Packet.handlerConfig. The
44 * information in the HandlerConfiguration is used by MUPipe and HandlerTube implementations.
45 *
46 * @author Rama Pulavarthi
47 */
48 public class HandlerConfiguration {
49 private final Set<String> roles;
50 /**
51 * This chain may contain both soap and logical handlers.
52 */
53 private final List<Handler> handlerChain;
54 private final List<LogicalHandler> logicalHandlers;
55 private final List<SOAPHandler> soapHandlers;
56 private final List<MessageHandler> messageHandlers;
57 private Set<QName> handlerKnownHeaders;
58
59 /**
60 * @param roles This contains the roles assumed by the Binding implementation.
61 * @param handlerChain This contains the handler chain set on the Binding
62 */
63 public HandlerConfiguration(Set<String> roles, List<Handler> handlerChain) {
64 this.roles = roles;
65 this.handlerChain = handlerChain;
66 logicalHandlers = new ArrayList<LogicalHandler>();
67 soapHandlers = new ArrayList<SOAPHandler>();
68 messageHandlers = new ArrayList<MessageHandler>();
69 handlerKnownHeaders = new HashSet<QName>();
70
71 for (Handler handler : handlerChain) {
72 if (handler instanceof LogicalHandler) {
73 logicalHandlers.add((LogicalHandler) handler);
74 } else if (handler instanceof SOAPHandler) {
75 soapHandlers.add((SOAPHandler) handler);
76 Set<QName> headers = ((SOAPHandler<?>) handler).getHeaders();
77 if (headers != null) {
78 handlerKnownHeaders.addAll(headers);
79 }
80 } else if (handler instanceof MessageHandler) {
81 messageHandlers.add((MessageHandler) handler);
82 Set<QName> headers = ((MessageHandler<?>) handler).getHeaders();
83 if (headers != null) {
84 handlerKnownHeaders.addAll(headers);
85 }
86 }else {
87 throw new HandlerException("handler.not.valid.type",
88 handler.getClass());
89 }
90 }
91 }
92
93 /**
94 * This is called when roles as reset on binding using SOAPBinding#setRoles(), to save reparsing the handlers again.
95 * @param roles
96 * @param oldConfig
97 */
98 public HandlerConfiguration(Set<String> roles, HandlerConfiguration oldConfig) {
99 this.roles = roles;
100 this.handlerChain = oldConfig.handlerChain;
101 this.logicalHandlers = oldConfig.logicalHandlers;
102 this.soapHandlers = oldConfig.soapHandlers;
103 this.messageHandlers = oldConfig.messageHandlers;
104 this.handlerKnownHeaders = oldConfig.handlerKnownHeaders;
105 }
106
107 public Set<String> getRoles() {
108 return roles;
109 }
110
111 /**
112 *
113 * @return return a copy of handler chain
114 */
115 public List<Handler> getHandlerChain() {
116 if(handlerChain == null)
117 return Collections.emptyList();
118 return new ArrayList<Handler>(handlerChain);
119
120 }
121
122 public List<LogicalHandler> getLogicalHandlers() {
123 return logicalHandlers;
124 }
125
126 public List<SOAPHandler> getSoapHandlers() {
127 return soapHandlers;
128 }
129
130 public List<MessageHandler> getMessageHandlers() {
131 return messageHandlers;
132 }
133
134 public Set<QName> getHandlerKnownHeaders() {
135 return handlerKnownHeaders;
136 }
137
138 }

mercurial