001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.message;
019:
020: import java.util.Collection;
021: import java.util.IdentityHashMap;
022: import java.util.Map;
023: import java.util.Set;
024:
025: import org.apache.cxf.endpoint.Endpoint;
026: import org.apache.cxf.interceptor.InterceptorChain;
027: import org.apache.cxf.service.Service;
028: import org.apache.cxf.service.model.OperationInfo;
029: import org.apache.cxf.transport.Destination;
030:
031: public class MessageImpl extends StringMapImpl implements Message {
032: static int count;
033:
034: private Collection<Attachment> attachments;
035: private Exchange exchange;
036: private String id;
037: private InterceptorChain interceptorChain;
038: private Map<Class<?>, Object> contents = new IdentityHashMap<Class<?>, Object>(
039: 6);
040:
041: public Collection<Attachment> getAttachments() {
042: return attachments;
043: }
044:
045: public void setAttachments(Collection<Attachment> attachments) {
046: this .attachments = attachments;
047: }
048:
049: public String getAttachmentMimeType() {
050: //for sub class overriding
051: return null;
052: }
053:
054: public Destination getDestination() {
055: return get(Destination.class);
056: }
057:
058: public Exchange getExchange() {
059: return exchange;
060: }
061:
062: public String getId() {
063: return id;
064: }
065:
066: public InterceptorChain getInterceptorChain() {
067: return this .interceptorChain;
068: }
069:
070: public <T> T getContent(Class<T> format) {
071: return format.cast(contents.get(format));
072: }
073:
074: public <T> void setContent(Class<T> format, Object content) {
075: contents.put(format, content);
076: }
077:
078: public <T> void removeContent(Class<T> format) {
079: contents.remove(format);
080: }
081:
082: public Set<Class<?>> getContentFormats() {
083: return contents.keySet();
084: }
085:
086: public void setDestination(Destination d) {
087: put(Destination.class, d);
088: }
089:
090: public void setExchange(Exchange e) {
091: this .exchange = e;
092: }
093:
094: public void setId(String i) {
095: this .id = i;
096: }
097:
098: public void setInterceptorChain(InterceptorChain ic) {
099: this .interceptorChain = ic;
100: }
101:
102: public Object getContextualProperty(String key) {
103: Object val = get(key);
104:
105: Exchange ex = getExchange();
106: if (val == null) {
107: val = ex.get(key);
108: }
109:
110: if (val == null) {
111: OperationInfo ep = get(OperationInfo.class);
112: if (ep != null) {
113: val = ep.getProperty(key);
114: }
115: }
116:
117: if (val == null) {
118: Endpoint ep = ex.get(Endpoint.class);
119: if (ep != null) {
120: val = ep.get(key);
121:
122: if (val == null) {
123: val = ep.getEndpointInfo().getProperty(key);
124: }
125:
126: if (val == null) {
127: val = ep.getEndpointInfo().getBinding()
128: .getProperty(key);
129: }
130:
131: }
132: }
133:
134: if (val == null) {
135: Service ep = ex.get(Service.class);
136: if (ep != null) {
137: val = ep.get(key);
138: }
139: }
140:
141: return val;
142: }
143:
144: public static void copyContent(Message m1, Message m2) {
145: for (Class<?> c : m1.getContentFormats()) {
146: m2.setContent(c, m1.getContent(c));
147: }
148: }
149: }
|