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

HeaderFactory

public class HeaderFactory extends Object
Implementation of the JAIN SIP HeaderFactory
version
JAIN-SIP-1.1 This code is in the public domain.

Fields Summary
Constructors Summary
public HeaderFactory()
Default constructor.


    
Methods Summary
public AuthorizationHeadercreateAuthorizationHeader(java.lang.String scheme)
Creates a new AuthorizationHeader based on the newly supplied scheme value.

param
scheme - the new string value of the scheme.
throws
ParseException which signals that an error has been reached unexpectedly while parsing the scheme value.
return
the newly created AuthorizationHeader object.

        if (scheme == null)
            throw new NullPointerException("null arg scheme ");
        AuthorizationHeader auth = new AuthorizationHeader();
        auth.setScheme(scheme);

        return auth;
    
public CSeqHeadercreateCSeqHeader(int sequenceNumber, java.lang.String method)
Creates a new CSeqHeader based on the newly supplied sequence number and method values.

param
sequenceNumber - the new integer value of the sequence number.
param
method - the new string value of the method.
throws
IllegalArgumentException if supplied sequence number is less than zero.
throws
ParseException which signals that an error has been reached unexpectedly while parsing the method value.
return
the newly created CSeqHeader object.

        if (sequenceNumber < 0)
            throw new IllegalArgumentException
                    ("bad arg " + sequenceNumber);
        if (method == null)
            throw new NullPointerException("null arg method");
        CSeqHeader cseq = new CSeqHeader();
        cseq.setMethod(method);
        cseq.setSequenceNumber(sequenceNumber);

        return cseq;
    
public CallIdHeadercreateCallId(java.lang.String callId)
Creates a new CallIdHeader based on the newly supplied callId value.

param
callId - the new string value of the call-id.
throws
ParseException which signals that an error has been reached unexpectedly while parsing the callId value.
return
the newly created CallIdHeader object.

        if (callId == null)
            throw new NullPointerException("null arg callId");
        CallIdHeader c = new CallIdHeader();
        c.setCallId(callId);
        return c;
    
public ContactHeadercreateContactHeader(Address address)
Creates a new ContactHeader based on the newly supplied address value.

param
address - the new Address value of the address.
return
the newly created ContactHeader object.

        if (address == null)
            throw new NullPointerException("null arg address");
        ContactHeader contact = new ContactHeader();
        contact.setAddress(address);

        return contact;
    
public ContactHeadercreateContactHeader()
Creates a new wildcard ContactHeader. This is used in Register requests to indicate to the server that it should remove all locations the at which the user is currently available. This implies that the following conditions are met:
  • ContactHeader.getAddress.getAddress.getUserInfo() == *;
  • ContactHeader.getAddress.getAddress.isWildCard() == true;
  • ContactHeader.getExpiresHeader() == 0;

return
the newly created wildcard ContactHeader.

        ContactHeader contact = new ContactHeader();
        contact.setWildCardFlag(true);
        contact.setExpires(0);

        return contact;
    
public ContentLengthHeadercreateContentLengthHeader(int contentLength)
Creates a new CSeqHeader based on the newly supplied contentLength value.

param
contentLength - the new integer value of the contentLength.
throws
IllegalArgumentException if supplied contentLength is less than zero.
return
the newly created ContentLengthHeader object.

        if (contentLength < 0)
            throw new IllegalArgumentException("bad contentLength");
        ContentLengthHeader c = new ContentLengthHeader();
        c.setContentLength(contentLength);

        return c;
    
public ContentTypeHeadercreateContentTypeHeader(java.lang.String contentType, java.lang.String contentSubType)
Creates a new ContentTypeHeader based on the newly supplied contentType and contentSubType values.

param
contentType the new string content type value.
param
contentSubType the new string content sub-type value.
throws
ParseException which signals that an error has been reached unexpectedly while parsing the content type or content subtype value.
return
the newly created ContentTypeHeader object.

        if (contentType == null || contentSubType == null)
            throw new NullPointerException("null contentType or subType");
        ContentTypeHeader c = new ContentTypeHeader();
        c.setContentType(contentType);
        c.setContentSubType(contentSubType);
        return c;
    
public DateHeadercreateDateHeader(java.util.Calendar date)
Creates a new DateHeader based on the newly supplied date value.

param
date - the new Calender value of the date.
return
the newly created DateHeader object.

        DateHeader d = new DateHeader();
        if (date == null)
            throw new NullPointerException("null date");
        d.setDate(date);

        return d;
    
public EventHeadercreateEventHeader(java.lang.String eventType)
Creates a new EventHeader based on the newly supplied eventType value.

param
eventType - the new string value of the eventType.
throws
ParseException which signals that an error has been reached unexpectedly while parsing the eventType value.
return
the newly created EventHeader object.
since
v1.1

        if (eventType == null)
            throw new NullPointerException("null eventType");
        EventHeader event = new EventHeader();
        event.setEventType(eventType);

        return event;
    
public ExpiresHeadercreateExpiresHeader(int expires)
Creates a new ExpiresHeader based on the newly supplied expires value.

param
expires - the new integer value of the expires.
throws
IllegalArgumentException if supplied expires is less than zero.
return
the newly created ExpiresHeader object.

        if (expires < 0)
            throw new IllegalArgumentException("bad value " + expires);
        ExpiresHeader e = new ExpiresHeader();
        e.setExpires(expires);

        return e;
    
public ExtensionHeadercreateExtensionHeader(java.lang.String name, java.lang.String value)
Creates a new ExtensionHeader based on the newly supplied name and value values.

param
name - the new string name of the ExtensionHeader value.
param
value - the new string value of the ExtensionHeader.
throws
ParseException which signals that an error has been reached unexpectedly while parsing the name or value values.
return
the newly created ExtensionHeader object.

        if (name == null)
            throw new NullPointerException("bad name");

        ExtensionHeader ext = new ExtensionHeader();
        ext.setHeaderName(name);
        ext.setValue(value);

        return ext;
    
public FromHeadercreateFromHeader(Address address, java.lang.String tag)
Creates a new FromHeader based on the newly supplied address and tag values.

param
address - the new Address object of the address.
param
tag - the new string value of the tag.
throws
ParseException which signals that an error has been reached unexpectedly while parsing the tag value.
return
the newly created FromHeader object.

        if (address == null)
            throw new NullPointerException("null address arg");
        FromHeader from = new FromHeader();
        from.setAddress(address);
        if (tag != null) from.setTag(tag);

        return from;
    
public HeadercreateHeader(java.lang.String headerName, java.lang.String headerValue)
Create and parse a header.

param
headerName -- header name for the header to parse.
param
headerValue -- header value for the header to parse.
throws
ParseException
return
the parsed sip header


        if (headerName == null)
            throw new NullPointerException("header name is null");

        String expandedHeaderName = NameMap.expandHeaderName(headerName);

        if (Header.isParameterLess(expandedHeaderName)) {
            // The header can't have any parameters
            // System.out.println("> '" + headerName + "' parameter-less");

            ParameterLessHeader retval = new ParameterLessHeader();
            retval.setHeaderName(headerName);
            retval.setValue(headerValue);

            return retval;
        }

        String hdrText = new StringBuffer().append(headerName)
                    .append(":").append(headerValue).toString();
        Class clazz = NameMap.getClassFromName(expandedHeaderName);

        if (clazz == null) {
            // ExtensionHeader - can have some parameters
            clazz = ExtensionHeader.clazz;
        }

        Exception ex = null;
        try {
            if (headerValue == null) {
                Header retval = (Header) clazz.newInstance();
                retval.setHeaderName(headerName);
            }
        } catch (InstantiationException ie) {
            ex = ie;
        } catch (IllegalAccessException iae) {
            ex = iae;
        }
        if (ex != null) {
            // print system message and exit
            InternalErrorHandler.handleException(ex);
            return null;
        }

        StringMsgParser smp = new StringMsgParser();
        Header sipHeader = smp.parseHeader(hdrText);

        if (sipHeader instanceof HeaderList) {
            if (((HeaderList) sipHeader).size() > 1)
                throw new ParseException("Only signleton allowed !", 0);
            else {
                // We have to preserve the original header's name
                // (it might be given in a copact form)
                Enumeration li = ((HeaderList) sipHeader).getElements();

                while (li.hasMoreElements()) {
                    Header header = (Header) li.nextElement();
                    header.setHeaderName(headerName);
                }

                return (Header) ((HeaderList) sipHeader).first();
            }
        } else {
            // We have to preserve the original header's name
            // (it might be given in a copact form)
            sipHeader.setHeaderName(headerName);
            return sipHeader;
        }
    
public java.util.VectorcreateHeaders(java.lang.String headers)
Create and return a list of headers.

param
headers -- list of headers.
throws
ParseException -- if a parse exception occurs or a List of that type of header is not alowed.
return
a List containing the headers.

        if (headers == null)
            throw new NullPointerException("null arg!");
        StringMsgParser smp = new StringMsgParser();
        Header shdr = smp.parseHeader(headers);
        if (shdr instanceof HeaderList)
            return ((HeaderList) shdr).getHeaders();
        else throw new ParseException
                ("List of headers of this type is not allowed in a message", 0);
    
public MaxForwardsHeadercreateMaxForwardsHeader(int maxForwards)
Creates a new MaxForwardsHeader based on the newly supplied maxForwards value.

param
maxForwards the new integer value of the maxForwards.
throws
IllegalArgumentException if supplied maxForwards is less than zero or greater than 255.
return
the newly created MaxForwardsHeader object.

        if (maxForwards < 0 || maxForwards > 255)
            throw new IllegalArgumentException
                    ("bad maxForwards arg " + maxForwards);
        MaxForwardsHeader m = new MaxForwardsHeader();
        m.setMaxForwards(maxForwards);

        return m;
    
public ProxyAuthenticateHeadercreateProxyAuthenticateHeader(java.lang.String scheme)
Creates a new ProxyAuthenticateHeader based on the newly supplied scheme value.

param
scheme - the new string value of the scheme.
throws
ParseException which signals that an error has been reached unexpectedly while parsing the scheme value.
return
the newly created ProxyAuthenticateHeader object.

        if (scheme == null)
            throw new NullPointerException("bad scheme arg");
        ProxyAuthenticateHeader p = new ProxyAuthenticateHeader();
        p.setScheme(scheme);

        return p;
    
public ProxyAuthorizationHeadercreateProxyAuthorizationHeader(java.lang.String scheme)
Creates a new ProxyAuthorizationHeader based on the newly supplied scheme value.

param
scheme - the new string value of the scheme.
throws
ParseException which signals that an error has been reached unexpectedly while parsing the scheme value.
return
the newly created ProxyAuthorizationHeader object.

        if (scheme == null)
            throw new NullPointerException("bad scheme arg");
        ProxyAuthorizationHeader p = new ProxyAuthorizationHeader();
        p.setScheme(scheme);

        return p;
    
public RecordRouteHeadercreateRecordRouteHeader(Address address)
Creates a new RecordRouteHeader based on the newly supplied address value.

param
address - the new Address object of the address.
return
the newly created RecordRouteHeader object.

        RecordRouteHeader recordRouteHeader = new RecordRouteHeader();
        recordRouteHeader.setAddress(address);

        return recordRouteHeader;
    
public RouteHeadercreateRouteHeader(Address address)
Creates a new RouteHeader based on the newly supplied address value.

param
address - the new Address object of the address.
return
the newly created RouteHeader object.

        if (address == null)
            throw new NullPointerException
                    ("null address arg");
        RouteHeader route = new RouteHeader();
        route.setAddress(address);

        return route;
    
public ToHeadercreateToHeader(Address address, java.lang.String tag)
Creates a new ToHeader based on the newly supplied address and tag values.

param
address - the new Address object of the address.
param
tag - the new string value of the tag.
throws
ParseException which signals that an error has been reached unexpectedly while parsing the tag value.
return
the newly created ToHeader object.

        if (address == null)
            throw new NullPointerException("null address");
        ToHeader to = new ToHeader();
        to.setAddress(address);
        if (tag != null) to.setTag(tag);

        return to;
    
public ViaHeadercreateViaHeader(java.lang.String host, int port, java.lang.String transport, java.lang.String branch)
Creates a new ViaHeader based on the newly supplied uri and branch values.

param
host the new host value from the uri field
param
port the new port value from the uri field
param
transport the new transport value from the uri field
param
branch - the new string value of the branch.
throws
ParseException which signals that an error has been reached unexpectedly while parsing the branch value.
return
the newly created ViaHeader object.

        // This should be changed.
        if (host == null || transport == null)
            throw new NullPointerException("null arg");
        ViaHeader via = new ViaHeader();
        if (branch != null) via.setBranch(branch);
        via.setHost(host);
        via.setPort(port);
        via.setTransport(transport);

        return via;
    
public WWWAuthenticateHeadercreateWWWAuthenticateHeader(java.lang.String scheme)
Creates a new WWWAuthenticateHeader based on the newly supplied scheme value.

param
scheme - the new string value of the scheme.
throws
ParseException which signals that an error has been reached unexpectedly while parsing the scheme values.
return
the newly created WWWAuthenticateHeader object.

        if (scheme == null)
            throw new NullPointerException("null scheme");
        WWWAuthenticateHeader www = new WWWAuthenticateHeader();
        www.setScheme(scheme);

        return www;