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.siplite.header;
028:
029: import gov.nist.siplite.address.*;
030: import gov.nist.core.*;
031:
032: /**
033: * ToHeader SIP Header.
034: * <a "href=${docRoot}/uncopyright.html">This code is in the public domain.</a>
035: *
036: */
037: public final class ToHeader extends AddressParametersHeader {
038: /** To header field label. */
039: public static final String NAME = Header.TO;
040: /** Tag label. */
041: public static final String TAG = "tag";
042: /** Class handle. */
043: public static Class clazz;
044:
045: static {
046: clazz = new ToHeader().getClass();
047: }
048:
049: /**
050: * Default constructor.
051: */
052: public ToHeader() {
053: super (TO);
054: }
055:
056: /**
057: * Generates a TO header from a FROM header.
058: * @param from sender addres
059: */
060: public ToHeader(FromHeader from) {
061: super (TO);
062: address = (Address) from.address.clone();
063: parameters = (NameValueList) from.parameters.clone();
064: }
065:
066: /**
067: * Compares two ToHeader headers for equality.
068: * @param otherHeader Object to set
069: * @return true if the two headers are the same.
070: */
071: public boolean equals(Object otherHeader) {
072: try {
073: if (!otherHeader.getClass().equals(this .getClass())) {
074: return false;
075: }
076: return super .equals(otherHeader);
077:
078: } finally {
079: // System.out.println("equals " + retval + exitpoint);
080: }
081: }
082:
083: /**
084: * Encodes the header content into a String.
085: * @return String
086: */
087: public String encodeBody() {
088: String retval = "";
089: if (address.getAddressType() != Address.NAME_ADDR) {
090: retval += Separators.LESS_THAN;
091: }
092: retval += address.encode();
093: if (address.getAddressType() != Address.NAME_ADDR) {
094: retval += Separators.GREATER_THAN;
095: }
096: retval += encodeWithSep();
097: return retval;
098: }
099:
100: /**
101: * Gets the tag parameter from the address parm list.
102: * @return tag field
103: */
104: public String getTag() {
105: return getParameter(TAG);
106: }
107:
108: /**
109: * Returns true if tag is present.
110: * @return true if the Tag exist
111: */
112: public boolean hasTag() {
113: return hasParameter(TAG);
114: }
115:
116: /**
117: * Sets the tag member.
118: * @param t String to set
119: */
120: public void setTag(String t) {
121: setParameter(TAG, t);
122: }
123:
124: /**
125: * Removes the tag field.
126: */
127: public void removeTag() {
128: removeParameter(TAG);
129: }
130: }
|