RE: "Smart" Bindings?
RE: "Smart" Bindings?
- Subject: RE: "Smart" Bindings?
- From: <email@hidden>
- Date: Wed, 26 Jan 2005 14:32:07 +0100
- Thread-topic: "Smart" Bindings?
Hi!
I
would actually refrain from overriding valueForKey wherever possible. Thus your
suggestion of overriding it in CTUser rather than in WOComponent would seem appropriate as it is likely to get called less often.
An
approach I really like is having 'proxy' object that handles key-value coding
once it goes down a certain branch. I guess I'd best explain this with an example.
Let's
say we dont override key-value coding in neither CTUser nor WOComponent. We rather accept to work with keypaths that have an additional dot:
su.can.editCustomers, su.can.editUsers,...
We
thus need the following method on aour WOComponent:
protected CTUser su();
In
order to handle key-value-coding for keypaths starting with 'can.' we need the
following method on CTUser:
protected PrivilegeProxy can()
{
if (this.privilegeProxy == null)
{
this.privilegeProxy = new
PrivilegeProxy();
}
return
this.privilegeProxy;
}
This
lazily instantiates an inner class:
class PrivilegeProxy implements
NSKeyValueCoding
In
this class we implement (rather than override) key-value
coding:
public Object valueForKey(String key)
{
EOQualifier qualifier = new EOKeyValueQualifier("label", EOQualifier.QualifierOperatorEqual,
key);
boolean hasPrivilege =
EOQualifier.filteredArrayWithQualifier(CTUser.this.privileges(),
qualifier).count() > 0;
return hasPrivilege ? Boolean.TRUE :
Boolean.FALSE;
}
The
above method receives the last segment of the keypath for an argument. E.g. the
String "editUsers".
This
has the distinct advantage of having code of ours only called when the key-path
starts with "su.can". All existing optimizations remain in
place.
Pierre
I have CTUser <->> CTPrivilege
CTPrivilege primarily defines a text privilege such as "canEditCustomers",
"canEditUsers", etc.
I am using bindings such as su.canEditCustomers, su.canEditUsers, etc in
WOConditionals in my components. "su" is not a real method ..... just a prefix
to intercept in overridden valueForKeyPath.
Based on the "Smart Bindings" pattern in WWDC2003-614, I have overridden
valueForKeyPath in my custom WOComponent subclass (effectively overriding valueForKeyPath in every component) to intercept keyPaths beginning with "su.can" in which case the privilege relationship is checked and a Boolean
object is returned by valueForKeyPath. This works fine but the severe warnings
in the WOComponent API that valueForKeyPath is highly optimized and should not
be over-ridden worries me!
Is this best practice or is there a more efficient way to achieve the same
goal? For example should I instead have a method "su" that returns the session
user and override something in the CTUser EOCustomObject subclass? If so, what
should I override, storedValueForKey, valueForKey, storedValueForKeyPath, valueForKeyPath and would that be more efficient than intercepting every component's valueForKeyPath?
Advice is appreciated,
Kieran
___________________________________
Kieran Kelleher
Palm Harbor, Florida USA
**********************************************************************
This email and any files transmitted with it are intended solely for
the use of the individual or entity to whom they are addressed.
If you have received this email in error please notify the sender
of this message. (email@hidden)
This email message has been checked for the presence of computer
viruses; however this protection does not ensure this message is
virus free.
Banque centrale du Luxembourg; Tel ++352-4774-1; http://www.bcl.lu
**********************************************************************
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden