edu.ucsb.ccs.jcontractor
Class PackageLevelInstrumentationFilter

java.lang.Object
  |
  +--edu.ucsb.ccs.jcontractor.PackageLevelInstrumentationFilter
All Implemented Interfaces:
InstrumentationFilter

public class PackageLevelInstrumentationFilter
extends java.lang.Object
implements InstrumentationFilter

An instrumentation filter that assigns instrumentation level by package (or class, if desired). The filter is given a package name, a class name, and an instrumentation level. The class name may be "*" to match any class in the package or a subpackage. Note that this differs a little from how Java import statements work.

The filter level is how many levels down the package is, so "edu.*" has filter level 1, and "edu.ucsb.ccs.*" has filter level 3. This way, more specific filters override more general filters.

To match classes in the default package, but no other packages, use the "magic" package name "<default>".

Version:
$Id: PackageLevelInstrumentationFilter.java,v 1.2 2002/05/22 06:28:39 parkera Exp $
Author:
Parker Abercrombie

Field Summary
 
Fields inherited from interface edu.ucsb.ccs.jcontractor.InstrumentationFilter
ALL, NONE, POST, PRE
 
Constructor Summary
PackageLevelInstrumentationFilter(java.lang.String classAndPackageName, int instrumentationLevel)
          Create a filter from a class and package string.
PackageLevelInstrumentationFilter(java.lang.String packagename, java.lang.String classname, int instrumentationLevel)
          Create a new filter.
 
Method Summary
 boolean appliesTo(java.lang.String theclass)
          Determine if this filter applies to a given class.
 java.lang.String getClassName()
          Get the name of the class matched by this filter.
 int getFilterLevel()
          Get the level of this filter.
 int getInstrumentationLevel()
          Get the instrumentation level assigned to classes that match the filter criteria.
 int getInstrumentationLevel(java.lang.String theclass)
          Get the instrumentation level to assign to a class that matches the filter criteria.
 java.lang.String getPackageName()
          Get the name of the package matched by this filter.
 void setClassName(java.lang.String name)
          Set the name of the class matched by this filter.
 void setInstrumentationLevel(int level)
          Set the instrumentation level assigned to classes that match the filter criteria.
 void setPackageAndClass(java.lang.String packageAndClass)
          Set the package and class from a full class name (including package).
 void setPackageName(java.lang.String name)
          Set the name of the package to match.
 java.lang.String toString()
          Get a string representation of the filter, for debugging.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PackageLevelInstrumentationFilter

public PackageLevelInstrumentationFilter(java.lang.String packagename,
                                         java.lang.String classname,
                                         int instrumentationLevel)
Create a new filter.

Parameters:
packagename - the name of the package to match. If both package and class are "*", all classes match.
classname - the name of the class to match, or "*" to match any class in any subpackage.
instrumentationLevel - the instrumentation level to assign to classes that match.

PackageLevelInstrumentationFilter

public PackageLevelInstrumentationFilter(java.lang.String classAndPackageName,
                                         int instrumentationLevel)
Create a filter from a class and package string. To match all classes in any package, simply pass "*". If only a class name is given the default package is assumed ("jInstrument" is the same as "<default>.jInstrument").

Parameters:
classAndPackageName - the name of the class and package to match, for example "edu.ucsb.ccs.jcontractor.jInstrument" or "edu.ccs.*".
instrumentationLevel - the instrumentation level to assign to classes that match.
Method Detail

appliesTo

public boolean appliesTo(java.lang.String theclass)
Determine if this filter applies to a given class. Returns true if the class matches the class and package criteria in this filter.

Specified by:
appliesTo in interface InstrumentationFilter
Parameters:
theclass - the name of a class to test (including package name).
Returns:
true if theclass matches the criteria.

getInstrumentationLevel

public int getInstrumentationLevel(java.lang.String theclass)
Get the instrumentation level to assign to a class that matches the filter criteria.

Specified by:
getInstrumentationLevel in interface InstrumentationFilter
Parameters:
theclass - the name of the class to get the instrumentation level for.
Returns:
the instrumentation level for theclass.
See Also:
setInstrumentationLevel(int), getInstrumentationLevel()

setPackageName

public void setPackageName(java.lang.String name)
Set the name of the package to match. If both class name and package name are "*", any class matches. If the class name is not "*", then a package name of "*" has no meaning (you can't match a certain class in any package).

Parameters:
name - the new package name.
See Also:
getPackageName()

getPackageName

public java.lang.String getPackageName()
Get the name of the package matched by this filter.

Returns:
the name of the package matched by the filter.
See Also:
setPackageName(String)

setClassName

public void setClassName(java.lang.String name)
Set the name of the class matched by this filter. Pass "*" to match any class in any subpackage. If both class name and package name are "*", any class matches.

Parameters:
name - the name of the class to match.
See Also:
getClassName()

getClassName

public java.lang.String getClassName()
Get the name of the class matched by this filter.

Returns:
the name of the class matched by the filter.
See Also:
setClassName(String)

setPackageAndClass

public void setPackageAndClass(java.lang.String packageAndClass)
Set the package and class from a full class name (including package). Examples include "edu.ucsb.ccs.jcontractor.jInstrument" and "edu.ccs.*".


setInstrumentationLevel

public void setInstrumentationLevel(int level)
Set the instrumentation level assigned to classes that match the filter criteria.

Parameters:
level - the instrumentation level.
See Also:
getInstrumentationLevel(), getInstrumentationLevel(String)

getInstrumentationLevel

public int getInstrumentationLevel()
Get the instrumentation level assigned to classes that match the filter criteria.

Returns:
the instrumentation level.
See Also:
setInstrumentationLevel(int), getInstrumentationLevel(String)

getFilterLevel

public int getFilterLevel()
Get the level of this filter. The filter level is determined by how the depth of the package. "*" has level 0, "edu.*" has level 1, "edu.ucsb.ccs.jcontractor.jInstrument" has level 4, etc.

Specified by:
getFilterLevel in interface InstrumentationFilter
Returns:
the filter level.

toString

public java.lang.String toString()
Get a string representation of the filter, for debugging.

Overrides:
toString in class java.lang.Object