@implementation OCSFolder
+- (id)initWithPath:(NSString *)_path primaryKey:(id)_folderId
+ folderTypeName:(NSString *)_ftname folderType:(OCSFolderType *)_ftype
+ location:(NSURL *)_loc
+ folderManager:(OCSFolderManager *)_fm
+{
+ if ((self = [super init])) {
+ self->folderManager = [_fm retain];
+ self->folderInfo = [_ftype retain];
+
+ self->folderId = [_folderId copy];
+ self->folderName = [[_path lastPathComponent] copy];
+ self->path = [_path copy];
+ self->location = [_loc retain];
+ self->folderType = [_ftname copy];
+ }
+ return self;
+}
+- (id)init {
+ return [self initWithPath:nil primaryKey:nil
+ folderTypeName:nil folderType:nil
+ location:nil folderManager:nil];
+}
+
- (void)dealloc {
[self->folderManager release];
[self->folderInfo release];
[self->folderId release];
[self->folderName release];
- [self->rootName release];
[self->path release];
[self->location release];
[self->folderType release];
- (NSString *)folderName {
return self->folderName;
}
-- (NSString *)rootName {
- return self->rootName;
-}
- (NSString *)path {
return self->path;
}
- (NSString *)description {
NSMutableString *ms;
-
+ id tmp;
+
ms = [NSMutableString stringWithCapacity:256];
[ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])];
else
[ms appendString:@" no-id"];
- if (self->path) [ms appendFormat:@" path=%@", self->path];
- if (self->folderType) [ms appendFormat:@" type=%@", self->folderType];
- if (self->location) [ms appendFormat:@" location=%@", self->location];
+ if ((tmp = [self path])) [ms appendFormat:@" path=%@", tmp];
+ if ((tmp = [self folderTypeName])) [ms appendFormat:@" type=%@", tmp];
+ if ((tmp = [self location]))
+ [ms appendFormat:@" db=%@", [tmp absoluteString]];
[ms appendString:@">"];
return ms;
#include "OCSFolderManager.h"
#include "OCSChannelManager.h"
+#include "OCSFolderType.h"
+#include "OCSFolder.h"
#include "NSURL+OCS.h"
#include "common.h"
#include <GDLAccess/EOAdaptorChannel.h>
/* checking connection */
+- (OCSChannelManager *)channelManager {
+ return self->channelManager;
+}
+
- (EOAdaptorChannel *)acquireOpenChannel {
EOAdaptorChannel *ch;
- ch = [self->channelManager acquireOpenChannelForURL:
+ ch = [[self channelManager] acquireOpenChannelForURL:
[self folderInfoLocation]];
return ch;
}
- (void)releaseChannel:(EOAdaptorChannel *)_channel {
- [self->channelManager releaseChannel:_channel];
+ [[self channelManager] releaseChannel:_channel];
if (debugOn) [self debugWithFormat:@"released channel: %@", _channel];
}
return rows;
}
+/* row factory */
+
+- (OCSFolder *)folderForRecord:(NSDictionary *)_record {
+ OCSFolder *folder;
+ OCSFolderType *folderType;
+ NSString *folderTypeName, *locationString, *folderName, *path;
+ NSNumber *folderId;
+ NSURL *location;
+
+ if (_record == nil) return nil;
+
+ folderTypeName = [_record objectForKey:@"cFolderType"];
+ if ((folderType = [self folderTypeWithName:folderTypeName]) == nil) {
+ [self logWithFormat:@"ERROR(%s): got no type from folder record: %@",
+ __PRETTY_FUNCTION__, _record];
+ return nil;
+ }
+
+ folderId = [_record objectForKey:@"cFolderId"];
+ folderName = [_record objectForKey:@"cPath"];
+ path = [self pathFromInternalName:folderName];
+
+ locationString = [_record objectForKey:@"cLocation"];
+ location = [locationString isNotNull]
+ ? [NSURL URLWithString:locationString]
+ : nil;
+ if (location == nil) {
+ [self logWithFormat:@"ERROR(%s): missing folder location in record: %@",
+ __PRETTY_FUNCTION__, _record];
+ return nil;
+ }
+
+ folder = [[OCSFolder alloc] initWithPath:path primaryKey:folderId
+ folderTypeName:folderTypeName
+ folderType:folderType
+ location:location folderManager:self];
+ return [folder autorelease];
+}
+
/* path SQL */
- (NSString *)generateSQLWhereForInternalNames:(NSArray *)_names
return nil;
}
- [self logWithFormat:@"record: %@", record];
- return nil;
+ return [self folderForRecord:record];
}
/* folder types */
if ([_name length] == 0)
_name = OCSGenericFolderTypeName;
- return [self->nameToType objectForKey:_name];
+ return [self->nameToType objectForKey:[_name lowercaseString]];
}
/* cache management */
[ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])];
[ms appendFormat:@" url=%@", [self->folderInfoLocation absoluteString]];
- [ms appendFormat:@" channel-manager=0x%08X", self->channelManager];
+ [ms appendFormat:@" channel-manager=0x%08X", [self channelManager]];
[ms appendString:@">"];
return ms;