• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: "Smart" Bindings?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "Smart" Bindings?


  • Subject: Re: "Smart" Bindings?
  • From: Kieran Kelleher <email@hidden>
  • Date: Wed, 26 Jan 2005 16:16:25 -0500

Pierre,

Brilliant strategy! I'll do it!

Thanks very much, Kieran

___________________________________
Kieran Kelleher
Palm Harbor, Florida USA

On Jan 26, 2005, at 8:32 AM, email@hidden wrote:

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
-----Original Message-----
From: webobjects-dev-bounces+pierre.bernard=email@hidden [mailto:webobjects-dev- bounces+pierre.bernard=email@hidden]On Behalf Of Kieran Kelleher
Sent: Wednesday, January 26, 2005 1:15 PM
To: WebObjects Dev (Apple)
Subject: "Smart" Bindings?



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


References: 
 >RE: "Smart" Bindings? (From: <email@hidden>)

  • Prev by Date: Many to Many self join
  • Next by Date: Re: Many to Many self join
  • Previous by thread: RE: "Smart" Bindings?
  • Next by thread: Many to Many relationship
  • Index(es):
    • Date
    • Thread