]> err.no Git - sope/commitdiff
fixed decoding of arrays in kv archiver
authorhelge <helge@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Fri, 5 Aug 2005 10:21:11 +0000 (10:21 +0000)
committerhelge <helge@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Fri, 5 Aug 2005 10:21:11 +0000 (10:21 +0000)
added 'selectorName' support in EOSortOrdering kv decoding
added kv archiving to EODetailDataSource

git-svn-id: http://svn.opengroupware.org/SOPE/trunk@974 e4a50df8-12e2-0310-a44c-efbce7f8a7e3

sope-core/EOControl/ChangeLog
sope-core/EOControl/EODetailDataSource.h
sope-core/EOControl/EODetailDataSource.m
sope-core/EOControl/EOKeyValueArchiver.h
sope-core/EOControl/EOKeyValueArchiver.m
sope-core/EOControl/EOSortOrdering.m
sope-core/EOControl/Version

index 8039c15c5af5d2931e01de17b5cc0ed1e6c876e8..f6e8f38103be328d5f11b219410d8fa534ad76c1 100644 (file)
@@ -1,5 +1,18 @@
+2005-08-05  Helge Hess  <helge.hess@opengroupware.org>
+
+       * v4.5.58
+       
+       * EODetailDataSource.m: added EOKeyValueArchiving
+
+       * EOSortOrdering.m: use 'selectorName' instead of 'selector' for
+         kv archiving
+       
+       * EOKeyValueArchiver.m: fixed decoding of arrays
+
 2005-08-04  Helge Hess  <helge.hess@opengroupware.org>
 
+       * EOKeyValueArchiver.m: fixed a bug with decoding references (v4.5.57)
+
        * EOKeyValueArchiver.m: print a warning if a class specified in the
          archive could not be found (v4.5.56)
 
index 9cc939afa6c49fcdeaa89a5d78155340092bb2f8..67e798a783efa6abc9d16eaf969715c7be60aa6c 100644 (file)
 #define __EOControl_EODetailDataSource_H__
 
 #include <EOControl/EODataSource.h>
+#include <EOControl/EOKeyValueArchiver.h>
 
 @class EOClassDescription;
 
-@interface EODetailDataSource : EODataSource
+@interface EODetailDataSource : EODataSource < EOKeyValueArchiving >
 {
   EOClassDescription *masterClassDescription;
   EODataSource       *masterDataSource;
index b5ad8aae7d63676d86af48e3231ac1d0a287c86f..764858cf91753884277a406ee08487bfef4578e4 100644 (file)
   [eo removeObject:_object fromPropertyWithKey:dk];
 }
 
+/* key/value archiving */
+
+- (id)initWithKeyValueUnarchiver:(EOKeyValueUnarchiver *)_unarchiver {
+  /*
+      dataSource = {
+        class                  = EODetailDataSource; 
+        detailKey              = roles; 
+        masterClassDescription = Movie; 
+      }; 
+  */
+  if ((self = [super init])) {
+    NSString *ename;
+    
+    self->detailKey = [[_unarchiver decodeObjectForKey:@"detailKey"] copy];
+    
+    ename = [_unarchiver decodeObjectForKey:@"masterClassDescription"];
+    NSLog(@"TODO(%s): set class description: %@", 
+         __PRETTY_FUNCTION__, ename);
+  }
+  return self;
+}
+- (void)encodeWithKeyValueArchiver:(EOKeyValueArchiver *)_archiver {
+  [_archiver encodeObject:[self detailKey] forKey:@"detailKey"];
+  [_archiver encodeObject:[[self masterClassDescription] entityName]
+            forKey:@"masterClassDescription"];
+}
+
 @end /* EODetailDataSource */
index e451fc9eb8caec418386ad37c3a8cc235529f5bc..a03bbd7779d4aa1fda33d6ca6b1702c1ef176a2f 100644 (file)
@@ -68,6 +68,8 @@
 - (BOOL)decodeBoolForKey:(NSString *)_key;
 - (int)decodeIntForKey:(NSString *)_key;
 
+- (id)decodeObjectAtIndex:(unsigned)_idx;
+
 /* operations */
 
 - (void)ensureObjectAwake:(id)_object;
index f2eabf527bb1b258ec62552b902df1ea29ff4bf2..9b8b2fe5e9ee0eedead3929a9070ab8cf2632fcf 100644 (file)
@@ -112,12 +112,14 @@ static BOOL isPListObject(id _obj) {
 
 @end /* EOKeyValueArchiver */
 
+
 @implementation EOKeyValueUnarchiver
 
 - (id)initWithDictionary:(NSDictionary *)_dict {
   self->plist = [_dict copy];
-  self->unarchivedObjects = [[NSMutableArray alloc] init];
-  self->awakeObjects      = [[NSMutableSet alloc] init]; // should be a hashtable
+  self->unarchivedObjects = [[NSMutableArray alloc] initWithCapacity:16];
+  // should be a hashtable
+  self->awakeObjects = [[NSMutableSet alloc] initWithCapacity:16];
   return self;
 }
 - (id)init {
@@ -182,45 +184,93 @@ static BOOL isPListObject(id _obj) {
 
 /* decoding */
 
+- (id)_decodeCurrentPlist {
+  NSString *className;
+  Class    clazz;
+  id       obj;
+
+  if ([self->plist isKindOfClass:[NSArray class]]) {
+      unsigned count;
+      
+      if ((count = [self->plist count]) == 0)
+       obj = [[self->plist copy] autorelease];
+      else {
+       unsigned i;
+       id *objs;
+       
+       objs = calloc(count + 1, sizeof(id));
+       for (i = 0; i < count; i++)
+         objs[i] = [self decodeObjectAtIndex:i];
+       
+       obj = [NSArray arrayWithObjects:objs count:count];
+       if (objs != NULL) free(objs);
+      }
+      return obj;
+  }
+  
+  if (![self->plist isKindOfClass:[NSDictionary class]])
+    return [[self->plist copy] autorelease];
+  
+  /* handle dictionary */
+  
+  if ((className = [self->plist objectForKey:@"class"]) == nil)
+    return [[self->plist copy] autorelease]; /* treat as plain dictionary */
+  
+  if ((clazz = [self classForName:className]) == nil) {
+    NSLog(@"WARNING(%s): did not find class specified in archive '%@': %@",
+         __PRETTY_FUNCTION__, className, self->plist);
+    return nil;
+  }
+  
+  /* create custom object */
+  
+  obj = [clazz alloc];
+  obj = [obj initWithKeyValueUnarchiver:self];
+    
+  if (obj != nil)
+    [self->unarchivedObjects addObject:obj];
+  else {
+    NSLog(@"WARNING(%s): could not unarchive object %@",
+         __PRETTY_FUNCTION__, self->plist);
+  }
+  if (self->unarchivedObjects != nil)
+    [obj release];
+  else
+    [obj autorelease];
+  
+  return obj;
+}
+
+- (id)decodeObjectAtIndex:(unsigned)_idx {
+  NSDictionary *lastParent;
+  id obj;
+  
+  /* push */
+  lastParent   = self->parent;
+  self->parent = self->plist;
+  self->plist  = [(NSArray *)self->parent objectAtIndex:_idx];
+  
+  obj = [self _decodeCurrentPlist];
+
+  /* pop */
+  self->plist  = self->parent;
+  self->parent = lastParent;
+  
+  return obj ? obj : [NSNull null];
+}
+
 - (id)decodeObjectForKey:(NSString *)_key {
-  NSString     *className;
   NSDictionary *lastParent;
   id obj;
 
+  /* push */
   lastParent   = self->parent;
   self->parent = self->plist;
   self->plist  = [(NSDictionary *)self->parent objectForKey:_key];
 
-  if (![self->plist isKindOfClass:[NSDictionary class]]) {
-    obj = [[self->plist copy] autorelease];
-  }
-  else if ((className = [self->plist objectForKey:@"class"]) != nil) {
-    Class clazz;
-
-    if ((clazz = [self classForName:className]) != nil) {
-      obj = [clazz alloc];
-      obj = [obj initWithKeyValueUnarchiver:self];
-    
-      if (obj != nil)
-       [self->unarchivedObjects addObject:obj];
-      else {
-       NSLog(@"WARNING(%s): could not unarchive object %@",
-             __PRETTY_FUNCTION__, self->plist);
-      }
-      if (self->unarchivedObjects != nil)
-       [obj release];
-      else
-       [obj autorelease];
-    }
-    else {
-      NSLog(@"WARNING(%s): did not find class specified in archive '%@': %@",
-           __PRETTY_FUNCTION__, className, self->plist);
-    }
-  }
-  else {
-    obj = nil;
-  }
+  obj = [self _decodeCurrentPlist];
   
+  /* pop */
   self->plist  = self->parent;
   self->parent = lastParent;
   
@@ -235,7 +285,8 @@ static BOOL isPListObject(id _obj) {
            @selector(unarchiver:objectForReference:)]) {
     obj = [self->delegate unarchiver:self objectForReference:refObj];
     
-    [self->unarchivedObjects addObject:obj];
+    if (obj != nil) 
+      [self->unarchivedObjects addObject:obj];
   }
   else {
     /* if delegate does not dereference, pass back the reference object */
@@ -266,7 +317,7 @@ static BOOL isPListObject(id _obj) {
   id obj;
 
   e = [self->unarchivedObjects objectEnumerator];
-  while ((obj = [e nextObject]))
+  while ((obj = [e nextObject]) != nil)
     [self ensureObjectAwake:obj];
 }
 
@@ -275,7 +326,7 @@ static BOOL isPListObject(id _obj) {
   id obj;
 
   e = [self->unarchivedObjects objectEnumerator];
-  while ((obj = [e nextObject])) {
+  while ((obj = [e nextObject]) != nil) {
     if ([obj respondsToSelector:
                @selector(finishInitializationWithKeyValueUnarchiver:)])
       [obj finishInitializationWithKeyValueUnarchiver:self];
index 93d2c01dab8bfc8a70955256f19674b98691d517..3dd7e00cc42d44ccf3542a8f4323ad3b5f22c498 100644 (file)
@@ -121,16 +121,23 @@ EOControl_DECLARE SEL EOCompareCaseInsensitiveDescending =
 
 - (id)initWithKeyValueUnarchiver:(EOKeyValueUnarchiver *)_unarchiver {
   if ((self = [super init]) != nil) {
+    NSString *s;
+    
     self->key = [[_unarchiver decodeObjectForKey:@"key"] copy];
-    self->selector = 
-      NSSelectorFromString([_unarchiver decodeObjectForKey:@"selector"]);
+    
+    if ((s = [_unarchiver decodeObjectForKey:@"selector"]) != nil)
+      self->selector = NSSelectorFromString(s);
+    else if ((s = [_unarchiver decodeObjectForKey:@"selectorName"]) != nil) {
+      if (![s hasSuffix:@":"]) s = [s stringByAppendingString:@":"];
+      self->selector = NSSelectorFromString(s);
+    }
   }
   return self;
 }
 - (void)encodeWithKeyValueArchiver:(EOKeyValueArchiver *)_archiver {
   [_archiver encodeObject:[self key] forKey:@"key"];
   [_archiver encodeObject:NSStringFromSelector([self selector])
-             forKey:@"selector"];
+             forKey:@"selectorName"];
 }
 
 /* description */
index 0d71e7663cdd42daf5b48bcffc44392a12b595b6..31494853fc6418695cfabaf78b7d27ee87f6e96d 100644 (file)
@@ -1,3 +1,3 @@
 # version file
 
-SUBMINOR_VERSION:=56
+SUBMINOR_VERSION:=58