01: /*
02: *
03: *
04: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: */
26:
27: package com.sun.tck.wma.sms;
28:
29: import com.sun.tck.wma.TextMessage;
30: import com.sun.tck.wma.MessageConnection;
31: import com.sun.midp.io.j2me.sms.TextEncoder;
32:
33: /**
34: * Implements an instance of a text message.
35: */
36: public class TextObject extends MessageObject implements TextMessage {
37:
38: /** Buffer that will hold the text payload. */
39: private byte[] buffer;
40:
41: /**
42: * Construct a text specific message.
43: * @param addr the destination address of the message.
44: */
45: public TextObject(String addr) {
46: super (MessageConnection.TEXT_MESSAGE, addr);
47: }
48:
49: /**
50: * Returns a <code>String</code> representing the message payload data.
51: *
52: * @return <code>null</code> if the payload isn't set, or
53: * this message's payload
54: * @see #setPayloadText
55: */
56: public String getPayloadText() {
57: if (buffer == null) {
58: return null;
59: }
60: return TextEncoder.toString(buffer);
61: }
62:
63: /**
64: * Sets this message's payload data. It may be <code>null</code>.
65: * @param data a <code>String</code> representing the payload data
66: * @see #getPayloadText
67: */
68: public void setPayloadText(String data) {
69: if (data != null) {
70: buffer = TextEncoder.toByteArray(data);
71: } else {
72: buffer = null;
73: }
74: }
75:
76: /**
77: * Gets the raw byte array.
78: * @return an array of raw UCS-2 payload data
79: * @see #getPayloadText
80: * @see #setBytes
81: */
82: public byte[] getPayloadData() {
83: return buffer;
84: }
85:
86: /**
87: * Sets the raw byte array.
88: * @param data an array of raw UCS-2 payload data.
89: * @see #getBytes
90: */
91: public void setPayloadData(byte[] data) {
92: buffer = data;
93: }
94:
95: }
|