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

ParametersHeader

public abstract class ParametersHeader extends Header
Parameters header. Suitable for extension by headers that have parameters. This code is in the public domain.
version
JAIN-SIP-1.1

Fields Summary
protected NameValueList
parameters
Contents of the parameter list.
Constructors Summary
protected ParametersHeader()
Default constructor.

        this.parameters = new NameValueList();
    
protected ParametersHeader(String hdrName)
Constructor with initial header name.

param
hdrName an initial header name

        super(hdrName);
        this.parameters = new NameValueList();
    
Methods Summary
protected abstract java.lang.StringencodeBody()
Encodes the contents as a string.

return
encoded string of object contents.

protected java.lang.StringencodeWithSep()
Encodes the parameters as a string.

return
encoded string of object contents.

        if (parameters == null) {
            return "";
        } else {
            return parameters.encodeWithSep();
        }
    
public NameValuegetNameValue(java.lang.String parameterName)
This is for the benifit of the TCK.

param
parameterName the parameter name
return
the name value pair for the given parameter name.

        return parameters.getNameValue(parameterName);
    
public java.lang.StringgetParameter(java.lang.String name)
Returns the value of the named parameter, or null if it is not set. A zero-length String indicates flag parameter.

param
name name of parameter to retrieve
return
the value of specified parameter

        return this.parameters.getParameter(name);
        
    
protected booleangetParameterAsBoolean(java.lang.String parameterName)
Gets the parameter value as a boolean.

param
parameterName the parameter name
return
boolean value of the parameter.

        Object val = getParameterValue(parameterName);
        if (val == null) {
            return false;
        } else if (val instanceof Boolean) {
            return ((Boolean) val).booleanValue();
        } else if (val instanceof String) {
            return equalsIgnoreCase((String)val, "true");
        } else return false;
    
protected intgetParameterAsHexInt(java.lang.String parameterName)
Gets the parameter as an integer when it is entered as a hex.

param
parameterName -- The parameter name to fetch.
return
-1 if the parameter is not defined in the header.

        if (this.getParameterValue(parameterName) != null) {
            try {
                if (this.getParameterValue(parameterName)
                instanceof String) {
                    return Integer.parseInt
                            (this.getParameter(parameterName), 16);
                } else {
                    return
			((Integer)getParameterValue(parameterName)).intValue();
                }
            } catch (NumberFormatException ex) {
                return -1;
            }
        } else return -1;
    
protected intgetParameterAsInt(java.lang.String parameterName)
Gets the parameter as an integer value.

param
parameterName -- the parameter name to fetch.
return
-1 if the parameter is not defined in the header.

        if (this.getParameterValue(parameterName) != null) {
            try {
                if (this.getParameterValue(parameterName)
                instanceof String) {
                    return Integer.parseInt
                            (this.getParameter(parameterName));
                } else {
                    return
			((Integer)getParameterValue(parameterName)).intValue();
                }
            } catch (NumberFormatException ex) {
                return -1;
            }
        } else return -1;
    
protected longgetParameterAsLong(java.lang.String parameterName)
Gets the parameter as a long value.

param
parameterName -- the parameter name to fetch.
return
-1 if the parameter is not defined or the parameter as a long.

        if (this.getParameterValue(parameterName) != null) {
            try {
                if (this.getParameterValue(parameterName)
                instanceof String) {
                    return Long.parseLong
                            (this.getParameter(parameterName));
                } else {
                    return
			((Long)getParameterValue(parameterName)).longValue();
                }
            } catch (NumberFormatException ex) {
                return -1;
            }
        } else return -1;
    
protected URIgetParameterAsURI(java.lang.String parameterName)
Gets the parameter value as a URI.

param
parameterName -- the parameter name
return
value of the parameter as a URI or null if the parameter not present.

        Object val = getParameterValue(parameterName);
        if (val instanceof URI)
            return (URI) val;
        else {
            try {
                return new URI((String)val);
            } catch (ParseException ex) {
                // catch (URISyntaxException ex) {
                return null;
            }
        }
    
public java.util.VectorgetParameterNames()
Returns an Vector over the names (Strings) of all parameters present in this ParametersHeader.

return
an Iterator over all the parameter names

        return parameters.getNames();
    
public java.lang.ObjectgetParameterValue(java.lang.String name)
Returns the parameter as an object (dont convert to string).

param
name is the name of the parameter to get.
return
the object associated with the name.

        return this.parameters.getValue(name);
    
public NameValueListgetParameters()
get the parameter list.

return
parameter list

        return parameters;
    
public booleanhasParameter(java.lang.String parameterName)
Returns true if has a parameter.

param
parameterName is the name of the parameter.
return
true if the parameter exists and false if not.

        return this.parameters.hasNameValue(parameterName);
    
public booleanhasParameters()
Returns true if you have a parameter and false otherwise.

return
true if the parameters list is non-empty.

        return parameters != null && ! parameters.isEmpty();
    
public voidremoveParameter(java.lang.String name)
Removes the specified parameter from Parameters of this ParametersHeader. This method returns silently if the parameter is not part of the ParametersHeader.

param
name - a String specifying the parameter name

        this.parameters.delete(name);
    
public voidremoveParameters()
Removes all parameters.

        this.parameters = new NameValueList();
    
protected voidsetParameter(java.lang.String name, int value)
Sets the value of the specified parameter. If the parameter already had a value it will be overwritten.

param
name - a String specifying the parameter name
param
value - an int specifying the parameter value
throws
ParseException which signals that an error has been reached unexpectedly while parsing the parameter name or value.

        Integer val = new Integer(value);
        NameValue nv = parameters.getNameValue(name);
        if (nv != null) {
            nv.setValue(val);
        } else {
            nv = new NameValue(name, val);
            this.parameters.set(nv);
        }
    
protected voidsetParameter(java.lang.String name, boolean value)
Sets the value of the specified parameter. If the parameter already had a value it will be overwritten.

param
name - a String specifying the parameter name
param
value - a boolean specifying the parameter value
throws
ParseException which signals that an error has been reached unexpectedly while parsing the parameter name or value.

        Boolean val = new Boolean(value);
        NameValue nv = parameters.getNameValue(name);
        if (nv != null) {
            nv.setValue(val);
        } else {
            nv = new NameValue(name, val);
            this.parameters.set(nv);
        }
    
protected voidsetParameter(java.lang.String name, java.lang.Object value)
Sets the value of the specified parameter. If the parameter already had a value it will be overwritten. A zero-length String indicates flag parameter.

param
name - a String specifying the parameter name
param
value - a String specifying the parameter value
throws
ParseException which signals that an error has been reached unexpectedly while parsing the parameter name or value.

        NameValue nv = parameters.getNameValue(name);
        if (nv != null) {
            nv.setValue(value);
        } else {
            nv = new NameValue(name, value);
            this.parameters.set(nv);
        }
    
public voidsetParameter(NameValue nameValue)
Sets the parameter given a name and value.

param
nameValue - the name value of the parameter to set.

        this.parameters.set(nameValue);
    
public voidsetParameter(java.lang.String name, java.lang.String value)
Sets the value of the specified parameter. If the parameter already had a value it will be overwritten. A zero-length String indicates flag parameter.

param
name - a String specifying the parameter name
param
value - a String specifying the parameter value
throws
ParseException which signals that an error has been reached unexpectedly while parsing the parameter name or value.

        NameValue nv = parameters.getNameValue(name);
        
        if (nv != null) {
            nv.setValue(value);
        } else {
            nv = new NameValue(name, value);
        }
        
        this.parameters.set(nv);
    
public voidsetParameters(NameValueList parameters)
Sets the parameter list.

param
parameters the name value list to set as the parameter list.

        this.parameters = parameters;
    
public voidsetQuotedParameter(java.lang.String name, java.lang.String value)
Sets the value of the specified parameter. If the parameter already had a value it will be overwritten. A zero-length String indicates flag parameter.

param
name - a String specifying the parameter name
param
value - a String specifying the parameter value
throws
ParseException which signals that an error has been reached unexpectedly while parsing the parameter name or value.

        NameValue nv = parameters.getNameValue(name);
        if (nv != null) {
            nv.setValue(value);
            nv.setQuotedValue();
        } else {
            nv = new NameValue(name, value);
            nv.setQuotedValue();
            this.parameters.set(nv);
        }