mirror of
https://github.com/gnustep/libs-gsweb.git
synced 2025-02-21 02:41:04 +00:00
* GSWeb.framework/GNUmakefile
* GSWeb.framework/WOKeyValueUnarchiver.m/h add WOKeyValueUnarchiver * GSWeb.framework/GSWComponentDefinition.m add check, reformat * GSWeb.framework/GSWBundle.m add WOKeyValueUnarchiver initializeObject: fromArchive: use WOKeyValueUnarchiver to create objects * GSWeb.framework/GSWComponent.m validateTakeValue:forKeyPath: fix path problem on multiple "." like foo.bar.test add unarchiver: objectForReference: * Examples/WebBookStore1/Main.wo/Main.woo fix class of authorDG WODisplayGroup git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@30647 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
705f8cb1cf
commit
514d24d161
8 changed files with 713 additions and 84 deletions
44
ChangeLog
44
ChangeLog
|
@ -1,3 +1,47 @@
|
|||
2010-06-10 David Wetzel <dave@turbocat.de>
|
||||
* GSWeb.framework/GNUmakefile
|
||||
* GSWeb.framework/WOKeyValueUnarchiver.m/h
|
||||
add WOKeyValueUnarchiver
|
||||
* GSWeb.framework/GSWComponentDefinition.m
|
||||
add check, reformat
|
||||
* GSWeb.framework/GSWBundle.m
|
||||
add WOKeyValueUnarchiver
|
||||
initializeObject: fromArchive:
|
||||
use WOKeyValueUnarchiver to create objects
|
||||
* GSWeb.framework/GSWComponent.m
|
||||
validateTakeValue:forKeyPath:
|
||||
fix path problem on multiple "." like foo.bar.test
|
||||
add unarchiver: objectForReference:
|
||||
* Examples/WebBookStore1/Main.wo/Main.woo
|
||||
fix class of authorDG WODisplayGroup
|
||||
|
||||
2010-06-09 David Wetzel <dave@turbocat.de>
|
||||
* GSWDatabase/WODisplayGroup.m
|
||||
compiles without warning
|
||||
cleanup, removed logs,
|
||||
added exceptions
|
||||
* GSWDatabase/WODisplayGroup.h
|
||||
cleanup includes
|
||||
* Examples/WebBookStore1/Main.m
|
||||
removed create and drop tables.
|
||||
* Examples/WebBookStore1/WebBookStore1_main.m
|
||||
adapt to WO naming
|
||||
* Examples/WebBookStore1/Main.gswc -> Main.wo
|
||||
* Examples/WebBookStore1/GNUmakefile
|
||||
updated
|
||||
* Examples/WebBookStore1/Application.h
|
||||
* Examples/WebBookStore1/DirectAction.h
|
||||
* Examples/WebBookStore1/DirectAction.m
|
||||
* Examples/WebBookStore1/Session.h
|
||||
* Examples/WebBookStore1/Main.h
|
||||
WO naming
|
||||
* Examples/WebBookStore1/README
|
||||
new file
|
||||
* Examples/WebBookStore1/BookStore.eomodeld/index.eomodeld
|
||||
added more sample data to connection dictionary
|
||||
* GNUmakefile
|
||||
add GSWDatabase to main project makefile
|
||||
|
||||
2010-06-09 David Wetzel <dave@turbocat.de>
|
||||
* Examples/hello/Main.m
|
||||
GSW* -> WO*
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
variables = {
|
||||
authorDG = {
|
||||
class = GSWDisplayGroup;
|
||||
class = WODisplayGroup;
|
||||
dataSource = {
|
||||
class = EODatabaseDataSource;
|
||||
editingContext = session.defaultEditingContext;
|
||||
|
|
|
@ -193,7 +193,8 @@ GSWRecording.m \
|
|||
GSWInputStreamData.m \
|
||||
GSWActionURL.m \
|
||||
GSWWorkerThread.m \
|
||||
NSObject+XML.m
|
||||
NSObject+XML.m \
|
||||
WOKeyValueUnarchiver.m
|
||||
|
||||
#For next Version:
|
||||
#GSWAdminAction.m \
|
||||
|
@ -324,7 +325,8 @@ GSWActionURL.h \
|
|||
GSWDefines.h \
|
||||
GSWHTTPIO.h \
|
||||
GSWPrivate.h \
|
||||
NSObject+XML.h
|
||||
NSObject+XML.h \
|
||||
WOKeyValueUnarchiver.h
|
||||
|
||||
#For next Version:
|
||||
#GSWAdminAction.h \
|
||||
|
|
|
@ -1,34 +1,35 @@
|
|||
/** GSWBundle.m - <title>GSWeb: Class GSWBundle</title>
|
||||
|
||||
Copyright (C) 1999-2004 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Manuel Guesdon <mguesdon@orange-concept.com>
|
||||
Date: Mar 1999
|
||||
|
||||
$Revision$
|
||||
$Date$
|
||||
$Id$
|
||||
|
||||
<abstract></abstract>
|
||||
|
||||
This file is part of the GNUstep Web Library.
|
||||
|
||||
<license>
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
</license>
|
||||
**/
|
||||
|
||||
Copyright (C) 1999-2004 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Manuel Guesdon <mguesdon@orange-concept.com>
|
||||
Date: Mar 1999
|
||||
Written by: David Wetzel <dave@turbocat.de>
|
||||
|
||||
$Revision$
|
||||
$Date$
|
||||
$Id$
|
||||
|
||||
<abstract></abstract>
|
||||
|
||||
This file is part of the GNUstep Web Library.
|
||||
|
||||
<license>
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
</license>
|
||||
**/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
|
@ -36,9 +37,7 @@ RCS_ID("$Id$")
|
|||
|
||||
#include "GSWeb.h"
|
||||
#include <GNUstepBase/NSObject+GNUstepBase.h>
|
||||
|
||||
//#ifdef HAVE_GDL2
|
||||
//#include <EOControl/EOKeyValueCoding.h>
|
||||
#include "WOKeyValueUnarchiver.h"
|
||||
|
||||
//====================================================================
|
||||
@interface GSWBundleUnarchiverDelegate : NSObject
|
||||
|
@ -342,44 +341,34 @@ RCS_ID("$Id$")
|
|||
-(void)initializeObject:(id)anObject
|
||||
fromArchive:(NSDictionary*)anArchive
|
||||
{
|
||||
[self lock];
|
||||
NS_DURING
|
||||
SYNCHRONIZED(self) {
|
||||
NSDictionary * variableDefinitions = nil;
|
||||
WOKeyValueUnarchiver * unarchiver;
|
||||
|
||||
unarchiver = [[WOKeyValueUnarchiver alloc] initWithDictionary: anArchive];
|
||||
AUTORELEASE(unarchiver);
|
||||
|
||||
[unarchiver setDelegate:anObject];
|
||||
|
||||
variableDefinitions = (NSDictionary*) [unarchiver decodeObjectForKey:@"variables"];
|
||||
[unarchiver finishInitializationOfObjects];
|
||||
[unarchiver awakeObjects];
|
||||
|
||||
if (variableDefinitions)
|
||||
{
|
||||
/*
|
||||
if (!WOStrictFlag)
|
||||
{
|
||||
NSDictionary* userDictionary=[anArchive objectForKey:@"userDictionary"];
|
||||
NSDictionary* userAssociations=[anArchive objectForKey:@"userAssociations"];
|
||||
NSDictionary* defaultAssociations=[anArchive objectForKey:@"defaultAssociations"];
|
||||
NSString * varName;
|
||||
id varValue;
|
||||
NSEnumerator * keyEnumer = [variableDefinitions keyEnumerator];
|
||||
|
||||
while ((varName = [keyEnumer nextObject])) {
|
||||
varValue = [variableDefinitions objectForKey:varName];
|
||||
|
||||
userAssociations=[userAssociations dictionaryByReplacingStringsWithAssociations];
|
||||
defaultAssociations=[defaultAssociations dictionaryByReplacingStringsWithAssociations];
|
||||
if (userDictionary && [anObject respondsToSelector:@selector(setUserDictionary:)])
|
||||
[anObject setUserDictionary:userDictionary];
|
||||
if (userAssociations && [anObject respondsToSelector:@selector(setUserAssociations:)])
|
||||
[anObject setUserAssociations:userAssociations];
|
||||
if (defaultAssociations && [anObject respondsToSelector:@selector(setDefaultAssociations:)])
|
||||
[anObject setDefaultAssociations:defaultAssociations];
|
||||
}
|
||||
[self notImplemented: _cmd];
|
||||
*/
|
||||
[anObject setValue:varValue
|
||||
forKey:varName];
|
||||
}
|
||||
}
|
||||
NS_HANDLER
|
||||
{
|
||||
NSDebugMLog(@"EXCEPTION:%@ (%@) [%s %d] anObject=%p class=%@ superClass=%@ ",
|
||||
localException,
|
||||
[localException reason],
|
||||
__FILE__,
|
||||
__LINE__,
|
||||
anObject,
|
||||
[anObject class],
|
||||
[anObject superclass]);
|
||||
//TODO
|
||||
[self unlock];
|
||||
[localException raise];
|
||||
}
|
||||
NS_ENDHANDLER;
|
||||
[self unlock];
|
||||
|
||||
} END_SYNCHRONIZED;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
|
|
@ -37,6 +37,7 @@ RCS_ID("$Id$")
|
|||
#include "GSWeb.h"
|
||||
|
||||
#include "GSWPrivate.h"
|
||||
#include "WOKeyValueUnarchiver.h"
|
||||
#include <GNUstepBase/NSObject+GNUstepBase.h>
|
||||
#include <GNUstepBase/NSString+GNUstepBase.h>
|
||||
|
||||
|
@ -1391,6 +1392,7 @@ Call this method before using a component which was cached in a variable.
|
|||
BOOL ok = NO;
|
||||
NSRange dotRange;
|
||||
NSString * errorStr = @"unknown reason";
|
||||
NSString * validatePath = path;
|
||||
|
||||
if (!path) {
|
||||
errorStr = @"keyPath must not be nil";
|
||||
|
@ -1412,20 +1414,15 @@ Call this method before using a component which was cached in a variable.
|
|||
return nil;
|
||||
}
|
||||
|
||||
path = [path substringFromIndex: dotRange.location];
|
||||
|
||||
NSLog(@"paths '%@'", path);
|
||||
|
||||
// 1 is the length of the "."
|
||||
validatePath = [path substringFromIndex: dotRange.location+1];
|
||||
}
|
||||
|
||||
ok = [targetObject validateValue:&value
|
||||
forKeyPath:path
|
||||
forKeyPath:validatePath
|
||||
error:&outError];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (ok) { // value is ok
|
||||
[self setValue:value
|
||||
forKeyPath:path];
|
||||
|
@ -1713,6 +1710,14 @@ Call this method before using a component which was cached in a variable.
|
|||
}
|
||||
}
|
||||
|
||||
- (id)unarchiver: (WOKeyValueUnarchiver*)archiver objectForReference: (id)keyPath
|
||||
{
|
||||
if ([keyPath isKindOfClass:[NSString class]])
|
||||
{
|
||||
return [self valueForKeyPath:keyPath];
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -532,12 +532,15 @@ static GSWContext * TheTemporaryContext;
|
|||
//--------------------------------------------------------------------
|
||||
-(void) finishInitializingComponent:(GSWComponent*)component
|
||||
{
|
||||
//OK
|
||||
NSDictionary* archive=nil;
|
||||
archive=[_bundle archiveNamed:_name];
|
||||
[_bundle initializeObject:component
|
||||
fromArchive:archive];
|
||||
};
|
||||
|
||||
archive = [_bundle archiveNamed:_name];
|
||||
|
||||
if (archive) {
|
||||
[_bundle initializeObject:component
|
||||
fromArchive:archive];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
|
107
GSWeb.framework/WOKeyValueUnarchiver.h
Normal file
107
GSWeb.framework/WOKeyValueUnarchiver.h
Normal file
|
@ -0,0 +1,107 @@
|
|||
/* -*-objc-*-
|
||||
WOKeyValueUnarchiver.h <title>GSWeb: Class WOKeyValueUnarchiver</title>
|
||||
|
||||
Copyright (C) 2010 Free Software Foundation, Inc.
|
||||
|
||||
Written by: David Wetzel <dave@turbocat.de>
|
||||
|
||||
$Revision: 30607 $
|
||||
$Date: 2010-06-07 11:49:24 -0700 (Mo, 07 Jun 2010) $
|
||||
$Id: GSWComponent.m 30607 2010-06-07 18:49:24Z dwetzel $
|
||||
|
||||
<abstract>
|
||||
Basically the same we find in GDL's EOKeyValueUnarchiver.
|
||||
Because we might want applications without database, we
|
||||
need it here too.
|
||||
</abstract>
|
||||
|
||||
This file is part of the GNUstep Web Library.
|
||||
|
||||
<license>
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
</license>
|
||||
**/
|
||||
|
||||
#ifndef __WOKeyValueUnarchiver_h__
|
||||
#define __WOKeyValueUnarchiver_h__
|
||||
|
||||
#ifdef GNUSTEP
|
||||
#include <Foundation/NSObject.h>
|
||||
#include <Foundation/NSHashTable.h>
|
||||
#else
|
||||
#include <Foundation/Foundation.h>
|
||||
#endif
|
||||
|
||||
@interface WOKeyValueUnarchiver : NSObject
|
||||
{
|
||||
NSDictionary *_propertyList;
|
||||
id _parent;
|
||||
id _nextParent;
|
||||
NSMutableArray *_allUnarchivedObjects;
|
||||
id _delegate;
|
||||
NSHashTable *_awakenedObjects;
|
||||
}
|
||||
|
||||
- (id)initWithDictionary: (NSDictionary *)dictionary;
|
||||
|
||||
- (id)decodeObjectForKey: (NSString *)key;
|
||||
|
||||
- (id)decodeObjectReferenceForKey: (NSString *)key;
|
||||
|
||||
- (BOOL)decodeBoolForKey: (NSString *)key;
|
||||
|
||||
- (int)decodeIntForKey: (NSString *)key;
|
||||
|
||||
- (BOOL)isThereValueForKey: (NSString *)key;
|
||||
|
||||
- (void)ensureObjectAwake: (id)object;
|
||||
|
||||
- (void)finishInitializationOfObjects;
|
||||
|
||||
- (void)awakeObjects;
|
||||
|
||||
- (id)parent;
|
||||
|
||||
- (void)setDelegate: (id)delegate;
|
||||
- (id)delegate;
|
||||
|
||||
- (id)_findTypeForPropertyListDecoding: (id)obj;
|
||||
- (id)_dictionaryForPropertyList: (NSDictionary *)propList;
|
||||
- (id)_objectsForPropertyList: (NSArray *)propList;
|
||||
- (id)_objectForPropertyList: (NSDictionary *)propList;
|
||||
|
||||
@end
|
||||
|
||||
@interface NSObject (WOKeyValueUnarchiverDelegation)
|
||||
|
||||
- (id) unarchiver: (WOKeyValueUnarchiver *)archiver objectForReference: (id)keyPath;
|
||||
|
||||
@end
|
||||
|
||||
@protocol WOKeyValueArchiving
|
||||
|
||||
- (id)initWithKeyValueUnarchiver: (WOKeyValueUnarchiver *)unarchiver;
|
||||
|
||||
@end
|
||||
|
||||
@interface NSObject(WOKeyValueArchivingAwakeMethods)
|
||||
|
||||
- (void)finishInitializationWithKeyValueUnarchiver: (WOKeyValueUnarchiver *)unarchiver;
|
||||
|
||||
- (void)awakeFromKeyValueUnarchiver: (WOKeyValueUnarchiver *)unarchiver;
|
||||
|
||||
@end
|
||||
|
||||
#endif // __WOKeyValueUnarchiver_h__
|
479
GSWeb.framework/WOKeyValueUnarchiver.m
Normal file
479
GSWeb.framework/WOKeyValueUnarchiver.m
Normal file
|
@ -0,0 +1,479 @@
|
|||
/* -*-objc-*-
|
||||
WOKeyValueUnarchiver.m
|
||||
|
||||
Copyright (C) 2010 Free Software Foundation, Inc.
|
||||
|
||||
Written by: David Wetzel <dave@turbocat.de>
|
||||
|
||||
$Revision: 30607 $
|
||||
$Date: 2010-06-07 11:49:24 -0700 (Mo, 07 Jun 2010) $
|
||||
$Id: GSWComponent.m 30607 2010-06-07 18:49:24Z dwetzel $
|
||||
|
||||
This file is part of the GNUstep Web Library.
|
||||
|
||||
<license>
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
</license>
|
||||
**/
|
||||
|
||||
#ifdef GNUSTEP
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSDebug.h>
|
||||
#include <Foundation/NSDictionary.h>
|
||||
#include <Foundation/NSEnumerator.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSValue.h>
|
||||
#else
|
||||
#include <Foundation/Foundation.h>
|
||||
#endif
|
||||
|
||||
#ifndef GNUSTEP
|
||||
#include <GNUstepBase/GNUstep.h>
|
||||
#include <GNUstepBase/NSObject+GNUstepBase.h>
|
||||
#include <GNUstepBase/NSDebug+GNUstepBase.h>
|
||||
#endif
|
||||
|
||||
#include "WOKeyValueUnarchiver.h"
|
||||
|
||||
@interface WOKeyValueArchivingContainer : NSObject
|
||||
{
|
||||
id _object;
|
||||
id _parent;
|
||||
NSDictionary * _propertyList;
|
||||
}
|
||||
|
||||
+ (WOKeyValueArchivingContainer*)keyValueArchivingContainer;
|
||||
- (void) setPropertyList: (id)propList;
|
||||
- (id) propertyList;
|
||||
- (void) setParent: (id)parent;
|
||||
- (id) parent;
|
||||
- (void) setObject: (id)object;
|
||||
- (id) object;
|
||||
|
||||
@end
|
||||
|
||||
@implementation WOKeyValueArchivingContainer
|
||||
|
||||
+ (void)initialize
|
||||
{
|
||||
}
|
||||
|
||||
+ (WOKeyValueArchivingContainer *)keyValueArchivingContainer
|
||||
{
|
||||
return [[[self alloc] init] autorelease];
|
||||
}
|
||||
|
||||
- (void) setPropertyList: (id)propList
|
||||
{
|
||||
ASSIGN(_propertyList, propList);
|
||||
}
|
||||
|
||||
- (id) propertyList
|
||||
{
|
||||
return _propertyList;
|
||||
}
|
||||
|
||||
- (void) setParent: (id)parent
|
||||
{
|
||||
_parent = parent;
|
||||
}
|
||||
|
||||
- (id) parent
|
||||
{
|
||||
return _parent;
|
||||
}
|
||||
|
||||
- (void) setObject: (id)object
|
||||
{
|
||||
ASSIGN(_object, object);
|
||||
}
|
||||
|
||||
- (id) object
|
||||
{
|
||||
return _object;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
DESTROY(_object);
|
||||
_parent = nil;
|
||||
DESTROY(_propertyList);
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation WOKeyValueUnarchiver
|
||||
|
||||
/** Inits unarchiver with propertyList 'dictionary' **/
|
||||
- (id) initWithDictionary: (NSDictionary*)dictionary
|
||||
{
|
||||
if ((self = [super init]))
|
||||
{
|
||||
ASSIGN(_propertyList, dictionary);
|
||||
_allUnarchivedObjects = [NSMutableArray array];
|
||||
|
||||
RETAIN(_allUnarchivedObjects);
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
/** Finalize unarchiving by calling finishInitializationWithKeyValueUnarchiver:
|
||||
on all unarchived objects **/
|
||||
- (void) finishInitializationOfObjects
|
||||
{
|
||||
int i;
|
||||
int count = [_allUnarchivedObjects count];
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
WOKeyValueArchivingContainer *container;
|
||||
id object;
|
||||
|
||||
container = [_allUnarchivedObjects objectAtIndex: i];
|
||||
object = [container object];
|
||||
|
||||
|
||||
|
||||
[object finishInitializationWithKeyValueUnarchiver: self];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
DESTROY(_propertyList);
|
||||
DESTROY(_allUnarchivedObjects);
|
||||
|
||||
if (_awakenedObjects)
|
||||
NSFreeHashTable(_awakenedObjects);
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
/** Finalize unarchiving by calling awakeFromKeyValueUnarchiver:
|
||||
on all unarchived objects **/
|
||||
- (void) awakeObjects
|
||||
{
|
||||
int i;
|
||||
int count = [_allUnarchivedObjects count];
|
||||
|
||||
if (!_awakenedObjects)
|
||||
_awakenedObjects = NSCreateHashTable(NSNonRetainedObjectHashCallBacks,
|
||||
count);
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
WOKeyValueArchivingContainer *container;
|
||||
id object;
|
||||
|
||||
|
||||
|
||||
container = [_allUnarchivedObjects objectAtIndex: i];
|
||||
object = [container object];
|
||||
|
||||
[self ensureObjectAwake:object];
|
||||
}
|
||||
}
|
||||
|
||||
/** ensure 'object' is awake
|
||||
(has received -awakeFromKeyValueUnarchiver: message) **/
|
||||
- (void) ensureObjectAwake: (id)object
|
||||
{
|
||||
if (object)
|
||||
{
|
||||
if (!NSHashInsertIfAbsent(_awakenedObjects, object))
|
||||
{
|
||||
|
||||
|
||||
[object awakeFromKeyValueUnarchiver: self];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns unarchived integer which was archived as 'key'.
|
||||
0 if no object is found **/
|
||||
- (int) decodeIntForKey: (NSString*)key
|
||||
{
|
||||
id object = nil;
|
||||
|
||||
|
||||
|
||||
object = [_propertyList objectForKey: key];
|
||||
|
||||
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=nil;
|
||||
|
||||
|
||||
|
||||
object = [_propertyList objectForKey: key];
|
||||
|
||||
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 -unarchiver:objectForReference: **/
|
||||
- (id) decodeObjectReferenceForKey: (NSString*)key
|
||||
{
|
||||
id objectReference = nil;
|
||||
id object;
|
||||
|
||||
|
||||
|
||||
object = [self decodeObjectForKey: key];
|
||||
|
||||
if (object)
|
||||
{
|
||||
objectReference = [_delegate unarchiver: self
|
||||
objectForReference: 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;
|
||||
id obj = nil;
|
||||
|
||||
|
||||
|
||||
propListObject = [_propertyList objectForKey: key];
|
||||
|
||||
|
||||
if (propListObject)
|
||||
{
|
||||
obj = [self _findTypeForPropertyListDecoding: propListObject];
|
||||
}
|
||||
|
||||
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
/** Returns YES if there's a value for key 'key' **/
|
||||
- (BOOL) isThereValueForKey: (NSString *)key
|
||||
{
|
||||
return ([_propertyList objectForKey: key] != nil);
|
||||
}
|
||||
|
||||
- (id) _findTypeForPropertyListDecoding: (id)obj
|
||||
{
|
||||
id retVal = nil;
|
||||
|
||||
|
||||
|
||||
if ([obj isKindOfClass: [NSDictionary class]])
|
||||
{
|
||||
NSString *className = [obj objectForKey: @"class"];
|
||||
|
||||
if (className)
|
||||
retVal = [self _objectForPropertyList: obj];
|
||||
else
|
||||
retVal = [self _dictionaryForPropertyList: obj];
|
||||
|
||||
if (!retVal)
|
||||
{
|
||||
//TODO
|
||||
|
||||
}
|
||||
}
|
||||
else if ([obj isKindOfClass: [NSArray class]])
|
||||
retVal = [self _objectsForPropertyList: obj];
|
||||
else
|
||||
retVal=obj;
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
- (id) _dictionaryForPropertyList: (NSDictionary*)propList
|
||||
{
|
||||
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
|
||||
NSEnumerator *enumerator = [propList keyEnumerator];
|
||||
id key;
|
||||
|
||||
while ((key = [enumerator nextObject]))
|
||||
{
|
||||
id object;
|
||||
id retObject;
|
||||
|
||||
|
||||
|
||||
object = [propList objectForKey: key];
|
||||
|
||||
|
||||
retObject = [self _findTypeForPropertyListDecoding: object];
|
||||
|
||||
|
||||
if (!retObject)
|
||||
{
|
||||
|
||||
//TODO
|
||||
}
|
||||
else
|
||||
[dict setObject: retObject
|
||||
forKey: key];
|
||||
}
|
||||
|
||||
return dict;
|
||||
}
|
||||
|
||||
- (id) _objectsForPropertyList: (NSArray*)propList
|
||||
{
|
||||
NSMutableArray *newObjects = [NSMutableArray array];
|
||||
id object = nil;
|
||||
NSEnumerator *propListEnum;
|
||||
id propListObject;
|
||||
|
||||
|
||||
|
||||
if (propList && (propListEnum = [propList objectEnumerator]))
|
||||
{
|
||||
while ((propListObject = [propListEnum nextObject]))
|
||||
{
|
||||
object = [self _findTypeForPropertyListDecoding: propListObject];
|
||||
|
||||
if (object)
|
||||
{
|
||||
[newObjects addObject: object];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return newObjects;
|
||||
}
|
||||
|
||||
- (id) _objectForPropertyList: (NSDictionary*)propList
|
||||
{
|
||||
WOKeyValueArchivingContainer *container = nil;
|
||||
NSString *className = nil;
|
||||
Class objectClass = Nil;
|
||||
id object = nil;
|
||||
NSDictionary *oldPropList = AUTORELEASE(_propertyList);
|
||||
|
||||
_propertyList = RETAIN(propList); //Because dealloc may try to release it
|
||||
|
||||
|
||||
|
||||
NS_DURING
|
||||
{
|
||||
className = [propList objectForKey: @"class"];
|
||||
objectClass = NSClassFromString(className);
|
||||
|
||||
NSAssert1(objectClass, @"ERROR: No class named '%@'", className);
|
||||
|
||||
object = [[[objectClass alloc] initWithKeyValueUnarchiver: self]
|
||||
autorelease];
|
||||
container = [WOKeyValueArchivingContainer keyValueArchivingContainer];
|
||||
|
||||
[container setObject: object];
|
||||
[container setParent: nil]; //TODO VERIFY
|
||||
[container setPropertyList: propList];
|
||||
|
||||
[_allUnarchivedObjects addObject: container];
|
||||
}
|
||||
NS_HANDLER
|
||||
{
|
||||
NSDebugMLLog(@"gsdb", @"WOKeyValueUnarchiver",@"EXCEPTION:%@ (%@) [%s %d]",
|
||||
localException,
|
||||
[localException reason],
|
||||
__FILE__,
|
||||
__LINE__);
|
||||
|
||||
//Restaure the original propertyList
|
||||
_propertyList = RETAIN(oldPropList);
|
||||
|
||||
AUTORELEASE(propList);
|
||||
[localException raise];
|
||||
}
|
||||
NS_ENDHANDLER;
|
||||
|
||||
_propertyList = RETAIN(oldPropList);
|
||||
|
||||
AUTORELEASE(propList);
|
||||
|
||||
|
||||
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
/** 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;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation NSObject (WOKeyValueUnarchiverDelegation)
|
||||
|
||||
/**
|
||||
* Returns an object for archived 'reference'.
|
||||
* Implemented by WOKeyValueUnarchiver's delegate.
|
||||
*/
|
||||
- (id)unarchiver: (WOKeyValueUnarchiver*)archiver
|
||||
objectForReference: (id)keyPath
|
||||
{
|
||||
[self subclassResponsibility:_cmd];
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation NSObject(WOKeyValueArchivingAwakeMethods)
|
||||
|
||||
- (void)finishInitializationWithKeyValueUnarchiver: (WOKeyValueUnarchiver *)unarchiver
|
||||
{
|
||||
//Does nothing ?
|
||||
return;
|
||||
}
|
||||
|
||||
- (void)awakeFromKeyValueUnarchiver: (WOKeyValueUnarchiver *)unarchiver
|
||||
{
|
||||
//Does nothing ?
|
||||
return;
|
||||
}
|
||||
|
||||
@end
|
Loading…
Reference in a new issue