mirror of
https://github.com/gnustep/libs-gdl2.git
synced 2025-04-22 12:55:44 +00:00
Implemeted things in EOKeyValueArchiver, put back David changes in
-adaptorValueByConvertingAttributeValue in EOAttribute.m git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@21125 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
ad07dd8054
commit
375fc565d9
5 changed files with 447 additions and 211 deletions
|
@ -1,3 +1,11 @@
|
|||
2005-04-19 Manuel Guesdon <mguesdon@orange-concept.com>
|
||||
|
||||
* EOControl/EOKeyValueArchiver.m: implemented EOKeyValueArchiver
|
||||
* EOControl/EOKeyValueArchiver.h: removed private methods
|
||||
* EOControl/EOSortOrdering.h: added EOKeyValueArchiving protocol to EOSortOrdering
|
||||
* EOAccess/EOAttribute.m: put back David changes in -adaptorValueByConvertingAttributeValue
|
||||
added some docs
|
||||
|
||||
2005-04-07 Stephane Corthesy <stephane@sente.ch>
|
||||
|
||||
* Tools/eoutil.m: Added -excludedEntities option when dumping;
|
||||
|
|
|
@ -1101,8 +1101,11 @@ return nexexp
|
|||
value = [GDL2_alloc(NSData) initWithBytes: bytes length: length];
|
||||
|
||||
if(_valueFactoryMethod != NULL)
|
||||
value = [(id)valueClass performSelector: _valueFactoryMethod
|
||||
withObject: [value autorelease]];
|
||||
{
|
||||
//TODO: doc says that the returned value is autoreleased !!
|
||||
value = [(id)valueClass performSelector: _valueFactoryMethod
|
||||
withObject: [value autorelease]];
|
||||
};
|
||||
break;
|
||||
|
||||
case EOFactoryMethodArgumentIsBytes:
|
||||
|
@ -1242,11 +1245,23 @@ return nexexp
|
|||
return date;
|
||||
}
|
||||
|
||||
/** Returns the name of the method to use for creating a custom class
|
||||
value for this attribute.
|
||||
|
||||
See Also: - valueFactoryMethod, -newValueForBytes:length:
|
||||
**/
|
||||
- (NSString *)valueFactoryMethodName
|
||||
{
|
||||
return _valueFactoryMethodName;
|
||||
}
|
||||
|
||||
/** Returns the selector of the method to use for creating a custom class
|
||||
value for this attribute.
|
||||
Default implementation returns selector for name returned by
|
||||
-valueFactoryMethodName or NULL if no selector is found.
|
||||
|
||||
See Also: - valueFactoryMethodName, -newValueForBytes:length:
|
||||
**/
|
||||
- (SEL)valueFactoryMethod
|
||||
{
|
||||
return _valueFactoryMethod;
|
||||
|
@ -1268,12 +1283,16 @@ return nexexp
|
|||
*/
|
||||
- (id)adaptorValueByConvertingAttributeValue: (id)value
|
||||
{
|
||||
BOOL convert = NO;
|
||||
EOAdaptorValueType adaptorValueType = [self adaptorValueType];
|
||||
|
||||
switch (adaptorValueType)
|
||||
// No conversion for an EONull value
|
||||
if (value != GDL2_EONull)
|
||||
{
|
||||
/* Temporary reverted so we can discuss about this
|
||||
BOOL convert = NO;
|
||||
|
||||
// Find if we need a conversion
|
||||
switch (adaptorValueType)
|
||||
{
|
||||
case EOAdaptorNumberType:
|
||||
convert = [value isKindOfClass: GDL2_NSNumberClass] ? NO : YES;
|
||||
break;
|
||||
|
@ -1286,67 +1305,76 @@ return nexexp
|
|||
case EOAdaptorDateType:
|
||||
convert = [value isKindOfClass: GDL2_NSDateClass] ? NO : YES;
|
||||
break;
|
||||
*/
|
||||
//TODO It's only a quick Fix
|
||||
case EOAdaptorNumberType:
|
||||
case EOAdaptorCharactersType:
|
||||
case EOAdaptorDateType:
|
||||
convert = ([value isKindOfClass: GDL2_NSNumberClass]
|
||||
|| [value isKindOfClass: GDL2_NSStringClass]
|
||||
|| [value isKindOfClass: GDL2_NSDateClass]) ? NO : YES;
|
||||
break;
|
||||
case EOAdaptorBytesType:
|
||||
convert = [value isKindOfClass: GDL2_NSDataClass] ? NO : YES;
|
||||
break;
|
||||
default:
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"Illegal adaptorValueType: %d",
|
||||
adaptorValueType];
|
||||
}
|
||||
|
||||
convert = (value == GDL2_EONull) ? NO : convert;
|
||||
|
||||
if (convert)
|
||||
{
|
||||
SEL sel;
|
||||
sel = [self adaptorValueConversionMethod];
|
||||
|
||||
if (sel == 0)
|
||||
{
|
||||
if (adaptorValueType == EOAdaptorBytesType)
|
||||
{
|
||||
value = [value archiveData];
|
||||
}
|
||||
else
|
||||
{
|
||||
/* This exception might not be conformant, but seems helpful. */
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"Value of class: %@ needs conversion "
|
||||
@"yet no conversion method specified. "
|
||||
@"Attribute is %@. adaptorValueType=%d",
|
||||
NSStringFromClass([value class]),
|
||||
self,adaptorValueType];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
value = [value performSelector: sel];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Do value need conversion ?
|
||||
if (convert)
|
||||
{
|
||||
SEL sel;
|
||||
sel = [self adaptorValueConversionMethod];
|
||||
|
||||
if (sel == 0)
|
||||
{
|
||||
if (adaptorValueType == EOAdaptorBytesType)
|
||||
{
|
||||
value = [value archiveData];
|
||||
}
|
||||
else
|
||||
{
|
||||
/* This exception might not be conformant, but seems helpful. */
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"Value of class: %@ needs conversion "
|
||||
@"yet no conversion method specified. "
|
||||
@"Attribute is %@. adaptorValueType=%d",
|
||||
NSStringFromClass([value class]),
|
||||
self,adaptorValueType];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
value = [value performSelector: sel];
|
||||
}
|
||||
}
|
||||
};
|
||||
return value;
|
||||
}
|
||||
|
||||
/** Returns method name to use to convert value of a class
|
||||
different than attribute adaptor value type.
|
||||
|
||||
See also: -adaptorValueByConvertingAttributeValue, -adaptorValueConversionMethod
|
||||
**/
|
||||
- (NSString *)adaptorValueConversionMethodName
|
||||
{
|
||||
return _adaptorValueConversionMethodName;
|
||||
}
|
||||
|
||||
/** Returns selector of the method to use to convert value of a class
|
||||
different than attribute adaptor value type.
|
||||
Default implementation returns selector of method returned by
|
||||
adaptorValueConversionMethodName or NULL if there's not selector for the method
|
||||
|
||||
See also: -adaptorValueByConvertingAttributeValue, -adaptorValueConversionMethodName
|
||||
**/
|
||||
- (SEL)adaptorValueConversionMethod
|
||||
{
|
||||
return _adaptorValueConversionMethod;
|
||||
}
|
||||
|
||||
/** Returns an EOAdaptorValueType describing the adaptor
|
||||
(i.e. database) type of data for this attribute.
|
||||
|
||||
Returned value can be:
|
||||
EOAdaptorBytesType Raw bytes (default type)
|
||||
EOAdaptorNumberType Number value (attribute valueClass is kind of NSNumber)
|
||||
EOAdaptorCharactersType String value (attribute valueClass is kind of NSString)
|
||||
EOAdaptorDateType Date value (attribute valueClass is kind of NSDate)
|
||||
|
||||
**/
|
||||
- (EOAdaptorValueType)adaptorValueType
|
||||
{
|
||||
if (!_flags.isAttributeValueInitialized)
|
||||
|
@ -1392,6 +1420,11 @@ return nexexp
|
|||
|
||||
@implementation EOAttribute (EOAttributeValueCreationEditing)
|
||||
|
||||
/** Set the "factory method" name (the method to invoke to create custom class attribute value).
|
||||
This method must be a class method returning an autoreleased value of attribute valueClass.
|
||||
|
||||
See also: -setFactoryMethodArgumentType:
|
||||
**/
|
||||
- (void)setValueFactoryMethodName: (NSString *)factoryMethodName
|
||||
{
|
||||
[self willChange];
|
||||
|
|
|
@ -60,13 +60,6 @@
|
|||
- (void)encodeInt: (int)intValue
|
||||
forKey: (NSString *)key;
|
||||
|
||||
- (void)_encodeDictionary: (id)dictionary
|
||||
forKey: (id)key;
|
||||
- (void)_encodeObjects: (id)objects
|
||||
forKey: (id)key;
|
||||
- (void)_encodeValue: (id)value
|
||||
forKey: (id)key;
|
||||
|
||||
- (NSDictionary *)dictionary;
|
||||
|
||||
- (void)setDelegate: (id)delegate;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
EOKeyValueArchiver.m <title>EOKeyValueArchiver Class</title>
|
||||
|
||||
Copyright (C) 2000-2002 Free Software Foundation, Inc.
|
||||
Copyright (C) 2000-2002,2005 Free Software Foundation, Inc.
|
||||
|
||||
Author: Manuel Guesdon <mguesdon@orange-concept.com>
|
||||
Date: September 2000
|
||||
|
@ -9,7 +9,34 @@
|
|||
$Revision$
|
||||
$Date$
|
||||
|
||||
<abstract></abstract>
|
||||
<abstract>
|
||||
EOKeyValueArchiver object is used to archive a tree of objects into a
|
||||
key/value propertyList.
|
||||
EOKeyValueUnarchiver object is used to unarchive from a propertyList a
|
||||
tree of objects archived with a EOKeyValueArchiver.
|
||||
|
||||
Example:
|
||||
|
||||
// Archiving:
|
||||
EOKeyValueArchiver* archive=AUTORELEASE([EOKeyValueArchiver new]);
|
||||
[archive setDelegate:MyArchivingDelegate];
|
||||
[archiver encodeObject:anObject
|
||||
forKey:@"anObjectKey"];
|
||||
[archiver encodeInt:125
|
||||
forKey:@"aKey"];
|
||||
...
|
||||
|
||||
NSDictionary* archivePropertyList=[archiver dictionary];
|
||||
|
||||
// Now unarchive archivePropertyList
|
||||
|
||||
EOKeyValueUnarchiver* unarchiver=AUTORELEASE([[EOKeyValueUnarchiver alloc]initWith:archivePropertyList]);
|
||||
[archive setDelegate:MyUnarchivingDelegate];
|
||||
id anObject=[unarchiver decodeObjectForKey:@"anObjectKey"];
|
||||
int anInt=[unarchiver decodeIntForKey:@"anKey"];
|
||||
[unarchiver finishInitializationOfObjects];
|
||||
[unarchiver awakeObjects]
|
||||
</abstract>
|
||||
|
||||
This file is part of the GNUstep Database Library.
|
||||
|
||||
|
@ -52,6 +79,7 @@ RCS_ID("$Id$")
|
|||
|
||||
#include <EOControl/EOKeyValueArchiver.h>
|
||||
#include <EOControl/EODebug.h>
|
||||
#include <EOControl/EOPrivate.h>
|
||||
|
||||
|
||||
@interface EOKeyValueArchivingContainer : NSObject
|
||||
|
@ -74,6 +102,17 @@ RCS_ID("$Id$")
|
|||
|
||||
@implementation EOKeyValueArchivingContainer
|
||||
|
||||
+ (void)initialize
|
||||
{
|
||||
static BOOL initialized=NO;
|
||||
if (!initialized)
|
||||
{
|
||||
initialized=YES;
|
||||
|
||||
GDL2_PrivateInit();
|
||||
}
|
||||
}
|
||||
|
||||
+ (EOKeyValueArchivingContainer *)keyValueArchivingContainer
|
||||
{
|
||||
return [[[self alloc] init] autorelease];
|
||||
|
@ -120,13 +159,27 @@ RCS_ID("$Id$")
|
|||
|
||||
@end
|
||||
|
||||
|
||||
@implementation EOKeyValueArchiver
|
||||
|
||||
+ (void)initialize
|
||||
{
|
||||
static BOOL initialized=NO;
|
||||
if (!initialized)
|
||||
{
|
||||
initialized=YES;
|
||||
|
||||
GDL2_PrivateInit();
|
||||
}
|
||||
}
|
||||
|
||||
/** Init method **/
|
||||
- (id) init
|
||||
{
|
||||
[self notImplemented: _cmd]; //TODOFN
|
||||
return nil;
|
||||
if ((self=[super init]))
|
||||
{
|
||||
_propertyList=[NSMutableDictionary new];
|
||||
};
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
|
@ -135,61 +188,301 @@ RCS_ID("$Id$")
|
|||
[super dealloc];
|
||||
}
|
||||
|
||||
- (id) dictionary
|
||||
/** Returns archived object/tree as propertList **/
|
||||
- (NSDictionary*) dictionary
|
||||
{
|
||||
EOFLOGObjectFnStartOrCond(@"EOKeyValueArchiver");
|
||||
EOFLOGObjectFnStopOrCond(@"EOKeyValueArchiver");
|
||||
return _propertyList;
|
||||
}
|
||||
|
||||
/** Archives integer 'intValue' as 'key' **/
|
||||
- (void) encodeInt: (int)intValue
|
||||
forKey: (NSString*)key
|
||||
{
|
||||
[self notImplemented: _cmd]; //TODOFN
|
||||
EOFLOGObjectFnStartOrCond(@"EOKeyValueArchiver");
|
||||
|
||||
NSDebugMLLog(@"gsdb", @"key=%@ intValue=%d",key,intValue);
|
||||
NSAssert(key,@"No key");
|
||||
|
||||
[_propertyList setObject:[NSString stringWithFormat:@"%d",intValue]
|
||||
forKey:key];
|
||||
|
||||
NSDebugMLLog(@"gsdb", @"_propertyList=%@",_propertyList);
|
||||
|
||||
EOFLOGObjectFnStopOrCond(@"EOKeyValueArchiver");
|
||||
}
|
||||
|
||||
/** Archives boolean 'yn' as 'key' **/
|
||||
- (void) encodeBool: (BOOL)yn
|
||||
forKey: (NSString*)key
|
||||
{
|
||||
[self notImplemented: _cmd]; //TODOFN
|
||||
{
|
||||
EOFLOGObjectFnStartOrCond(@"EOKeyValueArchiver");
|
||||
|
||||
NSDebugMLLog(@"gsdb", @"key=%@ yn=%s",key,(yn ? "YES" : "NO"));
|
||||
NSAssert(key,@"No key");
|
||||
|
||||
[_propertyList setObject:(yn ? @"YES" : @"NO")
|
||||
forKey:key];
|
||||
|
||||
NSDebugMLLog(@"gsdb", @"_propertyList=%@",_propertyList);
|
||||
|
||||
EOFLOGObjectFnStopOrCond(@"EOKeyValueArchiver");
|
||||
}
|
||||
|
||||
- (void) encodeReferenceToObject: (id)object
|
||||
forKey: (NSString*)key
|
||||
{
|
||||
[self notImplemented: _cmd]; //TODOFN
|
||||
}
|
||||
|
||||
- (void) encodeObject: (id)object
|
||||
forKey: (NSString*)key
|
||||
{
|
||||
[self notImplemented: _cmd]; //TODOFN
|
||||
}
|
||||
|
||||
- (void) _encodeDictionary: (id)dictionary
|
||||
/** Archives a dictionary for 'key' **/
|
||||
- (void) _encodeDictionary: (NSDictionary*)dictionary
|
||||
forKey: (NSString*)key
|
||||
{
|
||||
[self notImplemented: _cmd]; //TODOFN
|
||||
EOFLOGObjectFnStartOrCond(@"EOKeyValueArchiver");
|
||||
|
||||
NSDebugMLLog(@"gsdb", @"key=%@ dictionary=%@",key,dictionary);
|
||||
NSAssert(key,@"No key");
|
||||
|
||||
if ([dictionary count]>0)
|
||||
{
|
||||
NSEnumerator* keyEnumerator=nil;
|
||||
NSString* tmpKey=nil;
|
||||
NSMutableDictionary* currentPropertyList=nil;
|
||||
|
||||
// Save current propertyList
|
||||
currentPropertyList=AUTORELEASE(_propertyList);
|
||||
NSDebugMLLog(@"gsdb", @"currentPropertyList=%@",currentPropertyList);
|
||||
|
||||
// Set new empty propertyList to encode each object
|
||||
_propertyList=[NSMutableDictionary new];
|
||||
|
||||
keyEnumerator=[dictionary keyEnumerator];
|
||||
while((tmpKey=[keyEnumerator nextObject]))
|
||||
{
|
||||
id object=[dictionary valueForKey:tmpKey];
|
||||
|
||||
[self encodeObject:object
|
||||
forKey:tmpKey];
|
||||
};
|
||||
|
||||
// add _propertyList into current propertyList
|
||||
// for the key
|
||||
[currentPropertyList setObject:_propertyList
|
||||
forKey:key];
|
||||
|
||||
// put back current propertyList
|
||||
ASSIGN(_propertyList,currentPropertyList);
|
||||
}
|
||||
else
|
||||
{
|
||||
[_propertyList setObject:[NSDictionary dictionary]
|
||||
forKey:key];
|
||||
};
|
||||
|
||||
EOFLOGObjectFnStopOrCond(@"EOKeyValueArchiver");
|
||||
}
|
||||
|
||||
- (void) _encodeObjects: (id)objects
|
||||
/** Archives an array objects for 'key' **/
|
||||
- (void) _encodeObjects: (NSArray*)objects
|
||||
forKey: (NSString*)key
|
||||
{
|
||||
[self notImplemented: _cmd]; //TODOFN
|
||||
unsigned int count=0;
|
||||
|
||||
EOFLOGObjectFnStartOrCond(@"EOKeyValueArchiver");
|
||||
|
||||
NSDebugMLLog(@"gsdb", @"key=%@ objects=%@",key,objects);
|
||||
NSAssert(key,@"No key");
|
||||
|
||||
count=[objects count];
|
||||
if (count>0)
|
||||
{
|
||||
unsigned int i=0;
|
||||
NSMutableDictionary* currentPropertyList=nil;
|
||||
NSMutableArray* archiveArray=(NSMutableArray*)[NSMutableArray array];
|
||||
|
||||
// Save current propertyList
|
||||
currentPropertyList=AUTORELEASE(_propertyList);
|
||||
NSDebugMLLog(@"gsdb", @"currentPropertyList=%@",currentPropertyList);
|
||||
|
||||
// Set new empty propertyList to encode each object
|
||||
_propertyList=[NSMutableDictionary new];
|
||||
|
||||
for(i=0;i<count;i++)
|
||||
{
|
||||
id object=[objects objectAtIndex:i];
|
||||
id encodedObject=nil;
|
||||
|
||||
[self encodeObject:object
|
||||
forKey:@"voidKey"];
|
||||
|
||||
encodedObject=[_propertyList objectForKey:@"voidKey"];
|
||||
NSDebugMLLog(@"gsdb", @"object=%@ encodedObject=%@",object,encodedObject);
|
||||
NSAssert1(encodedObject,@"No encodedObject for %@",object);
|
||||
|
||||
[archiveArray addObject:encodedObject];
|
||||
|
||||
[_propertyList removeObjectForKey:@"voidKey"];
|
||||
};
|
||||
|
||||
// add archiveArray into current propertyList
|
||||
// for the key
|
||||
[currentPropertyList setObject:archiveArray
|
||||
forKey:key];
|
||||
|
||||
// put back current propertyList
|
||||
ASSIGN(_propertyList,currentPropertyList);
|
||||
}
|
||||
else
|
||||
{
|
||||
[_propertyList setObject:[NSArray array]
|
||||
forKey:key];
|
||||
};
|
||||
|
||||
EOFLOGObjectFnStopOrCond(@"EOKeyValueArchiver");
|
||||
}
|
||||
|
||||
- (void) _encodeValue: (id)value
|
||||
forKey: (NSString*)key
|
||||
{
|
||||
//Private EO methods. Not currently used
|
||||
[self notImplemented: _cmd]; //TODOFN
|
||||
}
|
||||
|
||||
|
||||
/** Archives the object 'object' reference as 'key'
|
||||
The receiver gets the reference object by calling
|
||||
its delegate method -archiver:referenceToEncodeForObject:
|
||||
**/
|
||||
- (void) encodeReferenceToObject: (id)object
|
||||
forKey: (NSString*)key
|
||||
{
|
||||
EOFLOGObjectFnStartOrCond(@"EOKeyValueArchiver");
|
||||
|
||||
NSDebugMLLog(@"gsdb", @"key=%@ object=%@",key,object);
|
||||
NSAssert(key,@"No key");
|
||||
|
||||
// object is nil ?
|
||||
if (!object)
|
||||
{
|
||||
//Hum, what to do for nil object ? //TODO
|
||||
}
|
||||
else
|
||||
{
|
||||
// First get object reference
|
||||
if ([_delegate
|
||||
respondsToSelector:@selector(archiver:referenceToEncodeForObject:)])
|
||||
object = [_delegate archiver:self
|
||||
referenceToEncodeForObject:object];
|
||||
|
||||
|
||||
NSDebugMLLog(@"gsdb", @"key=%@ object (reference)=%@",key,object);
|
||||
|
||||
//TODO
|
||||
// What should we do when delegate returns no reference ?
|
||||
// Here we decide to encode it directly...
|
||||
|
||||
[self encodeObject:object
|
||||
forKey:key];
|
||||
};
|
||||
|
||||
NSDebugMLLog(@"gsdb", @"_propertyList=%@",_propertyList);
|
||||
|
||||
EOFLOGObjectFnStopOrCond(@"EOKeyValueArchiver");
|
||||
}
|
||||
|
||||
/** Archives the object 'object' as 'key'.
|
||||
'object' should be a NSString, a NSData, NSArray or NSDictionary or conforms to
|
||||
EOKeyValueArchiving protocol. Raise an exception otherwise.
|
||||
**/
|
||||
- (void) encodeObject: (id)object
|
||||
forKey: (NSString*)key
|
||||
{
|
||||
EOFLOGObjectFnStartOrCond(@"EOKeyValueArchiver");
|
||||
|
||||
NSDebugMLLog(@"gsdb", @"key=%@ object=%@",key,object);
|
||||
NSAssert(key,@"No key");
|
||||
|
||||
// object is nil ?
|
||||
if (!object)
|
||||
{
|
||||
//Hum, what to do for nil object ? //TODO
|
||||
}
|
||||
else if ([object isKindOfClass:GDL2_NSStringClass]
|
||||
|| [object isKindOfClass:GDL2_NSDataClass]
|
||||
|| [object isKindOfClass:GDL2_NSNumberClass])
|
||||
{
|
||||
// Add NSString & NSData directly (or a copy if it is mutable)
|
||||
|
||||
id objectCopy=[object copy];
|
||||
[_propertyList setObject:objectCopy
|
||||
forKey:key];
|
||||
DESTROY(objectCopy);
|
||||
}
|
||||
else if ([object isKindOfClass:GDL2_NSDictionaryClass])
|
||||
{
|
||||
[self _encodeDictionary:object
|
||||
forKey:key];
|
||||
}
|
||||
else if ([object isKindOfClass:GDL2_NSArrayClass])
|
||||
{
|
||||
[self _encodeObjects:object
|
||||
forKey:key];
|
||||
}
|
||||
else if ([object conformsToProtocol:@protocol(EOKeyValueArchiving)])
|
||||
{
|
||||
// Object conforms to protocol EOKeyValueArchiving ?
|
||||
|
||||
// We will encode it in self empty propertyList and put this
|
||||
// propertyList back and the current propertyList
|
||||
|
||||
// Save current propertyList
|
||||
NSMutableDictionary* currentPropertyList=nil;
|
||||
currentPropertyList=AUTORELEASE(_propertyList);
|
||||
NSDebugMLLog(@"gsdb", @"currentPropertyList=%@",currentPropertyList);
|
||||
|
||||
// Set new empty one as current one
|
||||
_propertyList=[NSMutableDictionary new];
|
||||
|
||||
// add object class name to object propertyList
|
||||
[_propertyList setObject:NSStringFromClass([object class])
|
||||
forKey:@"class"];
|
||||
|
||||
// Encode object
|
||||
[object encodeWithKeyValueArchiver:self];
|
||||
|
||||
NSDebugMLLog(@"gsdb", @"object propertyList=%@",_propertyList);
|
||||
|
||||
// add object propertyList into current propertyList
|
||||
// for the key
|
||||
[currentPropertyList setObject:_propertyList
|
||||
forKey:key];
|
||||
|
||||
// put back current propertyList
|
||||
ASSIGN(_propertyList,currentPropertyList);
|
||||
}
|
||||
else
|
||||
{
|
||||
[NSException raise:NSInvalidArgumentException
|
||||
format:@"Don't know how to keyValue archive object %@ for key %@",
|
||||
object,key];
|
||||
|
||||
};
|
||||
|
||||
NSDebugMLLog(@"gsdb", @"_propertyList=%@",_propertyList);
|
||||
|
||||
EOFLOGObjectFnStopOrCond(@"EOKeyValueArchiver");
|
||||
}
|
||||
|
||||
/** Returns receiver's delegate **/
|
||||
- (id) delegate
|
||||
{
|
||||
return _delegate;
|
||||
}
|
||||
|
||||
/** Set receiver's delegate **/
|
||||
- (void) setDelegate: (id)delegate
|
||||
{
|
||||
EOFLOGObjectFnStartOrCond(@"EOKeyValueArchiver");
|
||||
|
||||
_delegate=delegate;
|
||||
|
||||
EOFLOGObjectFnStopOrCond(@"EOKeyValueArchiver");
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -197,10 +490,14 @@ RCS_ID("$Id$")
|
|||
|
||||
@implementation NSObject (EOKeyValueArchiverDelegation)
|
||||
|
||||
/** Returns an object to be used as reference for 'archiver'
|
||||
to archive 'object'.
|
||||
Should be overriden by EOKeyValueArchiver's delegates
|
||||
**/
|
||||
- (id)archiver: (EOKeyValueArchiver *)archiver
|
||||
referenceToEncodeForObject: (id)object
|
||||
{
|
||||
[self notImplemented: _cmd]; //TODOFN
|
||||
[self subclassResponsibility:_cmd];
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
@ -209,6 +506,7 @@ referenceToEncodeForObject: (id)object
|
|||
|
||||
@implementation EOKeyValueUnarchiver
|
||||
|
||||
/** Inits unarchiver with propertyList 'dictionary' **/
|
||||
- (id) initWithDictionary: (NSDictionary*)dictionary
|
||||
{
|
||||
if ((self = [super init]))
|
||||
|
@ -222,6 +520,8 @@ referenceToEncodeForObject: (id)object
|
|||
return self;
|
||||
}
|
||||
|
||||
/** Finalize unarchiving by calling finishInitializationWithKeyValueUnarchiver:
|
||||
on all unarchived objects **/
|
||||
- (void) finishInitializationOfObjects
|
||||
{
|
||||
int i;
|
||||
|
@ -252,6 +552,8 @@ referenceToEncodeForObject: (id)object
|
|||
[super dealloc];
|
||||
}
|
||||
|
||||
/** Finalize unarchiving by calling awakeFromKeyValueUnarchiver:
|
||||
on all unarchived objects **/
|
||||
- (void) awakeObjects
|
||||
{
|
||||
int i;
|
||||
|
@ -275,6 +577,8 @@ referenceToEncodeForObject: (id)object
|
|||
}
|
||||
}
|
||||
|
||||
/** ensure 'object' is awake
|
||||
(has received -awakeFromKeyValueUnarchiver: message) **/
|
||||
- (void) ensureObjectAwake: (id)object
|
||||
{
|
||||
if (object)
|
||||
|
@ -288,28 +592,35 @@ referenceToEncodeForObject: (id)object
|
|||
}
|
||||
}
|
||||
|
||||
/** Returns unarchived integer which was archived as 'key'.
|
||||
0 if no object is found **/
|
||||
- (int) decodeIntForKey: (NSString*)key
|
||||
{
|
||||
id object;
|
||||
id object = nil;
|
||||
|
||||
NSDebugMLLog(@"gsdb", @"decodeIntForKey:%@", key);
|
||||
|
||||
object = [_propertyList objectForKey: key];
|
||||
|
||||
return [object intValue];
|
||||
return (object ? [object intValue] : 0);
|
||||
}
|
||||
|
||||
/** Returns unarchived boolean which was archived as 'key'.
|
||||
NO if no object is found **/
|
||||
- (BOOL) decodeBoolForKey: (NSString*)key
|
||||
{
|
||||
id object;
|
||||
id object=nil;
|
||||
|
||||
NSDebugMLLog(@"gsdb", @"decodeBoolForKey:%@", key);
|
||||
|
||||
object = [_propertyList objectForKey: key];
|
||||
|
||||
return [[_propertyList objectForKey: key] boolValue];
|
||||
return (object ? [[_propertyList objectForKey: key] boolValue] : NO);
|
||||
}
|
||||
|
||||
/** Returns unarchived object for the reference archived as 'key'.
|
||||
The receiver gets the object for reference by calling
|
||||
its delegate method -archiver:objectForReference: **/
|
||||
- (id) decodeObjectReferenceForKey: (NSString*)key
|
||||
{
|
||||
id objectReference = nil;
|
||||
|
@ -328,6 +639,9 @@ referenceToEncodeForObject: (id)object
|
|||
return objectReference;
|
||||
}
|
||||
|
||||
/** Returns unarchived object for key.
|
||||
The object should be a NSString, NSData, NSArray or NSDictionary or its
|
||||
class instances should implements -initWithKeyValueUnarchiver: **/
|
||||
- (id) decodeObjectForKey: (NSString*)key
|
||||
{
|
||||
id propListObject;
|
||||
|
@ -348,6 +662,7 @@ referenceToEncodeForObject: (id)object
|
|||
return obj;
|
||||
}
|
||||
|
||||
/** Returns YES if there's a value for key 'key' **/
|
||||
- (BOOL) isThereValueForKey: (NSString *)key
|
||||
{
|
||||
return ([_propertyList objectForKey: key] != nil);
|
||||
|
@ -359,7 +674,7 @@ referenceToEncodeForObject: (id)object
|
|||
|
||||
NSDebugMLLog(@"gsdb", @"obj:%@", obj);
|
||||
|
||||
if ([obj isKindOfClass: [NSDictionary class]])
|
||||
if ([obj isKindOfClass: GDL2_NSDictionaryClass])
|
||||
{
|
||||
NSString *className = [obj objectForKey: @"class"];
|
||||
|
||||
|
@ -374,7 +689,7 @@ referenceToEncodeForObject: (id)object
|
|||
NSDebugMLLog(@"gsdb", @"ERROR: No retVal for Obj:%@", obj);
|
||||
}
|
||||
}
|
||||
else if ([obj isKindOfClass: [NSArray class]])
|
||||
else if ([obj isKindOfClass: GDL2_NSArrayClass])
|
||||
retVal = [self _objectsForPropertyList: obj];
|
||||
else
|
||||
retVal=obj;
|
||||
|
@ -416,94 +731,6 @@ referenceToEncodeForObject: (id)object
|
|||
return dict;
|
||||
}
|
||||
|
||||
/*
|
||||
{
|
||||
batchSize = {AutoInitialized = 1; TypeName = Object; };
|
||||
checkOutLength = {AutoInitialized = 1; TypeName = Object; };
|
||||
cost = {AutoInitialized = 1; TypeName = Object; };
|
||||
currentItem = {TypeName = Object; };
|
||||
dateAcquired = {AutoInitialized = 1; TypeName = Object; };
|
||||
discInsert = {TypeName = Object; };
|
||||
errorString = {AutoInitialized = 1; TypeName = Object; };
|
||||
media = {AutoInitialized = 1; TypeName = Object; };
|
||||
movieMedia = {TypeName = MovieMedia; };
|
||||
movieMediaDataSource = {TypeName = Object; };
|
||||
moviemedias = {
|
||||
AutoInitialized = 1;
|
||||
TypeName = MovieMedias;
|
||||
initialValue = {
|
||||
class = WODisplayGroup;
|
||||
dataSource = {
|
||||
class = EODatabaseDataSource;
|
||||
editingContext = session.defaultEditingContext;
|
||||
fetchSpecification = {class = EOFetchSpecification; entityName = MovieMedia; isDeep = YES; };
|
||||
};
|
||||
formatForLikeQualifier = "%@*";
|
||||
numberOfObjectsPerBatch = 10;
|
||||
selectsFirstObjectAfterFetch = YES;
|
||||
};
|
||||
};
|
||||
objectArray = {TypeName = Object; };
|
||||
ordering = {AutoInitialized = 1; TypeName = Object; };
|
||||
orderingsArray = {AutoInitialized = 1; TypeName = Object; };
|
||||
rentalType = {AutoInitialized = 1; TypeName = Object; };
|
||||
selectedOrderings = {AutoInitialized = 1; TypeName = Object; };
|
||||
tapeInsert = {TypeName = Object; };
|
||||
yes = {TypeName = Object; };
|
||||
}
|
||||
|
||||
_findTypeForPropertyListDecoding:{TypeName = Object; }
|
||||
|
||||
|
||||
//3
|
||||
{TypeName = Object; }
|
||||
_findTypeForPropertyListDecoding:Object
|
||||
(return Object)
|
||||
return {TypeName = Object; } <==
|
||||
|
||||
//6 [1]
|
||||
{TypeName = Object; }
|
||||
|
||||
_findTypeForPropertyListDecoding:{TypeName = MovieMedia; }
|
||||
|
||||
|
||||
|
||||
//A2
|
||||
object=
|
||||
Description: {
|
||||
AutoInitialized = 1;
|
||||
TypeName = MovieMedias;
|
||||
initialValue = {
|
||||
class = WODisplayGroup;
|
||||
dataSource = {
|
||||
class = EODatabaseDataSource;
|
||||
editingContext = session.defaultEditingContext;
|
||||
fetchSpecification = {class = EOFetchSpecification; entityName = MovieMedia; isDeep = YES; };
|
||||
};
|
||||
formatForLikeQualifier = "%@*";
|
||||
numberOfObjectsPerBatch = 10;
|
||||
selectsFirstObjectAfterFetch = YES;
|
||||
};
|
||||
}
|
||||
|
||||
_findTypeForPropertyListDecoding:object=
|
||||
Description: 1
|
||||
_findTypeForPropertyListDecoding
|
||||
Description: MovieMedias
|
||||
_findTypeForPropertyListDecoding:object=
|
||||
Description: {
|
||||
class = WODisplayGroup;
|
||||
dataSource = {
|
||||
class = EODatabaseDataSource;
|
||||
editingContext = session.defaultEditingContext;
|
||||
fetchSpecification = {class = EOFetchSpecification; entityName = MovieMedia; isDeep = YES; };
|
||||
};
|
||||
formatForLikeQualifier = "%@*";
|
||||
numberOfObjectsPerBatch = 10;
|
||||
selectsFirstObjectAfterFetch = YES;
|
||||
}
|
||||
*/
|
||||
|
||||
- (id) _objectsForPropertyList: (NSArray*)propList
|
||||
{
|
||||
NSMutableArray *newObjects = [NSMutableArray array];
|
||||
|
@ -585,50 +812,21 @@ _findTypeForPropertyListDecoding:object=
|
|||
|
||||
return object;
|
||||
}
|
||||
/*
|
||||
//EOFetchSpecification
|
||||
|
||||
prop{
|
||||
class = WODisplayGroup;
|
||||
dataSource = {
|
||||
class = EODatabaseDataSource;
|
||||
editingContext = session.defaultEditingContext;
|
||||
fetchSpecification = {class = EOFetchSpecification; entityName = MovieMedia; isDeep = YES; };
|
||||
};
|
||||
formatForLikeQualifier = "%@*";
|
||||
numberOfObjectsPerBatch = 10;
|
||||
selectsFirstObjectAfterFetch = YES;
|
||||
}]
|
||||
|
||||
|
||||
|
||||
|
||||
object=
|
||||
Description: {
|
||||
class = WODisplayGroup;
|
||||
dataSource = {
|
||||
class = EODatabaseDataSource;
|
||||
editingContext = session.defaultEditingContext;
|
||||
fetchSpecification = {class = EOFetchSpecification; entityName = MovieMedia; isDeep = YES; };
|
||||
};
|
||||
formatForLikeQualifier = "%@*";
|
||||
numberOfObjectsPerBatch = 10;
|
||||
selectsFirstObjectAfterFetch = YES;
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/** Returns the parent object for the currently unarchiving object.
|
||||
**/
|
||||
- (id) parent
|
||||
{
|
||||
return _parent;
|
||||
}
|
||||
|
||||
/** Returns receiver's delegate **/
|
||||
- (id) delegate
|
||||
{
|
||||
return _delegate;
|
||||
}
|
||||
|
||||
/** Set the receiver's delegate **/
|
||||
- (void) setDelegate:(id)delegate
|
||||
{
|
||||
_delegate=delegate;
|
||||
|
@ -639,10 +837,13 @@ _findTypeForPropertyListDecoding:object=
|
|||
|
||||
@implementation NSObject (EOKeyValueUnarchiverDelegation)
|
||||
|
||||
/** Returns an object for archived 'reference'.
|
||||
Should be overriden by EOKeyValueUnarchiver's delegates
|
||||
**/
|
||||
- (id)unarchiver: (EOKeyValueUnarchiver*)archiver
|
||||
objectForReference: (id)keyPath
|
||||
objectForReference: (id)reference
|
||||
{
|
||||
[self notImplemented: _cmd]; //TODOFN
|
||||
[self subclassResponsibility:_cmd];
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,9 +36,10 @@
|
|||
#endif
|
||||
|
||||
#include <EOControl/EONull.h>
|
||||
#include <EOControl/EOKeyValueArchiver.h>
|
||||
|
||||
|
||||
@interface EOSortOrdering : NSObject <NSCoding, NSCopying>
|
||||
@interface EOSortOrdering : NSObject <NSCoding, NSCopying, EOKeyValueArchiving>
|
||||
{
|
||||
SEL _selector;
|
||||
NSString *_key;
|
||||
|
|
Loading…
Reference in a new issue