Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
  * Conditions Of Use
  *
  * This software was developed by employees of the National Institute of
  * Standards and Technology (NIST), an agency of the Federal Government.
  * Pursuant to title 15 Untied States Code Section 105, works of NIST
  * employees are not subject to copyright protection in the United States
  * and are considered to be in the public domain.  As a result, a formal
  * license is not needed to use the software.
 *
 * This software is provided by NIST as a service and is expressly
 * provided "AS IS."  NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED
 * OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT
 * AND DATA ACCURACY.  NIST does not warrant or make any representations
 * regarding the use of the software or the results thereof, including but
 * not limited to the correctness, accuracy, reliability or usefulness of
 * the software.
 *
 * Permission to use this software is contingent upon your acceptance
 * of the terms of this agreement
 *
 * .
 *
 */
/
 
 /* Product of NIST Advanced Networking Technologies Division  */
/
 
 
 package gov.nist.javax.sip.header;
 
 
Parameters header. Suitable for extension by headers that have parameters.

Author(s):
M. Ranganathan
Version:
1.2 $Revision: 1.15 $ $Date: 2010/01/12 00:05:27 $
 
 public abstract class ParametersHeader
     extends SIPHeader
     implements javax.sip.header.ParametersSerializable {
     protected NameValueList parameters;
     
     protected DuplicateNameValueList duplicates;
     
     protected ParametersHeader() {
         this. = new NameValueList();
         this. = new DuplicateNameValueList();
     }
 
     protected ParametersHeader(String hdrName) {
         super(hdrName);
         this. = new NameValueList();
         this. = new DuplicateNameValueList();
     }
 
     protected ParametersHeader(String hdrNameboolean sync) {
         super(hdrName);
         this. = new NameValueList(sync);
         this. = new DuplicateNameValueList();
     }

    
Returns the value of the named parameter, or null if it is not set. A zero-length String indicates flag parameter.

Parameters:
name name of parameter to retrieve
Returns:
the value of specified parameter
 
 
     public String getParameter(String name) {
         return this..getParameter(name);
 
     }

    
Return the parameter as an object (dont convert to string).

Parameters:
name is the name of the parameter to get.
Returns:
the object associated with the name.
 
     public Object getParameterValue(String name) {
         return this..getValue(name);
     }

    
Returns an Iterator over the names (Strings) of all parameters present in this ParametersHeader.

Returns:
an Iterator over all the parameter names
    public Iterator<StringgetParameterNames() {
        return .getNames();
    }

    
Return true if you have a parameter and false otherwise.

Returns:
true if the parameters list is non-empty.
    public boolean hasParameters() {
        return  != null && !.isEmpty();
    }

    
Removes the specified parameter from Parameters of this ParametersHeader. This method returns silently if the parameter is not part of the ParametersHeader.

Parameters:
name - a String specifying the parameter name
    public void removeParameter(String name) {
        this..delete(name);
    }

    
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.

Parameters:
name - a String specifying the parameter name
value - a String specifying the parameter value
Throws:
java.text.ParseException which signals that an error has been reached unexpectedly while parsing the parameter name or value.
    public void setParameter(String nameString valuethrows ParseException {
        NameValue nv = .getNameValue(name);
        if (nv != null) {
            nv.setValueAsObject(value);
        } else {
            nv = new NameValue(namevalue);
            this..set(nv);
        }
    }
    
    
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.

Parameters:
name - a String specifying the parameter name
value - a String specifying the parameter value
Throws:
java.text.ParseException which signals that an error has been reached unexpectedly while parsing the parameter name or value.
    public void setQuotedParameter(String nameString value)
        throws ParseException {
        NameValue nv = .getNameValue(name);
        if (nv != null) {
            nv.setValueAsObject(value);
            nv.setQuotedValue();
        } else {
            nv = new NameValue(namevalue);
            nv.setQuotedValue();
            this..set(nv);
        }
    }

    
Sets the value of the specified parameter. If the parameter already had a value it will be overwritten.

Parameters:
name - a String specifying the parameter name
value - an int specifying the parameter value
Throws:
java.text.ParseException which signals that an error has been reached unexpectedly while parsing the parameter name or value.
    protected void setParameter(String nameint value) {
        Integer val = Integer.valueOf(value);
        this..set(name,val);
    }

    
Sets the value of the specified parameter. If the parameter already had a value it will be overwritten.

Parameters:
name - a String specifying the parameter name
value - a boolean specifying the parameter value
Throws:
java.text.ParseException which signals that an error has been reached unexpectedly while parsing the parameter name or value.
    protected void setParameter(String nameboolean value) {
        Boolean val = Boolean.valueOf(value);
        this..set(name,val);
    }

    
Sets the value of the specified parameter. If the parameter already had a value it will be overwritten.

Parameters:
name - a String specifying the parameter name
value - a boolean specifying the parameter value
Throws:
java.text.ParseException which signals that an error has been reached unexpectedly while parsing the parameter name or value.
    protected void setParameter(String namefloat value) {
        Float val = Float.valueOf(value);
        NameValue nv = .getNameValue(name);
        if (nv != null) {
            nv.setValueAsObject(val);
        } else {
            nv = new NameValue(nameval);
            this..set(nv);
        }
    }

    
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.

Parameters:
name - a String specifying the parameter name
value - a String specifying the parameter value
Throws:
java.text.ParseException which signals that an error has been reached unexpectedly while parsing the parameter name or value.
    protected void setParameter(String nameObject value) {
        this..set(name,value);
    }

    
Return true if has a parameter.

Parameters:
parameterName is the name of the parameter.
Returns:
true if the parameter exists and false if not.
    public boolean hasParameter(String parameterName) {
        return this..hasNameValue(parameterName);
    }

    
Remove all parameters.
    public void removeParameters() {
        this. = new NameValueList();
    }

    
get the parameter list.

Returns:
parameter list
    public NameValueList getParameters() {
        return ;
    }

    
Set the parameter given a name and value.

Parameters:
nameValue - the name value of the parameter to set.
    public void setParameter(NameValue nameValue) {
        this..set(nameValue);
    }

    
Set the parameter list.

Parameters:
parameters The name value list to set as the parameter list.
    public void setParameters(NameValueList parameters) {
        this. = parameters;
    }

    
Get the parameter as an integer value.

Parameters:
parameterName -- the parameter name to fetch.
Returns:
-1 if the parameter is not defined in the header.
    protected int getParameterAsInt(String parameterName) {
        if (this.getParameterValue(parameterName) != null) {
            try {
                if (this.getParameterValue(parameterNameinstanceof String) {
                    return Integer.parseInt(this.getParameter(parameterName));
                } else {
                    return ((IntegergetParameterValue(parameterName))
                        .intValue();
                }
            } catch (NumberFormatException ex) {
                return -1;
            }
        } else
            return -1;
    }

    
Get the parameter as an integer when it is entered as a hex.

Parameters:
parameterName -- The parameter name to fetch.
Returns:
-1 if the parameter is not defined in the header.
    protected int getParameterAsHexInt(String parameterName) {
        if (this.getParameterValue(parameterName) != null) {
            try {
                if (this.getParameterValue(parameterNameinstanceof String) {
                    return Integer.parseInt(
                        this.getParameter(parameterName),
                        16);
                } else {
                    return ((IntegergetParameterValue(parameterName))
                        .intValue();
                }
            } catch (NumberFormatException ex) {
                return -1;
            }
        } else
            return -1;
    }

    
Get the parameter as a float value.

Parameters:
parameterName -- the parameter name to fetch
Returns:
-1 if the parameter is not defined or the parameter as a float.
    protected float getParameterAsFloat(String parameterName) {
        if (this.getParameterValue(parameterName) != null) {
            try {
                if (this.getParameterValue(parameterNameinstanceof String) {
                    return Float.parseFloat(this.getParameter(parameterName));
                } else {
                    return ((FloatgetParameterValue(parameterName))
                        .floatValue();
                }
            } catch (NumberFormatException ex) {
                return -1;
            }
        } else
            return -1;
    }

    
Get the parameter as a long value.

Parameters:
parameterName -- the parameter name to fetch.
Returns:
-1 if the parameter is not defined or the parameter as a long.
    protected long getParameterAsLong(String parameterName) {
        if (this.getParameterValue(parameterName) != null) {
            try {
                if (this.getParameterValue(parameterNameinstanceof String) {
                    return Long.parseLong(this.getParameter(parameterName));
                } else {
                    return ((LonggetParameterValue(parameterName))
                        .longValue();
                }
            } catch (NumberFormatException ex) {
                return -1;
            }
        } else
            return -1;
    }

    
Get the parameter value as a URI.

Parameters:
parameterName -- the parameter name
Returns:
value of the parameter as a URI or null if the parameter not present.
    protected GenericURI getParameterAsURI(String parameterName) {
        Object val = getParameterValue(parameterName);
        if (val instanceof GenericURI)
            return (GenericURIval;
        else {
            try {
                return new GenericURI((Stringval);
            } catch (ParseException ex) {
                //catch ( URISyntaxException ex) {
                return null;
            }
        }
    }

    
Get the parameter value as a boolean.

Parameters:
parameterName -- the parameter name
Returns:
boolean value of the parameter.
    protected boolean getParameterAsBoolean(String parameterName) {
        Object val = getParameterValue(parameterName);
        if (val == null) {
            return false;
        } else if (val instanceof Boolean) {
            return ((Booleanval).booleanValue();
        } else if (val instanceof String) {
            return Boolean.valueOf((Stringval).booleanValue();
        } else
            return false;
    }

    
This is for the benifit of the TCK.

Returns:
the name value pair for the given parameter name.
    public NameValue getNameValue(String parameterName) {
        return .getNameValue(parameterName);
    }
 
    public Object clone() {
        ParametersHeader retval = (ParametersHeadersuper.clone();
        if (this. != null)
            retval.parameters = (NameValueListthis..clone();
        return retval;
    }
    //-------------------------
    
Introduced specifically for the P-Charging-Function-Addresses Header and all other headers that may have multiple header parameters of the same name, but with multiple possible values. Example: P-Charging-Function-Addresses: ccf=[5555::b99:c88:d77:e66]; ccf=[5555::a55:b44:c33:d22]; ecf=[5555::1ff:2ee:3dd:4cc]; ecf=[5555::6aa:7bb:8cc:9dd]

Parameters:
name of the parameter
value of the parameter
    public void setMultiParameter(String nameString value)
    {
    	NameValue nv = new NameValue();
    	nv.setName(name);
    	nv.setValue(value);
    	.set(nv);
    }
    
    
Set the parameter given a name and value.

Parameters:
nameValue - the name value of the parameter to set.
   public void setMultiParameter(NameValue nameValue) {
       this..set(nameValue);
   }
    
    
Returns the parameter name

Parameters:
name
Returns:
    public String getMultiParameter(String name) {
        return this..getParameter(name);
    }
    
        return ;
    }
    
    
    
Return the parameter as an object (dont convert to string).

Parameters:
name is the name of the parameter to get.
Returns:
the object associated with the name.
    public Object getMultiParameterValue(String name) {
        return this..getValue(name);
    }

    
Returns an Iterator over the names (Strings) of all parameters present in this ParametersHeader.

Returns:
an Iterator over all the parameter names
        return .getNames();
    }

    
Return true if you have a parameter and false otherwise.

Returns:
true if the parameters list is non-empty.
    public boolean hasMultiParameters() {
        return  != null && !.isEmpty();
    }

    
Removes the specified parameter from Parameters of this ParametersHeader. This method returns silently if the parameter is not part of the ParametersHeader.

Parameters:
name - a String specifying the parameter name
    public void removeMultiParameter(String name) {
        this..delete(name);
    }
    
    
Return true if has a parameter.

Parameters:
parameterName is the name of the parameter.
Returns:
true if the parameter exists and false if not.
    public boolean hasMultiParameter(String parameterName) {
        return this..hasNameValue(parameterName);
    }

    
Remove all parameters.
    public void removeMultiParameters() {
        this. = new DuplicateNameValueList();
    }
    //-------------------------------
    
    @SuppressWarnings("unchecked")
    protected final boolean equalParametersParameters other ) {
        if (this==otherreturn true;
        for ( Iterator i = this.getParameterNames(); i.hasNext();) {
            String pname = (Stringi.next();
            String p1 = this.getParameterpname );
            String p2 = other.getParameterpname );
            // getting them based on this.getParameterNames. Note that p1 may be null
            // if this is a name-only parameter like rport or lr.
            if (p1 == null ^ p2 == nullreturn false;
            else if (p1 != null && !p1.equalsIgnoreCase(p2) ) return false;
        }
        // Also compare other's parameters; some duplicate testing here...
        for ( Iterator i = other.getParameterNames(); i.hasNext();) {
            String pname = (Stringi.next();
            String p1 = other.getParameterpname );
            String p2 = this.getParameterpname );
                // assert( p1 != null );
            // if ( p1 == null ) throw new RuntimeException("Assertion check failed!");
            // if (p2==null) return false;
            // getting them based on this.getParameterNames. Note that p1 may be null
            // if this is a name-only parameter like rport or lr.
            if (p1 == null ^ p2 == nullreturn false;
            else if (p1 != null && !p1.equalsIgnoreCase(p2) ) return false;
        }
        return true;
    }
    
    
    // ----------- Abstract methods --------------
    protected abstract String encodeBody();
New to GrepCode? Check out our FAQ X