NIST SIP Parser and Stack (v1.2) API

gov.nist.core
Class GenericObject

java.lang.Object
  |
  +--gov.nist.core.GenericObject
Direct Known Subclasses:
Host, HostPort, NameValue, NetObject, SIPObject

public abstract class GenericObject
extends Object

The base class from which all the other classes in the sipheader, sdpfields and sipmessage packages are extended. Provides a few utility funcitons such as indentation and pretty printing that all other classes benifit from.

Version:
JAIN-SIP-1.1
Author:
M. Ranganathan
This code is in the public domain.

Method Summary
 Object clone()
          Make a clone of this object.
 String debugDump()
          Generic print formatting function: Does depth-first descent of the structure and recursively prints all non-private objects pointed to by this object.
 String debugDump(int indent)
          Formatter with a given starting indentation.
abstract  String encode()
          Get the string encoded version of this object
 boolean equals(Object that)
          An introspection based equality predicate for GenericObjects.
static Class getClassFromName(String className)
           
 Match getMatcher()
          Return the match expression.
static boolean isMySubclass(Class other)
           
 boolean match(Object other)
          An introspection based predicate matching using a template object.
 void merge(Object mergeObject)
          Recursively override the fields of this object with the fields of a new object.
 void replace(Match regexp, GenericObject replacement)
          Do a find and replace of objects based on regular expression matching of fields.
 void replace(Match regexp, GenericObjectList replacement)
          Do a recursive find and replace of objects pointed to by this object based on regular expression pattern matching.
 void replace(String objectText, GenericObject replacement, boolean matchSubstring)
          Do a recursive find and replace of objects pointed to by this object.
 void replace(String objectText, GenericObjectList replacement, boolean matchSubstring)
          Do a recursive find and replace of objects pointed to by this object.
 void setMatcher(Match matchExpression)
          Set the pattern matcher.
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

setMatcher

public void setMatcher(Match matchExpression)
Set the pattern matcher. To match on the field of a sip message, set the match expression in the match template and invoke the match function. This useful because SIP headers and parameters may appear in different orders and are not necessarily in canonical form. This makes it hard to write a pattern matcher that relies on regular expressions alone. Thus we rely on the following strategy i.e. To do pattern matching on an incoming message, first parse it, and then construct a match template, filling in the fields that you want to match. The rules for matching are: A null object matches wild card - that is a match template of null matches any parsed SIP object. To match with any subfield, set the match template on a template object of the same type and invoke the match interface. Regular expressions matching implements the gov.nist.sip.Match interface that can be done using the Jakarta regexp package for example. package included herein. This can be used to implement the Match interface See the APACHE website for documents


getMatcher

public Match getMatcher()
Return the match expression.

Returns:
the match expression that has previously been set.

getClassFromName

public static Class getClassFromName(String className)

isMySubclass

public static boolean isMySubclass(Class other)

clone

public Object clone()
Make a clone of this object.

Overrides:
clone in class Object

merge

public void merge(Object mergeObject)
Recursively override the fields of this object with the fields of a new object. This is useful when you want to genrate a template and override the fields of an incoming SIPMessage with another SIP message that you have already generated.

Parameters:
mergeObject - is the replacement object. The override obect must be of the same class as this object. Set any fields that you do not want to override as null in the mergeOject object.

equals

public boolean equals(Object that)
An introspection based equality predicate for GenericObjects.

Overrides:
equals in class Object
Returns:
true if the objects are euqal and false otherwise

match

public boolean match(Object other)
An introspection based predicate matching using a template object. Allows for partial match of two protocl Objects.

Parameters:
other - the match pattern to test against. The match object has to be of the same type (class). Primitive types and non-sip fields that are non null are matched for equality. Null in any field matches anything. Some book-keeping fields are ignored when making the comparison.

debugDump

public String debugDump()
Generic print formatting function: Does depth-first descent of the structure and recursively prints all non-private objects pointed to by this object. Warning - the following generic string routine will bomb (go into infinite loop) if there are any circularly linked structures so if you have these, they had better be private! We dont have to worry about such things for our structures (we never use circular linked structures).


debugDump

public String debugDump(int indent)
Formatter with a given starting indentation.


encode

public abstract String encode()
Get the string encoded version of this object

Since:
v1.0

replace

public void replace(String objectText,
                    GenericObject replacement,
                    boolean matchSubstring)
             throws IllegalArgumentException
Do a recursive find and replace of objects pointed to by this object.

Parameters:
objectText - is the canonical string representation of the object that we want to replace.
replacement - is the object that we want to replace it with.
matchSubstring - a boolean which tells if we should match a substring of the target object A replacement will occur if a portion of the structure is found with matching encoded text (a substring if matchSubstring is true) as objectText and with the same class as replacement.
IllegalArgumentException
Since:
v1.0

replace

public void replace(String objectText,
                    GenericObjectList replacement,
                    boolean matchSubstring)
             throws IllegalArgumentException
Do a recursive find and replace of objects pointed to by this object.

Parameters:
objectText - Canonical string representation of the portion we want to replace.
replacement - object we want to replace this portion with. A replacement will occur if a portion of the structure is found with a match of the encoded text with objectText and with the same class as replacement.
matchSubstring - is true if we want to match objectText as a substring of the encoded target text. (i.e. an object is a candidate for replacement if objectText is a substring of candidate.encode() && candidate.class.equals(replacement.class) otherwise the match test is an equality test.)
IllegalArgumentException
Since:
v1.0

replace

public void replace(Match regexp,
                    GenericObjectList replacement)
             throws IllegalArgumentException
Do a recursive find and replace of objects pointed to by this object based on regular expression pattern matching.

Parameters:
regexp - regular expression for the object we want to find. This is generated using a regular expression matching package such as the apache regexp package.
replacement - object we want to replace this portion with. A replacement will occur if a portion of the structure is found with a match of the encoded text with objectText and with the same class as replacement.
IllegalArgumentException
Since:
v1.0

replace

public void replace(Match regexp,
                    GenericObject replacement)
             throws IllegalArgumentException
Do a find and replace of objects based on regular expression matching of fields.

Parameters:
regexp - is the match expression (i.e. implementation of the Match interface) for the object that we want to replace.
replacement - is the object that we want to replace it with. A replacement will occur if a portion of the structure is found that matches according to the given regexp and if the class of the replaced field matches the replacement.
IllegalArgumentException

NIST SIP Parser and Stack (v1.2) API

A product of the NIST/ITL Advanced Networking Technologies Division.
See conditions of use.
Get the latest distribution.
Submit a bug report or feature request.