mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-04-04 21:08:51 +00:00
Monotone-Parent: 98896091d472e0ee7990f69f32f5981f5d1dc546
Monotone-Revision: 925d096d1e0f9b05775333d6111c325f69a17ac0 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2008-01-16T18:47:20 Monotone-Branch: ca.inverse.sogo
This commit is contained in:
54
SoObjects/SOGo/SOGoCache.h
Normal file
54
SoObjects/SOGo/SOGoCache.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/* SOGoCache.h - this file is part of SOGo
|
||||
*
|
||||
* Copyright (C) 2008 Inverse groupe conseil
|
||||
*
|
||||
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This file 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef SOGOCACHE_H
|
||||
#define SOGOCACHE_H
|
||||
|
||||
#import <Foundation/NSObject.h>
|
||||
|
||||
@class NSMutableDictionary;
|
||||
@class NSString;
|
||||
|
||||
@class SOGoObject;
|
||||
@class SOGoUser;
|
||||
|
||||
@interface SOGoCache : NSObject
|
||||
{
|
||||
NSMutableDictionary *cache;
|
||||
NSMutableDictionary *users;
|
||||
}
|
||||
|
||||
+ (SOGoCache *) sharedCache;
|
||||
+ (void) killCache;
|
||||
|
||||
- (void) registerObject: (id) object
|
||||
withName: (NSString *) name
|
||||
inContainer: (SOGoObject *) container;
|
||||
- (id) objectNamed: (NSString *) name
|
||||
inContainer: (SOGoObject *) container;
|
||||
|
||||
- (void) registerUser: (SOGoUser *) user;
|
||||
- (id) userNamed: (NSString *) name;
|
||||
|
||||
@end
|
||||
|
||||
#endif /* SOGOCACHE_H */
|
||||
128
SoObjects/SOGo/SOGoCache.m
Normal file
128
SoObjects/SOGo/SOGoCache.m
Normal file
@@ -0,0 +1,128 @@
|
||||
/* SOGoCache.m - this file is part of SOGo
|
||||
*
|
||||
* Copyright (C) 2008 Inverse groupe conseil
|
||||
*
|
||||
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This file 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#import <Foundation/NSArray.h>
|
||||
|
||||
#import <NGObjWeb/SoObject.h>
|
||||
|
||||
#import "SOGoUser.h"
|
||||
#import "SOGoCache.h"
|
||||
|
||||
static SOGoCache *sharedCache = nil;
|
||||
|
||||
@implementation SOGoCache
|
||||
|
||||
+ (SOGoCache *) sharedCache
|
||||
{
|
||||
if (!sharedCache)
|
||||
sharedCache = [self new];
|
||||
|
||||
return sharedCache;
|
||||
}
|
||||
|
||||
+ (void) killCache
|
||||
{
|
||||
[sharedCache release];
|
||||
sharedCache = nil;
|
||||
}
|
||||
|
||||
- (id) init
|
||||
{
|
||||
if ((self = [super init]))
|
||||
{
|
||||
cache = [NSMutableDictionary new];
|
||||
users = [NSMutableDictionary new];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[cache release];
|
||||
[users release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSString *) _pathFromObject: (SOGoObject *) container
|
||||
withName: (NSString *) name
|
||||
{
|
||||
NSString *fullPath, *nameInContainer;
|
||||
NSMutableArray *names;
|
||||
id currentObject;
|
||||
|
||||
names = [NSMutableArray new];
|
||||
|
||||
[names addObject: name];
|
||||
currentObject = container;
|
||||
while ((nameInContainer = [currentObject nameInContainer]))
|
||||
{
|
||||
[names addObject: nameInContainer];
|
||||
currentObject = [currentObject container];
|
||||
}
|
||||
|
||||
fullPath = [names componentsJoinedByString: @"/"];
|
||||
[names release];
|
||||
|
||||
return fullPath;
|
||||
}
|
||||
|
||||
- (void) registerObject: (id) object
|
||||
withName: (NSString *) name
|
||||
inContainer: (SOGoObject *) container
|
||||
{
|
||||
NSString *fullPath;
|
||||
|
||||
if (object)
|
||||
{
|
||||
fullPath = [self _pathFromObject: container
|
||||
withName: name];
|
||||
[cache setObject: object forKey: fullPath];
|
||||
}
|
||||
}
|
||||
|
||||
- (id) objectNamed: (NSString *) name
|
||||
inContainer: (SOGoObject *) container
|
||||
{
|
||||
NSString *fullPath;
|
||||
|
||||
fullPath = [self _pathFromObject: container
|
||||
withName: name];
|
||||
|
||||
return [cache objectForKey: fullPath];
|
||||
}
|
||||
|
||||
- (void) registerUser: (SOGoUser *) user
|
||||
{
|
||||
NSLog (@"registerUser: %@", user);
|
||||
|
||||
[users setObject: user forKey: [user login]];
|
||||
}
|
||||
|
||||
- (id) userNamed: (NSString *) name
|
||||
{
|
||||
NSLog (@"userNamed: %@", name);
|
||||
|
||||
return [users objectForKey: name];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user