001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)MessageImpl.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.messaging;
030:
031: import java.util.HashMap;
032: import java.util.Iterator;
033: import java.util.Map;
034: import java.util.Set;
035:
036: import javax.jbi.messaging.NormalizedMessage;
037:
038: import javax.activation.DataHandler;
039: import javax.security.auth.Subject;
040: import javax.xml.transform.Source;
041:
042: /** Implementation of JBI <code>NormalizedMessage</code> interface.
043: * @author Sun Microsystems, Inc.
044: */
045: public class MessageImpl implements
046: javax.jbi.messaging.NormalizedMessage {
047: /** Attachment map */
048: private HashMap mAttachments;
049: /** Property map */
050: private HashMap mProperties;
051: /** Message content */
052: private Source mContent;
053:
054: /** Creates a new MessageImpl without content.
055: * @throws javax.jbi.messaging.MessagingException failed to init message.
056: */
057: public MessageImpl() {
058: this (null, new HashMap());
059: }
060:
061: /** Create a new MessageImpl with the specified content and properties.
062: * @param content message content
063: * @param properties message properties
064: * @throws javax.jbi.messaging.MessagingException initialization failed
065: */
066: MessageImpl(Source content, HashMap properties) {
067: mContent = content;
068: mProperties = properties;
069:
070: mAttachments = new HashMap();
071: }
072:
073: /** Returns a Source representation of message content.
074: * @return message content as Source object
075: */
076: public Source getContent() {
077: return mContent;
078: }
079:
080: /** Specifies the content of the message.
081: * @param content message content as Source object
082: */
083: public void setContent(Source content) {
084: mContent = content;
085: }
086:
087: public Object getProperty(String name) {
088: return mProperties.get(name);
089: }
090:
091: HashMap getProperties() {
092: return (mProperties);
093: }
094:
095: void setProperties(HashMap map) {
096: mProperties = map;
097: }
098:
099: public Set getPropertyNames() {
100: return (mProperties.keySet());
101: }
102:
103: public void setProperty(String name, Object value) {
104: mProperties.put(name, value);
105: }
106:
107: public void setSecuritySubject(Subject subject) {
108: setProperty("javax.jbi.security.subject", subject);
109: }
110:
111: public Subject getSecuritySubject() {
112: return ((Subject) getProperty("javax.jbi.security.subject"));
113: }
114:
115: public void addAttachment(String id, DataHandler content)
116: throws javax.jbi.messaging.MessagingException {
117: mAttachments.put(id, content);
118: }
119:
120: public javax.activation.DataHandler getAttachment(String id) {
121: return (DataHandler) mAttachments.get(id);
122: }
123:
124: public Set getAttachmentNames() {
125: return (mAttachments.keySet());
126: }
127:
128: public void removeAttachment(String id)
129: throws javax.jbi.messaging.MessagingException {
130: mAttachments.remove(id);
131: }
132:
133: void setAttachmentMap(HashMap attachments) {
134: mAttachments = attachments;
135: }
136:
137: HashMap getAttachmentMap() {
138: return mAttachments;
139: }
140:
141: public String toString() {
142: StringBuilder sb = new StringBuilder();
143:
144: sb.append(" Message Content(Type): ");
145: sb.append(mContent == null ? "null" : mContent.getClass()
146: .getName());
147: sb.append("\n Properties Count: ");
148: sb.append(mProperties.size());
149: sb.append("\n");
150: for (Iterator p = mProperties.entrySet().iterator(); p
151: .hasNext();) {
152: Map.Entry me = (Map.Entry) p.next();
153: sb.append(" Name: ");
154: sb.append((String) me.getKey());
155: if (me.getValue() instanceof String) {
156: sb.append("\n Value: ");
157: sb.append((String) me.getValue());
158: } else {
159: sb.append("\n Value(Type): ");
160: sb.append(me.getValue().getClass().getName());
161: }
162: sb.append("\n");
163: }
164: sb.append(" Attachments Count: ");
165: sb.append(mAttachments.size());
166: sb.append("\n");
167: for (Iterator p = mAttachments.entrySet().iterator(); p
168: .hasNext();) {
169: Map.Entry me = (Map.Entry) p.next();
170: sb.append(" Name: ");
171: sb.append((String) me.getKey());
172: sb.append("\n DataSource(Type) : ");
173: sb.append(((DataHandler) me.getValue()).getDataSource()
174: .getClass().getName());
175: sb.append("\n");
176: }
177: return (sb.toString());
178: }
179: }
|