org.iperg.part.core
Class IpObjectPattern

java.lang.Object
  extended by org.iperg.part.core.IpObjectPattern
All Implemented Interfaces:
IpSerializable

public class IpObjectPattern
extends java.lang.Object
implements IpSerializable

The IpObjectPattern class is used to create object patterns that can be matched against instances of any PART object class.

Patterns can be used to express requirements concerning the class to which a PART object instance belongs or inherits from. The setClass method takes a class name and a match parameter that determines how the class name will be matched against the class of a PART object. For example, the following pattern will match objects that are instances of the class SomeClass:

 IpObjectPattern pattern = new IpObjectPattern(); 
 pattern.setClass("SomeClass", IpObjectPattern.EQUALS); 
Patterns can also be used to express requirements concerning the state of an object's properties. For instance, the following pattern will match any object that has a property named speed, whose value is "23.0":
 IpObjectPattern pattern = new IpObjectPattern();
 pattern.addProperty("speed", "23.0"); 
If more than one property requirement is added to a pattern, objects must fulfill all of these in order to match the pattern.

The class and property pattern requirements can of course be used in combination:

 IpObjectPattern pattern = new IpObjectPattern(); 
 pattern.setClass("SomeClass", IpObjectPattern.EQUALS); 
 pattern.addProperty("speed", "23.0"); 
 pattern.addProperty("name", "Player1"); 

Apart from the class and property requirements, patterns can be also be used to search for objects using their identifiers. However, since every synchronised object has an unique identifier, a pattern that carries an identifier requirement can match one and only one object.

 IpObjectPattern pattern = new IpObjectPattern(); 
 pattern.setId(...); 

Version:
1.0.0 Initial version
Author:
Olov Stahl - olovs@sics.se

Field Summary
static int EQUALS
          A class requirement match type that specifies that the class of an object must equal the given class in order for the object to match the pattern.
static int INSTANCEOF
          A class requirement match type that specifies that the class of an object must be an instance of the given class or interface in order for the object to match the pattern.
 
Constructor Summary
IpObjectPattern()
          Constructs a empty pattern (the pattern contains no id, class or property requirements).
 
Method Summary
 void addProperty(java.lang.String name, java.lang.String value)
          Add a property requirement.
 void addProperty(java.lang.String group, java.lang.String name, java.lang.String value)
          Add a property requirement.
 void addPropertyExists(java.lang.String name)
          Add a property requirement.
 void addPropertyExists(java.lang.String group, java.lang.String name)
          Add a property requirement.
 void read(IpInputStream stream)
          Read the patterns's state from an input stream.
 void setClass(java.lang.String className, int matchType)
          Set class requirement.
 void setId(IpIdentifier id)
          Set id requirement.
 void write(IpOutputStream stream)
          Write the state of the pattern into an output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EQUALS

public static final int EQUALS
A class requirement match type that specifies that the class of an object must equal the given class in order for the object to match the pattern.

See Also:
Constant Field Values

INSTANCEOF

public static final int INSTANCEOF
A class requirement match type that specifies that the class of an object must be an instance of the given class or interface in order for the object to match the pattern.

See Also:
Constant Field Values
Constructor Detail

IpObjectPattern

public IpObjectPattern()
Constructs a empty pattern (the pattern contains no id, class or property requirements).

Method Detail

setId

public void setId(IpIdentifier id)
Set id requirement. To match the pattern a synchronised object must have the same identifier.

Parameters:
id - The identifier that must equal the identifier of a synchronised object for the object to match the pattern.

setClass

public void setClass(java.lang.String className,
                     int matchType)
Set class requirement. Since a pattern can hold only one class requirement, the given values will replace values supplied in previous calls to this method.

Parameters:
className - A class name. The match type parameter determines how the name should be interpreted when matching the pattern against an object.
matchType - The class match type

addProperty

public void addProperty(java.lang.String name,
                        java.lang.String value)
Add a property requirement. For an object to match the pattern, it must have a property with the same name and value as given by the method parameters. The property must belong to the default group.

Many property requirements can be added to the same pattern.

Parameters:
name - The name of the property
value - The required value of the property

addProperty

public void addProperty(java.lang.String group,
                        java.lang.String name,
                        java.lang.String value)
Add a property requirement. For an object to match the pattern, it must have a property with the same name and value as given by the method parameters. The property must also belong to the group specified by the group parameter. If the group parameter is

null

, the default group is assumed.

Many property requirements can be added to the same pattern.

Parameters:
group - The name of the group that the property belongs to
name - The name of the property
value - The required value of the property

addPropertyExists

public void addPropertyExists(java.lang.String name)
Add a property requirement. For an object to match the pattern, it must have a property with the same name as given by the name parameter. The property must belong to the default group. The property can have any value.

Many property requirements can be added to the same pattern.

Parameters:
name - The name of the property

addPropertyExists

public void addPropertyExists(java.lang.String group,
                              java.lang.String name)
Add a property requirement. For an object to match the pattern, it must have a property with the same name as given by the name parameter. The property must also belong to the group specified by the groupnull

, the default group is assumed. The property can have any value.

Many property requirements can be added to the same pattern.

Parameters:
group - The name of the group that the property belongs to
name - The name of the property

write

public void write(IpOutputStream stream)
           throws java.io.IOException
Write the state of the pattern into an output stream.

Specified by:
write in interface IpSerializable
Parameters:
stream - The output stream into which the patterns's state should be written
Throws:
java.io.IOException - if an io exception occured while writing the pattern to the stream

read

public void read(IpInputStream stream)
          throws java.io.IOException
Read the patterns's state from an input stream.

Specified by:
read in interface IpSerializable
Parameters:
stream - The input stream from which the patterns's state should be read
Throws:
java.io.IOException - if the read failed