WebObjects 5.2

com.webobjects.directtoweb
Class Rule

java.lang.Object
  |
  +--com.webobjects.directtoweb.Rule
All Implemented Interfaces:
EOKeyValueArchiving, Serializable

public class Rule
extends Object
implements Serializable, EOKeyValueArchiving

The Rule class represents a simple inference.

A rule consists of a left-hand side and right-hand side. The left-hand side is a set of pre-conditions, represented by a qualifier. The right-hand side is a post-condition, represented by an assignment.

One rule may take precendence over another, depending on authorship, context, and fit. In general, a more specific rule has higher priority.

The D2WModel class makes extensive use of rules.

The implementation is subject to change in future releases.

See Also:
D2WModel, Assignment, EOQualifier, Serialized Form

Inner classes inherited from class com.webobjects.eocontrol.EOKeyValueArchiving
EOKeyValueArchiving.Awaking, EOKeyValueArchiving.FinishInitialization, EOKeyValueArchiving.Support
 
Field Summary
static String authorKey
          A key representing the author.
static int DIRECT_2_WEB
          A constant denoting authorship by Direct to Web.
static String lhsKey
          A key representing the left-hand side.
static String rhsKey
          A key representing the right-hand side.
static int WEB_ASSISTANT
          A constant denoting authorship by the Web Assistant.
static int WEB_ASSISTANT_PAGE_AVAILABLE
          A constant denoting authorship by the Web Assistant when generating new pageAvailable rules in the user model.
 
Constructor Summary
Rule()
          Creates an instance of Rule.
Rule(int author, EOQualifier lhs, Assignment rhs)
          Creates an instance of Rule with the specified author, left-hand side, and right-hand side.
 
Method Summary
 int author()
          Gets the author.
 boolean canFireInContext(D2WContext context)
          Indicates whether the rule can fire by evaluating the left-hand side with the specified context.
 int compareRules(Rule otherRule)
          Compares two rules, based on priority.
 Assignment createAssignment(String keyPath, String value)
          Creates an assignment with the specified key path and value.
 Vector dataTypesInvolved()
          Gets the set of names of data types involved.
static Object decodeWithKeyValueUnarchiver(EOKeyValueUnarchiver unarchiver)
           
 Vector dynamicPagesInvolved()
          Gets the set of names of dynamic pages involved.
 void encodeWithKeyValueArchiver(EOKeyValueArchiver archiver)
          Asks the receiver to archive its state into the EOKeyValueArchiver archiver.
 Object fire(D2WContext context)
          Fires the right-hand side with the specified context.
 String firstDynamicPageNameInvolved()
          Gets the name of the first dynamic page involved.
 String firstEntityInvolved()
          Gets the name of the first entity involved.
 String firstPropertyKeyInvolved()
          Gets the name of the first property key involved.
 String firstTaskInvolved()
          Gets the name of the first task involved.
 boolean hasSameSettingsAs(com.apple.client.directtoweb.common.Settings settings, boolean areSettingsForADynamicPage)
          Compares the rule with the specified settings.
 boolean isEntityPermissionRule()
          Indicates that a rule involves the assignment of an entity permission.
 boolean isEntityRule()
          Indicates that a rule involves the assignment of an entity.
 boolean isLookRule()
          Indicates that a rule involves the assignment of a look.
 boolean isStartupRule()
          Indicates that a rule involves the assignment of a start-up task or start-up entity name.
 boolean isTaskRule()
          Indicates that a rule involves the assignment of a task.
 EOQualifier lhs()
          Gets the left-hand side.
 int priority()
          Gets the priority of the rule.
 Assignment rhs()
          Gets the left-hand side.
 String rhsKeyPath()
          Gets the key path of the right-hand side.
 int rhsKeyPathHash()
          Gets the hashcode of the key path of the right-hand side.
 void setLhs(EOQualifier newValue)
          Sets the left-hand side to the specified value.
 void setRhs(Assignment newValue)
          Sets the right-hand side to the specified value.
 Vector tasksInvolved()
          Gets the set of names of tasks involved.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DIRECT_2_WEB

public static final int DIRECT_2_WEB
A constant denoting authorship by Direct to Web.

In the current implementation, the value is the int zero.

The implementation is subject to change in future releases.

See Also:
author()

WEB_ASSISTANT

public static final int WEB_ASSISTANT
A constant denoting authorship by the Web Assistant.

In the current implementation, the value is the int 100.

The implementation is subject to change in future releases.

See Also:
DIRECT_2_WEB

WEB_ASSISTANT_PAGE_AVAILABLE

public static final int WEB_ASSISTANT_PAGE_AVAILABLE
A constant denoting authorship by the Web Assistant when generating new pageAvailable rules in the user model.

In the current implementation, the value is the int 105.

The implementation is subject to change in future releases.

See Also:
WEB_ASSISTANT

authorKey

public static final String authorKey
A key representing the author.

In the current implementation, the value is "author".

The implementation is subject to change in future releases.


lhsKey

public static final String lhsKey
A key representing the left-hand side.

In the current implementation, the value is "lhs".

The implementation is subject to change in future releases.


rhsKey

public static final String rhsKey
A key representing the right-hand side.

In the current implementation, the value is "rhs".

The implementation is subject to change in future releases.

Constructor Detail

Rule

public Rule()
Creates an instance of Rule.

In the current implementation, the default author is DIRECT_2_WEB, and both the left-hand side and right-hand side remain unassigned. Note: A rule should not be used before the right-hand side is set.

The implementation is subject to change in future releases.

See Also:
DIRECT_2_WEB, Rule(int, EOQualifier, Assignment)

Rule

public Rule(int author,
            EOQualifier lhs,
            Assignment rhs)
Creates an instance of Rule with the specified author, left-hand side, and right-hand side.

The interface is subject to change in future releases.

Parameters:
author - int
lhs - instance of EOQualifier
author - instance of Assignment
Throws:
IllegalArgumentException - if right-hand side is null
See Also:
Rule(), EOQualifier, Assignment
Method Detail

author

public int author()
Gets the author.
Returns:
int that represents the author

canFireInContext

public boolean canFireInContext(D2WContext context)
Indicates whether the rule can fire by evaluating the left-hand side with the specified context.
Parameters:
context - instance of D2WContext
Returns:
true if the rule can fire in the specified context; false otherwise
See Also:
lhs(), EOQualifier.evaluateWithObject(Object)

compareRules

public int compareRules(Rule otherRule)
Compares two rules, based on priority.
Parameters:
otherRule - instance of Rule
Returns:
the value 0 if the argument rule is equal to this rule; a value less than zero if this rule is greater than the rule argument; a value greater than zero if this rule is less than the rule argument or the rule argument is null
See Also:
priority()

createAssignment

public Assignment createAssignment(String keyPath,
                                   String value)
Creates an assignment with the specified key path and value. Creates an instance of Assignment if the value starts and ends with a quotation mark; an instance of KeyValueAssignment otherwise.
Parameters:
keyPath - the key path
value - the value
Returns:
instance of Assignment
See Also:
Assignment.Assignment(String, Object)

dataTypesInvolved

public Vector dataTypesInvolved()
Gets the set of names of data types involved.

The current implementation caches the names. Traverses the left-hand side, looking at EOKeyValueQualifiers that specify a class name.

The implementation is subject to change in future releases.

Returns:
instance of java.util.Vector
See Also:
lhs()

decodeWithKeyValueUnarchiver

public static Object decodeWithKeyValueUnarchiver(EOKeyValueUnarchiver unarchiver)

dynamicPagesInvolved

public Vector dynamicPagesInvolved()
Gets the set of names of dynamic pages involved.

The current implementation caches the names. Traverses the left-hand side, looking at EOKeyValueQualifiers that specify a dynamic page.

The implementation is subject to change in future releases.

Returns:
instance of java.util.Vector
See Also:
firstDynamicPageNameInvolved(), lhs(), D2WModel.DynamicPageKey

encodeWithKeyValueArchiver

public void encodeWithKeyValueArchiver(EOKeyValueArchiver archiver)
Description copied from interface: EOKeyValueArchiving
Asks the receiver to archive its state into the EOKeyValueArchiver archiver.
Specified by:
encodeWithKeyValueArchiver in interface EOKeyValueArchiving
Following copied from interface: com.webobjects.eocontrol.EOKeyValueArchiving
Parameters:
archiver - the EOKeyValueArchiver
See Also:
EOKeyValueArchiver

fire

public Object fire(D2WContext context)
Fires the right-hand side with the specified context.
Parameters:
context - instance of D2WContext
Returns:
the value returned by firing the right-hand side
See Also:
rhs(), Assignment.fire(D2WContext)

firstDynamicPageNameInvolved

public String firstDynamicPageNameInvolved()
Gets the name of the first dynamic page involved.

The current implementation caches the name. Traverses the left-hand side, looking for the first EOKeyValueQualifier that specifies a dynamic page.

The implementation is subject to change in future releases.

Returns:
instance of String
See Also:
dynamicPagesInvolved(), lhs(), D2WModel.DynamicPageKey

firstEntityInvolved

public String firstEntityInvolved()
Gets the name of the first entity involved.

The current implementation caches the name. Traverses the left-hand side, looking for the first EOKeyValueQualifier that specifies an entity.

The implementation is subject to change in future releases.

Returns:
instance of String
See Also:
lhs()

firstPropertyKeyInvolved

public String firstPropertyKeyInvolved()
Gets the name of the first property key involved.

The current implementation caches the name. Traverses the left-hand side, looking for the first EOKeyValueQualifier that specifies a property key.

The implementation is subject to change in future releases.

Returns:
instance of String
See Also:
lhs(), D2WModel.PropertyKeyKey

firstTaskInvolved

public String firstTaskInvolved()
Gets the name of the first task involved.

The current implementation caches the name. Traverses the left-hand side, looking for the first EOKeyValueQualifier that specifies a task.

The implementation is subject to change in future releases.

Returns:
instance of String
See Also:
tasksInvolved(), lhs(), D2WModel.TaskKey

hasSameSettingsAs

public boolean hasSameSettingsAs(com.apple.client.directtoweb.common.Settings settings,
                                 boolean areSettingsForADynamicPage)
Compares the rule with the specified settings. Looks only at the first dynamic page involved if the specified flag areSettingsForADynamicPage is true; looks at the first task involved and first entity involved otherwise.

If areSettingsForADynamicPage is true, it returns true if firstDynamicPageNameInvolved equals the dynamicPage of settings; false otherwise.

If areSettingsForADynamicPage is false, it returns true if firstTaskInvolved and firstEntityInvolved equal the task and entity (respectively) of settings.

The current implementation assumes that the rule is of the form (task="xx" and entity="yy"); no EOOrQualifiers.

The implementation is subject to change in future releases.

Parameters:
settings - instance of Settings
areSettingsForADynamicPage - boolean
Returns:
see method description
See Also:
firstDynamicPageNameInvolved(), firstTaskInvolved(), firstEntityInvolved()

isEntityPermissionRule

public boolean isEntityPermissionRule()
Indicates that a rule involves the assignment of an entity permission.
Returns:
true if the rule is an entity permission rule; false otherwise

isEntityRule

public boolean isEntityRule()
Indicates that a rule involves the assignment of an entity.
Returns:
true if the rule is an entity rule; false otherwise

isLookRule

public boolean isLookRule()
Indicates that a rule involves the assignment of a look.
Returns:
true if the rule is a look rule; false otherwise

isStartupRule

public boolean isStartupRule()
Indicates that a rule involves the assignment of a start-up task or start-up entity name.
Returns:
true if the rule is a start-up rule; false otherwise
See Also:
rhs(), D2WModel.StartupTaskKey, D2WModel.StartupEntityNameKey, D2WContext.startupTask(), D2WContext.startupEntityName()

isTaskRule

public boolean isTaskRule()
Indicates that a rule involves the assignment of a task.
Returns:
true if the rule is a task rule; false otherwise

lhs

public EOQualifier lhs()
Gets the left-hand side.
Returns:
instance of EOQualifier
See Also:
setLhs(EOQualifier)

priority

public int priority()
Gets the priority of the rule. Priority is largely a function of authorship and how specific a rule is.

The current implementation caches the value of the priority. A "dummy true" rule has low priority. Dynamic page rules have priority over others. A complex EOAndQualifier is higher than a simple one.

The implementation is subject to change in future releases.

Returns:
int representing the priority of the rule
See Also:
author(), D2WModel.DummyTrueKey, EOQualifier

rhs

public final Assignment rhs()
Gets the left-hand side.
Returns:
instance of Assignment
See Also:
setRhs(Assignment)

rhsKeyPath

public final String rhsKeyPath()
Gets the key path of the right-hand side.
Returns:
the right-hand side key path.
See Also:
rhs(), Assignment.keyPath()

rhsKeyPathHash

public int rhsKeyPathHash()
Gets the hashcode of the key path of the right-hand side.

The current implementation caches the value of the hashcode.

The implementation is subject to change in future releases.

Returns:
the right-hand side key path hashcode
See Also:
rhsKeyPath(), Object.hashCode()

setLhs

public void setLhs(EOQualifier newValue)
Sets the left-hand side to the specified value.
Parameters:
newValue - instance of EOQualifier
See Also:
lhs()

setRhs

public void setRhs(Assignment newValue)
Sets the right-hand side to the specified value.
Parameters:
newValue - instance of Assignment
See Also:
rhs()

tasksInvolved

public Vector tasksInvolved()
Gets the set of names of tasks involved.

The current implementation caches the names. Traverses the left-hand side, looking at EOKeyValueQualifiers that specify a task, for example, task="Edit".

The implementation is subject to change in future releases.

Returns:
instance of java.util.Vector
See Also:
lhs(), D2WModel.TaskKey, firstTaskInvolved()

toString

public String toString()
Overrides:
toString in class Object

Last updated Fri Feb 21 13:15:00 PST 2003.

Copyright © 2003 Apple Computer, Inc.