org.lastbamboo.common.sdp
Class GenericObject

java.lang.Object
  extended by org.lastbamboo.common.sdp.GenericObject
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
Host, HostPort, NameValue, SDPObject

public abstract class GenericObject
extends Object
implements Serializable, Cloneable

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.
See Also:
Serialized Form

Field Summary
protected static String AND
           
protected static String AT
           
protected static String COLON
           
protected static String COMMA
           
protected static String DOT
           
protected static String DOUBLE_QUOTE
           
protected static String EQUALS
           
protected static String GREATER_THAN
           
protected static String HT
           
protected static Set immutableClasses
           
protected static String[] immutableClassNames
           
protected  int indentation
           
protected static String LESS_THAN
           
protected static String LPAREN
           
protected  Match matchExpression
           
protected static String NEWLINE
           
protected static String PERCENT
           
protected static String POUND
           
protected static String QUESTION
           
protected static String QUOTE
           
protected static String RETURN
           
protected static String RPAREN
           
protected static String SEMICOLON
           
protected static String SLASH
           
protected static String SP
           
protected static String STAR
           
protected  String stringRepresentation
           
 
Constructor Summary
protected GenericObject()
           
 
Method Summary
protected  void Assert(boolean condition, String msg)
          An assertion checking utility.
 Object clone()
          Clones this object.
protected  void dbgPrint()
          Debug printing function.
protected  void dbgPrint(String s)
          Debug printing function.
 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.
protected  String getIndentation()
           
 Match getMatcher()
          Return the match expression.
static boolean isMySubclass(Class other)
           
static Object makeClone(Object obj)
          Clones the given object.
 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.
protected  void sprint(boolean booleanField)
          Pretty printing accumulator function for booleans
protected  void sprint(char charField)
          Pretty printing accumulator function for chars
protected  void sprint(double doubleField)
          Pretty printing accumulator function for doubles
protected  void sprint(float floatField)
          Pretty printing accumulator function for floats
protected  void sprint(int intField)
          Pretty printing accumulator function for ints
protected  void sprint(long longField)
          Pretty printing accumulator function for longs
protected  void sprint(Object o)
          Pretty printing function accumulator for objects.
protected  void sprint(short shortField)
          Pretty printing accumulator function for shorts
protected  void sprint(String a)
          Add a new string to the accumulated string representation.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SEMICOLON

protected static final String SEMICOLON
See Also:
Constant Field Values

COLON

protected static final String COLON
See Also:
Constant Field Values

COMMA

protected static final String COMMA
See Also:
Constant Field Values

SLASH

protected static final String SLASH
See Also:
Constant Field Values

SP

protected static final String SP
See Also:
Constant Field Values

EQUALS

protected static final String EQUALS
See Also:
Constant Field Values

STAR

protected static final String STAR
See Also:
Constant Field Values

NEWLINE

protected static final String NEWLINE
See Also:
Constant Field Values

RETURN

protected static final String RETURN
See Also:
Constant Field Values

LESS_THAN

protected static final String LESS_THAN
See Also:
Constant Field Values

GREATER_THAN

protected static final String GREATER_THAN
See Also:
Constant Field Values

AT

protected static final String AT
See Also:
Constant Field Values

DOT

protected static final String DOT
See Also:
Constant Field Values

QUESTION

protected static final String QUESTION
See Also:
Constant Field Values

POUND

protected static final String POUND
See Also:
Constant Field Values

AND

protected static final String AND
See Also:
Constant Field Values

LPAREN

protected static final String LPAREN
See Also:
Constant Field Values

RPAREN

protected static final String RPAREN
See Also:
Constant Field Values

DOUBLE_QUOTE

protected static final String DOUBLE_QUOTE
See Also:
Constant Field Values

QUOTE

protected static final String QUOTE
See Also:
Constant Field Values

HT

protected static final String HT
See Also:
Constant Field Values

PERCENT

protected static final String PERCENT
See Also:
Constant Field Values

immutableClasses

protected static final Set immutableClasses

immutableClassNames

protected static final String[] immutableClassNames

indentation

protected int indentation

stringRepresentation

protected String stringRepresentation

matchExpression

protected Match matchExpression
Constructor Detail

GenericObject

protected GenericObject()
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.

isMySubclass

public static boolean isMySubclass(Class other)

makeClone

public static Object makeClone(Object obj)
Clones the given object. If the object is a wrapped type, an array, a GenericObject or a GenericObjectList, it is cast to the appropriate type and the clone() method is invoked. Else if the object implements Cloneable, reflection is used to discover and invoke the public clone() method. Otherwise, the original object is returned.


clone

public Object clone()
Clones 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.

getIndentation

protected String getIndentation()

sprint

protected void sprint(String a)
Add a new string to the accumulated string representation.


sprint

protected void sprint(Object o)
Pretty printing function accumulator for objects.


sprint

protected void sprint(int intField)
Pretty printing accumulator function for ints


sprint

protected void sprint(short shortField)
Pretty printing accumulator function for shorts


sprint

protected void sprint(char charField)
Pretty printing accumulator function for chars


sprint

protected void sprint(long longField)
Pretty printing accumulator function for longs


sprint

protected void sprint(boolean booleanField)
Pretty printing accumulator function for booleans


sprint

protected void sprint(double doubleField)
Pretty printing accumulator function for doubles


sprint

protected void sprint(float floatField)
Pretty printing accumulator function for floats


dbgPrint

protected void dbgPrint()
Debug printing function.


dbgPrint

protected void dbgPrint(String s)
Debug printing function.


equals

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

Overrides:
equals in class Object
Parameters:
that - is the other object to test against.
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.


Assert

protected void Assert(boolean condition,
                      String msg)
An assertion checking utility.


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.
Throws:
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.)
Throws:
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.
Throws:
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.
Throws:
IllegalArgumentException


Copyright © 2013 LittleShoot. All Rights Reserved.