001: /*
002: * Portions Copyright 2000-2007 Sun Microsystems, Inc. All Rights
003: * Reserved. Use is subject to license terms.
004: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License version
008: * 2 only, as published by the Free Software Foundation.
009: *
010: * This program is distributed in the hope that it will be useful, but
011: * WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * General Public License version 2 for more details (a copy is
014: * included at /legal/license.txt).
015: *
016: * You should have received a copy of the GNU General Public License
017: * version 2 along with this work; if not, write to the Free Software
018: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
019: * 02110-1301 USA
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
022: * Clara, CA 95054 or visit www.sun.com if you need additional
023: * information or have any questions.
024: */
025: /*
026: */
027: package gov.nist.javax.sdp.fields;
028:
029: import gov.nist.core.*;
030: import gov.nist.javax.sdp.*;
031:
032: /**
033: * Phone Field SDP header.
034: *
035: * @version JSR141-PUBLIC-REVIEW (subject to change).
036: *
037: *
038: * <a href="{@docRoot}/uncopyright.html">This code is in the public domain.</a>
039: *
040: */
041: public class PhoneField extends SDPField {
042: /** Addressbook name. */
043: protected String name;
044: /** Entry phone number. */
045: protected String phoneNumber;
046:
047: /**
048: * Copies the current instance.
049: * @return the copy of this object
050: */
051: public Object clone() {
052: PhoneField retval = new PhoneField();
053: retval.name = this .name;
054: retval.phoneNumber = this .phoneNumber;
055: return retval;
056: }
057:
058: /** Default constructor. */
059: public PhoneField() {
060: super (PHONE_FIELD);
061: }
062:
063: /**
064: * Gets the name field.
065: * @return the name
066: */
067: public String getName() {
068: return name;
069: }
070:
071: /**
072: * Gets the phone number.
073: * @return the textual phone number
074: */
075: public String getPhoneNumber() {
076: return phoneNumber;
077: }
078:
079: /**
080: * Sets the name member.
081: * @param name the name to set.
082: */
083: public void setName(String name) {
084: this .name = name;
085: }
086:
087: /**
088: * Sets the phone number member.
089: * @param phoneNumber phone number to set.
090: */
091: public void setPhoneNumber(String phoneNumber) {
092: this .phoneNumber = phoneNumber;
093: }
094:
095: /**
096: * Returns the value.
097: * @throws SdpParseException if a parsing error occurs
098: * @return the value.
099: */
100: public String getValue() throws SdpParseException {
101: return getName();
102: }
103:
104: /**
105: * Sets the value.
106: * @param value the - new information.
107: * @throws SdpException if the value is null
108: */
109: public void setValue(String value) throws SdpException {
110: if (value == null)
111: throw new SdpException("The value parameter is null");
112: else
113: setName(value);
114: }
115:
116: /**
117: * Gets the string encoded version of this object.
118: * Here, we implement only the "name <phoneNumber>" form
119: * and not the "phoneNumber (name)" form
120: * @return encoded string of object contents
121: * @since v1.0
122: */
123: public String encode() {
124: String encoded_string;
125: encoded_string = PHONE_FIELD;
126: if (name != null) {
127: encoded_string += name + Separators.LESS_THAN;
128: }
129: encoded_string += phoneNumber;
130: if (name != null) {
131: encoded_string += Separators.GREATER_THAN;
132: }
133: encoded_string += Separators.NEWLINE;
134: return encoded_string;
135: }
136:
137: }
|