• 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: Custom Attribute Questions.....
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Custom Attribute Questions.....


  • Subject: Re: Custom Attribute Questions.....
  • From: Hugi Thordarson <email@hidden>
  • Date: Wed, 15 Jun 2005 15:59:29 +0000

The short answer:
Make your attribute type immutable. It is the right thing to do for such a simple class and will save you a lot of work in the long run. Plus, you get to keep all the hair you would otherwise lose while tracking down hard-to-find bugs :-).


The long answer:
I have a framework that uses a mutable attribute type, basically, my own subclass of NSMutableDictionary. I tried really hard to make the attribute's mutability work out without having to make any special acommodations outside of the value class itself, but it really just doesn't. EOF wants it's attributes nice, clean and immutable.


What I did to get around it was to make my dictionary attribute keep a reference to it's EO and attribute keypath. So every time the dictionary is changed, it replaces the EO's instance with a clone of itself. It works, but it's dirty as hell, slow, and is really only an option if you have complete control over your framework, i.e. you're using it in your own application. So, caveats aplenty.

In your class (I dropped accessors/mutators for brevity):

public class EncryptedEOAttribute {

	public EOEnterprise Object owningEO;
	public String keyPath;	

public void setValue( Object newValue ) {
// first do the stuff you need to do with (encrypt) your new value here, and then...:


		if( owningEO != null ) {
			owningEO.takeValueForKeyPath( this.clone(), keyPath );
		}
	}
}

In  the EO class:

public class MyEO extends EOGenericRecord {

    public void awakeFromInsertion( EOEditingContext ec ) {
        super.awakeFromInsertion( ec );
        setMyAttribute( new EncryptedEOAttribute() );
        myAttribute.owningEO = this;
        myAttribute.keyPath = "myAttribute";
    }

    public void awakeFromFetch( EOEditingContext ec ) {
        super.awakeFromFetch( ec );
        myAttribute.owningEO = this;
        myAttribute.keyPath = "myAttribute";
    }
}

Sorry for inflicting this abomination upon you - but you asked :-).

Cheers,
Hugi

// Hugi Thordarson
// Landeyưa
// http://hugi.karlmenn.is/



On 15.6.2005, at 15:24, Kieran Kelleher wrote:

I need a little Customer EO Attribute advice so I don't end up missing the beach this weekend like Chuck Hill did on page 43 of PWO :-)

I have a custom class, EncryptedEOAttribute, that wraps a String ivar named _decodedValue

The class has value() and setValue() that return and set the raw clear string.

It has a conversion method public String toEncodedString() that encodes the string into the database.

It has a factory method that decodes an encoded string from the database to create an instance (wrapping the clear string):
public static EncryptedEOAttribute createInstanceFromEncodedString( String encodedString )


It has a display method toString() that masks the clear string by replacing most of the characters with an asterisk.

In my app, I plan to simply use setValue to update the instance's _decodedValue ivar.

For a class like this, do I have to worry about the object mutability snapshot saving problem since changes only occur when setValue is called and the String ivar _decodedValue is changed?

If so, how would I approach it ..... do I need to design my EncryptedEOAttribute class to be immutable (basically remove setValue method) and create a new instance every time a new _decodedValue is to be stored? Does EOF just compare the object reference to the snapshot reference or does it use the conversion method return value for snapshot comparison before deciding to save.

Regards,

-Kieran
________________________________________________________________
Blog: http://webobjects.webhop.org/

_______________________________________________
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

_______________________________________________ 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: 
 >Custom Attribute Questions..... (From: Kieran Kelleher <email@hidden>)

  • Prev by Date: Re: OpenSource WebObjects
  • Next by Date: (no subject)
  • Previous by thread: Custom Attribute Questions.....
  • Next by thread: (no subject)
  • Index(es):
    • Date
    • Thread