FileDocCategorySizeDatePackage
HeaderList.javaAPI DocphoneME MR2 API (J2ME)9661Wed May 02 18:00:42 BST 2007gov.nist.siplite.header

HeaderList

public class HeaderList extends Header
This is a list for the headers. This code is in the public domain.

Fields Summary
protected Vector
sipHeaderVector
SIP header list.
Constructors Summary
public HeaderList()
Default constructor

        sipHeaderVector = new Vector();
    
public HeaderList(String sipHeaderName)
Constructor with initial header.

param
sipHeaderName to set

        sipHeaderVector = new Vector();
        this.headerName = sipHeaderName;
    
Methods Summary
public voidadd(java.lang.Object sipHeader)
Adds a new element.

param
sipHeader to add

        if (headerName != null) {
            String expandedName1 = NameMap.expandHeaderName(headerName);
            String expandedName2 = NameMap.expandHeaderName(
                ((Header)sipHeader).getHeaderName());

            if (!expandedName1.equalsIgnoreCase(expandedName2)) {
                throw new IllegalArgumentException("bad type");
            }
        }

        if (sipHeader != null)
            sipHeaderVector.addElement(sipHeader);
    
public voidaddFirst(java.lang.Object sipHeader)
Adds a new element on the top of the list.

param
sipHeader to add

        if (sipHeader != null) {
            Vector vec = new Vector();
            vec.addElement(sipHeader);
            for (int i = 0; i < sipHeaderVector.size(); i++) {
                vec.addElement(sipHeaderVector.elementAt(i));
            }
            sipHeaderVector = vec;
        }
    
public java.lang.Objectclone()
Copies the current instance.

return
copy of the current instance

        try {
            HeaderList retval =
                    (HeaderList)this.getClass().newInstance();
            if (this.headerName != null)
                retval.headerName = new String(this.headerName);
            if (this.headerValue != null)
                retval.headerValue = new String(this.headerValue);
            retval.sipHeaderVector = new Vector();
            for (int i = 0; i < sipHeaderVector.size(); i ++) {
                Header siphdr = (Header) sipHeaderVector.elementAt(i);
                Header newHdr = (Header) siphdr.clone();
                retval.sipHeaderVector.addElement(newHdr);
            }
            return (Object) retval;
        } catch (Exception ex) {
            ex.printStackTrace();
            System.out.print("Problem with clone method");
            System.exit(0);
            return null;
        }
    
public voidconcatenate(gov.nist.siplite.header.HeaderList other, boolean top)
Concatenates two compatible lists. This appends or prepends the new list to the end of this list.

param
other HeaderList to set
param
top boolean to set

        if (other != null) {
            if (top) {
                for (int i = 0; i < size(); i++) {
                    Header sipHeader = (Header)elementAt(i);
                    other.add(sipHeader);
                }
            } else {
                for (int i = 0; i < other.size(); i++) {
                    Header sipHeader = (Header)other.elementAt(i);
                    add(sipHeader);
                }
            }
        }
    
public java.lang.ObjectelementAt(int i)
Returns the element at the position i.

return
Object
param
i index of the requested element

        return sipHeaderVector.elementAt(i);
    
public java.lang.Stringencode()
Encodes the contents as a string.

return
encoded string of object contents

        if (sipHeaderVector.isEmpty() || headerName == null)
            return "";

        StringBuffer encoding = new StringBuffer();

        // The following headers do not have comma separated forms for
        // multiple headers. Thus, they must be encoded separately.
        if (this.headerName.equals(WWW_AUTHENTICATE) ||
                this.headerName.equals(PROXY_AUTHENTICATE) ||
                this.headerName.equals(AUTHORIZATION) ||
                this.headerName.equals(PROXY_AUTHORIZATION)) {

            for (int i = 0; i < sipHeaderVector.size(); i++) {
                Header sipheader =
                        (Header) sipHeaderVector.elementAt(i);
                encoding.append(sipheader.encode());
            }

            return encoding.toString();
        } else {
            // These can be concatenated together in an comma separated
            // list.
            return headerName + Separators.COLON + Separators.SP +
                    this.encodeBody() + Separators.NEWLINE;
        }
    
protected java.lang.StringencodeBody()
Encodes body as a string.

return
encoded string of body contents

        StringBuffer sbuf = new StringBuffer();
        for (int i = 0; i < sipHeaderVector.size(); i++) {
            Header sipHeader =
                    (Header) sipHeaderVector.elementAt(i);
            sbuf.append(sipHeader.encodeBody());
            if (i + 1 < sipHeaderVector.size())
                sbuf.append(",");
        }
        return sbuf.toString();
    
public java.lang.Objectfirst()
Gets the first element of the vector.

return
the first element of the vector.

        if (sipHeaderVector.size() == 0)
            return null;
        return this.sipHeaderVector.elementAt(0);
    
public java.util.EnumerationgetElements()
Returns an enumeration of the imbedded vector.

return
an Enumeration of the elements of the vector.

        return this.sipHeaderVector.elements();
    
public HeadergetFirst()
Gets the first element of the vector.

return
the first element of the vector.

        if (sipHeaderVector.size() == 0)
            return null;
        return (Header) this.sipHeaderVector.elementAt(0);
    
public java.util.VectorgetHeaders()
Gets the header list.

return
the header list

        return this.sipHeaderVector;
    
public java.util.VectorgetHeadersAsEncodedStrings()
Returns a vector of encoded strings (one for each sipheader).

return
Vector containing encoded strings in this header list. an empty vector is returned if this header list contains no sip headers.

        Vector retval = new Vector();

        for (int i = 0; i < size(); i++) {
            Header sipheader = (Header) elementAt(i);
            retval.addElement(sipheader.encode());
        }
        return retval;

    
public NameValueListgetParameters()
Gets the parameters of the header list.

return
always returns null

        return null;
    
public java.lang.ObjectgetValue()
Gets the value of the header list.

return
a vector of the header list contents

        Vector retval = new Vector();
        for (int i = 0; i < size(); i++) {
            Header sipheader = (Header) elementAt(i);
            retval.addElement(sipheader);
        }
        return retval;
    
public booleanisEmpty()
Returns true if this is empty.

return
true if no headers in the list

        return sipHeaderVector.isEmpty();
    
public java.lang.Objectlast()
Gets the last element of the vector.

return
the last element of the vector.

        if (sipHeaderVector.size() == 0)
            return null;
        else return (Header) this.sipHeaderVector.elementAt
                (sipHeaderVector.size() - 1);

    
public voidremoveElement(java.lang.Object element)
Removes the specified element.

param
element entry to delete

        sipHeaderVector.removeElement(element);
    
public voidremoveFirst()
Removes the first element of the list.

        if (sipHeaderVector.size() == 0)
            return;
        else
            sipHeaderVector.removeElementAt(0);

    
public voidremoveLast()
Removes the lastentry in the header list.

        if (sipHeaderVector.size() != 0) {
            sipHeaderVector.removeElementAt(sipHeaderVector.size() -1);
        }
    
public intsize()
Returns the list size.

return
size

        return sipHeaderVector.size();