home *** CD-ROM | disk | FTP | other *** search
- /*
- Copyright (c) 1996, NeXT Software, Inc.
- All rights reserved.
-
- You may freely copy, distribute and reuse the code in this example.
- NeXT disclaims any warranty of any kind, expressed or implied,
- as to its fitness for any particular use.
- */
- #import <BusinessLogic/MovieMedia.h>
-
- @implementation MovieMedia
-
- - (NSString *)name {
- return [movie valueForKey:@"title"];
- }
-
- - (NSNumber *)mediaAsNumber {
- if ([media isEqual:@"T"])
- return [NSNumber numberWithInt:1];
- else if ([media isEqual:@"D"])
- return [NSNumber numberWithInt:2];
- else
- return [NSNumber numberWithInt:0];
- }
-
- - (void)setMediaAsNumber:(int)iValue {
- [self willChange];
- [media autorelease];
- switch(iValue) {
- case 1: media = @"T"; break;
- case 2: media = @"D"; break;
- default: media = @"";
- }
- }
-
- - (void)dealloc
- {
- [media release];
- [movie release];
- [super dealloc];
- }
-
- - (void)awakeFromInsertionInEditingContext:(EOEditingContext *)editingContext
- {
- // set up our default values
- if(!rentalTerms) {
- static EOGlobalID *gid = nil;
-
- // I'd like to setup some default for rental terms here
- if(!gid) {
- EOFetchSpecification *fetchSpec;
- NSArray *results;
-
- // look up the global ID of the rental term with ID = 1
- fetchSpec = [EOFetchSpecification fetchSpecificationWithEntityName:@"RentalTerms"
- qualifier:[EOQualifier qualifierWithQualifierFormat:@"rentalTermID = 1"]
- sortOrderings:nil];
-
- results = [editingContext objectsWithFetchSpecification:fetchSpec
- editingContext:editingContext];
- gid = [editingContext globalIDForObject:[results objectAtIndex:0]];
- }
- rentalTerms = [[editingContext faultForGlobalID:gid editingContext:editingContext] retain];
- }
- }
-
- @end
-