com.cafesoft.cams.access
Class AbstractResourcePattern

java.lang.Object
  extended by com.cafesoft.cams.access.AbstractResourcePattern
All Implemented Interfaces:
ResourcePattern, Comparable

public abstract class AbstractResourcePattern
extends Object
implements ResourcePattern

Provides a generic implementation of ResourcePattern methods for extension by resource-specific base classes. Base classes must implement the abstract "matches(ResourceRequest r)" method and may override the "setPattern(String pattern)" method to interpret resource-specific patterns.

Since:
5/21/02

Field Summary
protected  int hashcode
          The hashcode of the ResourcePattern.
protected  boolean ignoreCase
          The flag indicating whether pattern matching is case sensitive or not.
protected  String pattern
          The overall Resource ID pattern.
protected  ResourcePatternInfo rpInfo
          The ResourcePatternInfo containing field-level metadata.
protected  BigDecimal score
          The specificality score.
 
Constructor Summary
AbstractResourcePattern()
           
 
Method Summary
 int compareTo(Object o)
          Compares two ResourcePatterns and determines if a ResourcePattern is less than, equals to, or greater than another ResourcePattern.
abstract  boolean equals(Object obj)
          Determine if two ResourcePattern objects are equal.
 FieldInfo[] getFieldInfo()
          Get information about ResourcePattern fields.
 FieldInfo getFieldInfo(String fieldName)
          Get information about a specific ResourcePattern field.
abstract  Object getFieldValue(String fieldName)
          Get the value associated with a ResourcePattern field.
 boolean getIgnoreCase()
          Get the flag indicating whether pattern matching is performed in a case sensitive or a case-insensitive way.
 String getPattern()
          Get the pattern.
 int hashCode()
          Compute the Hashcode for the ResourcePattern.
abstract  boolean match(ResourceRequest resourceReq)
          Determine if a ResourceRequest matches this ResourcePattern.
 BigDecimal score()
          Get the specificality score.
abstract  void setFieldValue(String fieldName, Object fieldValue)
          Set the value associated with a ResourcePattern field.
 void setIgnoreCase(boolean ignoreCase)
          Set the flag that enables/disables ignoring the case of the pattern.
abstract  void setPattern(String pattern)
          Set the Resource Identifier pattern.
 String toString()
          Get a String Representation of the pattern.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

pattern

protected String pattern
The overall Resource ID pattern.


ignoreCase

protected boolean ignoreCase
The flag indicating whether pattern matching is case sensitive or not.


rpInfo

protected ResourcePatternInfo rpInfo
The ResourcePatternInfo containing field-level metadata.


score

protected BigDecimal score
The specificality score.


hashcode

protected int hashcode
The hashcode of the ResourcePattern.

Constructor Detail

AbstractResourcePattern

public AbstractResourcePattern()
Method Detail

getPattern

public String getPattern()
Get the pattern.

Specified by:
getPattern in interface ResourcePattern
Returns:
a string representing a pattern of resource identifiers that will be used to match ResourceRequests.

setPattern

public abstract void setPattern(String pattern)
                         throws ResourcePatternException
Set the Resource Identifier pattern.

Specified by:
setPattern in interface ResourcePattern
Parameters:
pattern - a string that represents a pattern of Resource identifiers.
Throws:
ResourcePatternException - if the overall resource identifier pattern is invalid.

setIgnoreCase

public void setIgnoreCase(boolean ignoreCase)
Set the flag that enables/disables ignoring the case of the pattern.

Specified by:
setIgnoreCase in interface ResourcePattern
Parameters:
ignoreCase - if true, ignore the case of the pattern. If false, then matches the pattern case-sensitively.

getIgnoreCase

public boolean getIgnoreCase()
Get the flag indicating whether pattern matching is performed in a case sensitive or a case-insensitive way.

Specified by:
getIgnoreCase in interface ResourcePattern
Returns:
true if pattern matching is performed case-insentively, false if pattern matchin is performed case-sensitively.

getFieldInfo

public FieldInfo[] getFieldInfo()
Get information about ResourcePattern fields.

Specified by:
getFieldInfo in interface ResourcePattern
Returns:
an array of FieldInfo objects: one for each ResourcePattern field.

getFieldInfo

public FieldInfo getFieldInfo(String fieldName)
Get information about a specific ResourcePattern field.

Specified by:
getFieldInfo in interface ResourcePattern
Parameters:
fieldName - the name of the Field.
Returns:
the corresponding FieldInfo containing metadata about the ResourcePattern Field or null if no Field by that name.

getFieldValue

public abstract Object getFieldValue(String fieldName)
Get the value associated with a ResourcePattern field.

Specified by:
getFieldValue in interface ResourcePattern
Parameters:
fieldName - the name of the Field.
Returns:
the value associated with the Field.

setFieldValue

public abstract void setFieldValue(String fieldName,
                                   Object fieldValue)
                            throws ResourcePatternException
Set the value associated with a ResourcePattern field.

Specified by:
setFieldValue in interface ResourcePattern
Parameters:
fieldName - the name of the Field.
fieldValue - the value to be be assigned to the Field.
Throws:
ResourcePatternException - if the specified field is unknown or the field value is invalid.

match

public abstract boolean match(ResourceRequest resourceReq)
Determine if a ResourceRequest matches this ResourcePattern.

Specified by:
match in interface ResourcePattern
Parameters:
resourceReq - the ResourceRequest to be checked against this ResourcePattern.
Returns:
true if ResourceRequest matches, else return false.

equals

public abstract boolean equals(Object obj)
Determine if two ResourcePattern objects are equal.

The equals method implements an equivalence relation:

Overrides:
equals in class Object
Parameters:
obj - the reference object with which to compare.
Returns:
true if objects are equal, false otherwise.

toString

public String toString()
Get a String Representation of the pattern.

Overrides:
toString in class Object
Returns:
a String Representation of the pattern.

score

public BigDecimal score()
Get the specificality score.

This method calculates how specific a ResourcePattern is. Because, the ResourcePattern is aware of the various FieldValuePatterns that compose itself it can determine how specific a pattern is. The score is calculated using an algorithm that is implementation specific.

Specified by:
score in interface ResourcePattern
Returns:
a BigDecimal object containing the speificality score.

hashCode

public int hashCode()
Compute the Hashcode for the ResourcePattern.

Overrides:
hashCode in class Object
Returns:
the hashcode for the ResourcePattern.

compareTo

public int compareTo(Object o)
Compares two ResourcePatterns and determines if a ResourcePattern is less than, equals to, or greater than another ResourcePattern. The key functionality this function performs is that it tells us which ResourcePattern object is more specific. Therefore, the ResourcePattern that is the most specific should be ordered higher. Note: this class has a natural ordering that is inconsistent with equals.

Specified by:
compareTo in interface Comparable
Parameters:
o - the Object to be compared.
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
Throws:
NullPointerException - if o is null.
ClassCastException - if the specified object's type prevents it from being compared to this Object.


Generated on 10:38:35 AM April 14, 2011, © 1996-2010 Cafésoft LLC. All rights reserved.