home *** CD-ROM | disk | FTP | other *** search
/ OpenStep (Enterprise) / OpenStepENTCD.toast / OEDEV / EODEV.Z / MovieMedia.m < prev    next >
Encoding:
Text File  |  1996-08-23  |  2.0 KB  |  68 lines

  1. /*
  2.         Copyright (c) 1996, NeXT Software, Inc.
  3.         All rights reserved.
  4.  
  5.         You may freely copy, distribute and reuse the code in this example.
  6.         NeXT disclaims any warranty of any kind, expressed or implied,
  7.         as to its fitness for any particular use.
  8. */
  9. #import <BusinessLogic/MovieMedia.h>
  10.  
  11. @implementation MovieMedia
  12.  
  13. - (NSString *)name {
  14.     return [movie valueForKey:@"title"];
  15. }
  16.  
  17. - (NSNumber *)mediaAsNumber {
  18.     if ([media isEqual:@"T"])
  19.         return [NSNumber numberWithInt:1];
  20.     else if ([media isEqual:@"D"])
  21.         return [NSNumber numberWithInt:2];
  22.     else
  23.         return [NSNumber numberWithInt:0];
  24. }
  25.  
  26. - (void)setMediaAsNumber:(int)iValue {
  27.     [self willChange];
  28.     [media autorelease];
  29.     switch(iValue) {
  30.         case 1: media = @"T"; break;
  31.         case 2: media = @"D"; break;
  32.         default: media = @"";
  33.     }
  34. }
  35.  
  36. - (void)dealloc
  37. {
  38.     [media release];
  39.     [movie release];
  40.     [super dealloc];
  41. }
  42.  
  43. - (void)awakeFromInsertionInEditingContext:(EOEditingContext *)editingContext
  44. {
  45.     // set up our default values
  46.     if(!rentalTerms) {
  47.         static EOGlobalID *gid = nil;
  48.  
  49.         // I'd like to setup some default for rental terms here
  50.         if(!gid) {
  51.             EOFetchSpecification *fetchSpec;
  52.             NSArray *results;
  53.  
  54.             // look up the global ID of the rental term with ID = 1
  55.             fetchSpec = [EOFetchSpecification fetchSpecificationWithEntityName:@"RentalTerms"
  56.                          qualifier:[EOQualifier qualifierWithQualifierFormat:@"rentalTermID = 1"]
  57.                                                                  sortOrderings:nil];
  58.  
  59.             results = [editingContext objectsWithFetchSpecification:fetchSpec
  60.                                                      editingContext:editingContext];
  61.             gid = [editingContext globalIDForObject:[results objectAtIndex:0]];
  62.         }
  63.         rentalTerms = [[editingContext faultForGlobalID:gid editingContext:editingContext] retain];
  64.     }
  65. }
  66.  
  67. @end
  68.