|
WebObjects 5.4.2 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.webobjects.appserver.WOAssociation
public abstract class WOAssociation
The WOAssociation abstract class declares the programmatic interface to objects that represent the values of WebObject attributes, as specified in a declarations file.
The purpose of a WOAssociation object is to provide a unified interface to values of different types. For example, consider these declarations:
At runtime, the WebObjects parser scans an HTML template and these declarations and creates three WOString dynamic element objects. In the first case, the WOString's value
attribute is assigned a constant string. In the second, it's associated with the treeName
variable of the component in which the dynamic element is declared. In the third, value
is associated with the name
attribute of the component's selectedTree
variable. The search path for the value can be arbitrarily deep, depending on the needs of
your application:
MAYOR:WOString {value =country.state.city.mayor.name};
To resolve a path such as this, WebObjects accesses each part in turn. First, it looks for the component's country
variable. If the component implements a country
method, it sends one to determine the value; otherwise, it directly accesses the component's
country
instance variable to determine the value. Next, it checks the country
object for a state
attribute, using the same strategy of looking for an accessor method named state
and then, if necessary, accessing the state
variable's value directly. It continues in this way until it determines the ultimate value. This follows the NSKeyValueCoding
interface scheme.
WOAssociation objects present the WebObjects framework with a unified interface to attribute values, whether their values are static or dynamic. The value attribute for TREENAME1
in the example above will never change during the course of program execution, but the other WOStrings
have values that are potentially dynamic, and so will have to be determined at runtime.
Privately, WebObjects has its own set of subclasses of WOAssociation, each dealing with one of the above-mentioned association types. Since the value of any WOAssociation can be determined by invoking its valueInComponent
method, objects that use WOAssociation objects don't have to
be concerned with how values are resolved.
Also, objects that own WOAssociation objects can be used in a multithreaded environment and shared by multiple components safely. The component instance on which the association applies is determined at runtime, passed through by the various API defined below. The WODynamicElement subclasses make extensive use of this feature: although there is only one instance of a given dynamic element for a given page, several instances of the same page can be rendered dynamically each using their own value, at the same time, thanks to the WOAssociation owned by this dynamic element.
You rarely need to create subclasses of WOAssociation, except perhaps in situations where you subclassed WODynamicElement and wanted a special type of WOAssociation. In that case you would most likely instantiate your own WOAssociation subclass objects in your own WODynamicElement constructor.
WOAssociation.valueInComponent(WOComponent aComponent)
,
WODynamicElement
,
NSKeyValueCoding
Nested Class Summary | |
---|---|
static class |
WOAssociation.Event
The WOAssociation.Event class is used to time value assignment/retrieval at the component level. |
Field Summary | |
---|---|
static String |
TakeValueForKeyPathEvent
name of Event for timing value assignment involving traversing an arbitrary key path. |
static String |
ValueForKeyPathEvent
name of Event for timing value retrieval involving traversing an arbitrary key path. |
Constructor Summary | |
---|---|
protected |
WOAssociation()
|
Method Summary | |
---|---|
static WOAssociation |
associationWithKeyPath(String aKeyPath)
Creates and returns a WOAssociation object for a key path. |
static WOAssociation |
associationWithValue(Object aValue)
Creates and returns a WOAssociation object for a constant value. |
abstract String |
bindingInComponent(WOComponent aComponent)
Returns the binding String as seen in WebObjects Builder. |
boolean |
booleanValueInComponent(WOComponent aComponent)
Returns the association's value for this component as a boolean. |
boolean |
isValueConstant()
Used to check if an association value is constant at runtime. |
boolean |
isValueConstantInComponent(WOComponent aComponent)
Used to check if an association value is constant at runtime for a given component. |
boolean |
isValueSettable()
Used to check if an association can assign values at runtime. |
boolean |
isValueSettableInComponent(WOComponent aComponent)
Used to check if an association can assign values at runtime for a given component. |
abstract String |
keyPath()
Returns the key path if there is one. |
void |
setDebugEnabledForBinding(String aBindingName,
String aDeclarationName,
String aDeclarationType)
Enables logging whenever the association assigns or retrieves values. |
void |
setValue(Object aValue,
WOComponent aComponent)
Sets the value for this association in the component. |
String |
toString()
|
Object |
valueInComponent(WOComponent aComponent)
Returns the association's value for this component. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final String ValueForKeyPathEvent
WOEvent
,
Constant Field Valuespublic static final String TakeValueForKeyPathEvent
WOEvent
,
Constant Field ValuesConstructor Detail |
---|
protected WOAssociation()
Method Detail |
---|
public Object valueInComponent(WOComponent aComponent)
For example, invoking value
on a WOAssociation created from this declaration,
returns the value of the current component's
DOWNPAYMENT:WOString {value = downpayment};
downpayment
variable. Invoking value
on a WOAssociation created from this declaration,
returns the value "$5000.00" (independent of the current component).
DOWNPAYMENT:WOString {value = "$5000.00"};
This method raises an exception if it cannot resolve the WOAssociation's value with the current component.
This method is used to retrieve values throughout the WebObjects framework by all private subclasses of WODynamicElement.
Another way in which the WebObjects framework uses this method is to synchronize the values of nested components. When attributes in child and parent components are associated with one another and changes occur in one component, this method is invoked to migrate those changes to the other component.
aComponent
- component which should resolve the association
WOAssociation.setValue(Object aValue, WOComponent aComponent)
public boolean booleanValueInComponent(WOComponent aComponent)
value
is computed by calling valueInComponent(aComponent)
Then, this method returns false if:
- value
is null
- value
is a java.lang.Boolean with a value of false
- value
is a java.lang.Number, a numeric value equivalent to zero.
- value
is a java.lang.String, either "no", "false", "nil" or "null" (independent of case)
- value
is a java.lang.String that can be interpreted as a number whose value is zero (using Integer.parseInt()
)
Otherwise, this method returns true
.
aComponent
- component which should resolve the association
WOAssociation.valueInComponent(WOComponent aComponent)
public void setValue(Object aValue, WOComponent aComponent)
aComponent
pointed to by the association binding name. It then sets the variable's value to aValue
, or invokes the setter method
with aValue
as a parameter. This method throws an exception if the receiver's value is not settable. For example, invoking setValue
on a WOAssociation created from this declaration,
sets the current component's
USER:WOTextField {value = userName};
userName
variable to the value typed into the WOTextField.
This method is used to set values throughout the WebObjects framework by all private subclasses of WODynamicElement.
Another way in which the WebObjects framework uses this method is to synchronize the values of nested components. When attributes in child and parent components are associated with one another and changes occur in one component, this method is invoked to migrate those changes to the other component.
aValue
- the input valueaComponent
- component which should resolve the associationWOAssociation.valueInComponent(WOComponent aComponent)
,
WOAssociation.isValueSettable()
public boolean isValueSettable()
false
if the association's value is constant, true
otherwiseWOAssociation.associationWithKeyPath(String aKeyPath)
,
WOAssociation.isValueConstant()
,
WOAssociation.isValueSettableInComponent(WOComponent aComponent)
public boolean isValueConstant()
true
if the WOAssociation's value is a constant, false
otherwiseWOAssociation.associationWithValue(Object aValue)
,
WOAssociation.isValueSettable()
,
WOAssociation.isValueConstantInComponent(WOComponent aComponent)
public boolean isValueSettableInComponent(WOComponent aComponent)
aComponent
- component which should resolve the association
true
when the association is settable, false
otherwiseWOAssociation.associationWithKeyPath(String aKeyPath)
,
WOAssociation.isValueConstantInComponent(WOComponent aComponent)
,
WOAssociation.isValueSettable()
public boolean isValueConstantInComponent(WOComponent aComponent)
aComponent
- component which should resolve the association
false
when the association is constant, true
otherwiseWOAssociation.associationWithValue(Object aValue)
,
WOAssociation.isValueSettableInComponent(WOComponent aComponent)
,
WOAssociation.isValueConstant()
public void setDebugEnabledForBinding(String aBindingName, String aDeclarationName, String aDeclarationType)
aBindingName
- name of the binding valueaDeclarationName
- the declaration nameaDeclarationType
- the declaration typeWOApplication.logTakeValueForDeclarationNamed(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.Object)
,
WOApplication.logSetValueForDeclarationNamed(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.Object)
public abstract String keyPath()
public abstract String bindingInComponent(WOComponent aComponent)
aComponent
- component which should resolve the association
public static WOAssociation associationWithValue(Object aValue)
it invokes this method to create a WOAssociation whose value is "Time Flies!".
TREENAME3:WOString {value = "Time Flies!"};
aValue
- value of the WOAssociation object created
WOAssociation.associationWithKeyPath(String aKeyPath)
public static WOAssociation associationWithKeyPath(String aKeyPath)
aKeyPath
at runtime, in a given component. This method is used when a dynamic element's attribute is set to a variable from the component's script. For example, when the WebObjects
parser sees a declaration of this sort,
it invokes
TREENAME3:WOString {value = selectedTree.name};
associationWithKeyPath
to create a WOAssociation whose key is "selectedTree.name". When the resulting WOAssociation is asked for its value, it searches for the value of the name
attribute of the current component's
selectedTree
attribute. If aKeyPath
is null
, the value of the WOAssociation is also null
.
aKeyPath
- used to determine value of the WOAssociation object returned
WOAssociation.associationWithValue(Object aValue)
public String toString()
toString
in class Object
|
Last updated June 2008 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |