001: /*
002: * Portions Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025: package com.sun.xml.internal.ws.handler;
026:
027: import javax.xml.ws.handler.MessageContext;
028:
029: import com.sun.xml.internal.ws.pept.ept.MessageInfo;
030: import com.sun.xml.internal.ws.encoding.soap.internal.InternalMessage;
031: import com.sun.xml.internal.ws.encoding.soap.internal.HeaderBlock;
032: import com.sun.xml.internal.ws.encoding.soap.internal.AttachmentBlock;
033: import com.sun.xml.internal.ws.spi.runtime.InternalSoapEncoder;
034: import com.sun.xml.internal.ws.spi.runtime.Invoker;
035: import java.lang.reflect.Method;
036: import java.util.List;
037: import java.util.ArrayList;
038:
039: /**
040: * The HandlerContext is used in the client and server runtime
041: * in {@link com.sun.xml.internal.ws.protocol.soap.client.SOAPMessageDispatcher} and
042: * {@link com.sun.xml.internal.ws.protocol.soap.server.SOAPMessageDispatcher} to hold
043: * information about the current message.
044: *
045: * <p>It stores a {@link com.sun.xml.internal.ws.pept.ept.MessageInfo} and
046: * {@link com.sun.xml.internal.ws.encoding.soap.internal.InternalMessage}
047: * which are used by the rest of the runtime, and provides a bridge
048: * between these and the soap and logical message contexts that
049: * are used by the handlers.
050: *
051: * @see LogicalMessageContextImpl
052: * @see MessageContextImpl
053: * @see SOAPMessageContextImpl
054: *
055: * @author WS Development Team
056: */
057: public class HandlerContext {
058:
059: private MessageInfo messageInfo;
060: private InternalMessage internalMessage;
061: private MessageContext msgContext;
062:
063: private Method method;
064: private Invoker invoker;
065: private String algorithm;
066: private String bindingId;
067:
068: public HandlerContext(MessageInfo messageInfo,
069: InternalMessage internalMessage) {
070: this .messageInfo = messageInfo;
071: this .internalMessage = internalMessage;
072: this .msgContext = new MessageContextImpl();
073: //populateAttachmentMap();
074: }
075:
076: /**
077: * @return Returns the soapMessage.
078: */
079: public MessageContext getMessageContext() {
080: return msgContext;
081: }
082:
083: public void setMessageContext(MessageContext msgContext) {
084: this .msgContext = msgContext;
085: }
086:
087: public InternalMessage getInternalMessage() {
088: return internalMessage;
089: }
090:
091: /**
092: * @param internalMessage The internalMessage to set.
093: */
094: public void setInternalMessage(InternalMessage internalMessage) {
095: this .internalMessage = internalMessage;
096: populateAttachmentMap();
097: }
098:
099: public MessageInfo getMessageInfo() {
100: return messageInfo;
101: }
102:
103: /**
104: * @param messageInfo The messageInfo to set.
105: */
106: public void setMessageInfo(MessageInfo messageInfo) {
107: this .messageInfo = messageInfo;
108: }
109:
110: /*
111: * Returns the invocation method
112: */
113: public Method getMethod() {
114: return method;
115: }
116:
117: public void setMethod(Method method) {
118: this .method = method;
119: }
120:
121: /*
122: * Returns InternalMessage's BodyBlock value. It can be null for empty body.
123: */
124: public Object getBody() {
125: return (internalMessage == null) ? null : ((internalMessage
126: .getBody() == null) ? null : internalMessage.getBody()
127: .getValue());
128: }
129:
130: /*
131: * Returns InternalMessage's HeaderBlock values
132: */
133: public List getHeaders() {
134: List<HeaderBlock> headerBlocks = (internalMessage == null) ? null
135: : internalMessage.getHeaders();
136: if (headerBlocks != null) {
137: List headers = new ArrayList();
138: for (HeaderBlock headerBlock : headerBlocks) {
139: if (headerBlock.getValue() != null) {
140: headers.add(headerBlock.getValue());
141: }
142: }
143: return headers;
144: }
145: return null;
146: }
147:
148: public String getBindingId() {
149: return bindingId;
150: }
151:
152: public void setBindingId(String bindingID) {
153: bindingId = bindingID;
154: }
155:
156: public void setCanonicalization(String algorithm) {
157: this .algorithm = algorithm;
158: }
159:
160: public Invoker getInvoker() {
161: return invoker;
162: }
163:
164: public void setInvoker(Invoker invoker) {
165: this .invoker = invoker;
166: }
167:
168: public void populateAttachmentMap() {
169: //populate the attachment map
170: if (internalMessage != null) {
171: for (AttachmentBlock ab : internalMessage.getAttachments()
172: .values()) {
173: MessageContextUtil.addMessageAttachment(msgContext, ab
174: .getId(), ab.asDataHandler());
175: }
176: }
177: }
178:
179: }
|