/*
- Copyright (C) 2000-2004 SKYRIX Software AG
+ Copyright (C) 2000-2005 SKYRIX Software AG
- This file is part of OpenGroupware.org.
+ This file is part of SOPE.
- OGo is free software; you can redistribute it and/or modify it under
+ SOPE is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
- OGo is distributed in the hope that it will be useful, but WITHOUT ANY
+ SOPE 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 Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public
- License along with OGo; see the file COPYING. If not, write to the
+ License along with SOPE; see the file COPYING. If not, write to the
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
*/
#include <NGObjWeb/WODynamicElement.h>
#include "WOContext+private.h"
#include "WOElement+private.h"
-#include "WOComponentDefinition.h"
+#include <NGObjWeb/WOComponentDefinition.h>
#include <NGObjWeb/WOResourceManager.h>
#include <NGObjWeb/WOApplication.h>
#include <NGObjWeb/WOResponse.h>
static Class NSDateClass = Nil;
static Class WOComponentClass = Nil;
-static BOOL profElements = NO;
+
+static NGLogger *perfLogger = nil;
+
static BOOL debugOn = NO;
static BOOL debugComponentAwake = NO;
static BOOL debugTemplates = NO;
return [super version] + 0 /* v2 */;
}
+ (void)initialize {
- NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
+ NSUserDefaults *ud;
+ NGLoggerManager *lm;
static BOOL didInit = NO;
+
if (didInit) return;
didInit = YES;
NSAssert2([super version] == 2,
@"invalid superclass (%@) version %i !",
NSStringFromClass([self superclass]), [super version]);
-
- WOComponentClass = [WOComponent class];
- NSDateClass = [NSDate class];
-
- profElements = [ud boolForKey:@"WOProfileElements"];
+
+ ud = [NSUserDefaults standardUserDefaults];
+ lm = [NGLoggerManager defaultLoggerManager];
+
+ WOComponentClass = [WOComponent class];
+ NSDateClass = [NSDate class];
+ perfLogger = [lm loggerForDefaultKey:@"WOProfileElements"];
debugOn = [WOApplication isDebuggingEnabled];
debugComponentAwake = [ud boolForKey:@"WODebugComponentAwake"];
abortOnAwakeComponentInCtxDealloc =
if (self->context)
[self ensureAwakeInContext:self->context];
else {
- [self logWithFormat:
- @"WARNING: no context given to -initWithContext: ..."];
+ [self warnWithFormat:
+ @"no context given to -initWithContext: ..."];
}
}
return self;
withObject:nil];
[self->subcomponents release];
+ [self->wocClientObject release];
[self->wocBindings release];
[self->wocVariables release];
[self->wocName release];
#endif
if (self->componentFlags.isAwake) {
- [self logWithFormat:
- @"WARNING: session will dealloc, "
- @"but component 0x%08X is awake (ctx=%@) !", self, self->context];
+ [self warnWithFormat:
+ @"session will dealloc, but component 0x%08X is awake (ctx=%@) !",
+ self, self->context];
[self _sleepWithContext:self->context];
}
the event?!
*/
[self debugWithFormat:
- @"WARNING: context %@ will dealloc, "
- @"but component is awake in ctx %@!",
+ @"context %@ will dealloc, but component is awake in ctx %@!",
[_notification object], [self->context contextID]];
if (abortOnAwakeComponentInCtxDealloc)
abort();
- (void)sleep {
if (debugOn) {
if (self->componentFlags.isAwake) {
- [self debugWithFormat:
- @"WARNING: component should not be awake if sleep is called !"];
+ [self warnWithFormat:
+ @"component should not be awake if sleep is called !"];
}
if (self->context == nil) {
- [self debugWithFormat:
- @"WARNING: context should not be nil if sleep is called !"];
+ [self warnWithFormat:
+ @"context should not be nil if sleep is called !"];
}
}
#endif
if (debugComponentAwake)
- [self logWithFormat:@"0x%08X ensureAwakeInContext:0x%08X", self, _ctx];
+ [self debugWithFormat:@"0x%08X ensureAwakeInContext:0x%08X", self, _ctx];
if (self->context == nil) [self _setContext:_ctx];
if (self->application == nil) self->application = [_ctx application];
}
- (void)_sleepWithContext:(WOContext *)_ctx {
if (debugComponentAwake)
- [self logWithFormat:@"0x%08X _sleepWithContext:0x%08X", self, _ctx];
+ [self debugWithFormat:@"0x%08X _sleepWithContext:0x%08X", self, _ctx];
if (_ctx != self->context) {
if ((self->context != nil) && (_ctx != nil)) {
/* component is active in different context ... */
- [self debugWithFormat:
- @"WARNING: sleep context mismatch (own=0x%08X vs given=0x%08X)",
+ [self warnWithFormat:
+ @"sleep context mismatch (own=0x%08X vs given=0x%08X)",
self->context, _ctx];
return;
}
NSArray *languages = nil;
#if 0 // the component might not yet be awake !
- languages = [self hasSession]
- ? [[self session] languages]
- : [[[self context] request] browserLanguages];
+ languages = [[self context] resourceLookupLanguages];
#endif
return [[self resourceManager]
- (WOSession *)session {
if (self->session == nil) {
if ((self->session = [[self context] session]) == nil) {
- [self logWithFormat:@"could not get session object from context %@",
+ [self debugWithFormat:@"could not get session object from context %@",
self->context];
}
}
if (self->session == nil)
- [self logWithFormat:@"WARNING: missing session for component!"];
+ [self warnWithFormat:@"missing session for component!"];
return self->session;
}
return self->context;
[self debugWithFormat:
- @"WARNING: missing context in component 0x%08X (component%s)",
+ @"missing context in component 0x%08X (component%s)",
self,
self->componentFlags.isAwake ? " is awake" : " is not awake"];
if (abortOnMissingCtx) {
- [self logWithFormat:@"aborting, because ctx is missing !"];
+ [self errorWithFormat:@"aborting, because ctx is missing !"];
abort();
}
[self _setContext:[self->application context]];
if (self->context == nil)
- [self logWithFormat:@"WARNING: could not determine context object!"];
+ [self warnWithFormat:@"could not determine context object!"];
return self->context;
}
}
- (WOComponent *)pageWithName:(NSString *)_name {
- NSArray *languages = nil;
+ NSArray *languages;
WOResourceManager *rm;
WOComponent *component;
- languages = [self hasSession]
- ? [(WOSession *)[self session] languages]
- : [[[self context] request] browserLanguages];
-
- rm = [self resourceManager];
-
+ languages = [[self context] resourceLookupLanguages];
+ rm = [self resourceManager];
+
/*
Note: this API is somewhat broken since the component expects the
-initWithContext: message for initialization yet we pass no
NSArray *langs;
IS_DEPRECATED;
- langs = [self hasSession]
- ? [(WOSession *)[self session] languages]
- : [[[self context] request] browserLanguages];
+ langs = [[self context] resourceLookupLanguages];
return [[[self application]
resourceManager]
- (void)setName:(NSString *)_name {
if (![_name isNotNull])
- [self logWithFormat:@"WARNING: setting 'nil' name on component!"];
+ [self warnWithFormat:@"setting 'nil' name on component!"];
ASSIGNCOPY(self->wocName, _name);
}
if (_ext) _name = [_name stringByAppendingPathExtension:_ext];
if (cpath == nil) {
- NSLog(@"WARNING: no path set in component %@", [self name]);
+ [self warnWithFormat:@"no path set in component %@", [self name]];
return nil;
}
if (![fm fileExistsAtPath:cpath isDirectory:&isDirectory]) {
- NSLog(@"WARNING: component directory %@ does not exist !", cpath);
+ [self warnWithFormat:@"component directory %@ does not exist !", cpath];
return nil;
}
if (!isDirectory) {
- NSLog(@"WARNING: component path %@ is not a directory !", cpath);
+ [self warnWithFormat:@"component path %@ is not a directory !", cpath];
return nil;
}
WOElement *tmpl;
if ((resourceManager = [self resourceManager]) == nil) {
- [self logWithFormat:@"ERROR(%s): could not determine resource manager !",
- __PRETTY_FUNCTION__];
+ [self errorWithFormat:@"%s: could not determine resource manager !",
+ __PRETTY_FUNCTION__];
return nil;
}
- languages = [self hasSession]
- ? [(WOSession *)[self session] languages]
- : [[[self context] request] browserLanguages];
-
- tmpl = [resourceManager templateWithName:_name languages:languages];
- if (debugTemplates) [self logWithFormat:@"found template: %@", tmpl];
+ languages = [[self context] resourceLookupLanguages];
+ tmpl = [resourceManager templateWithName:_name languages:languages];
+
+ if (debugTemplates) [self debugWithFormat:@"found template: %@", tmpl];
return tmpl;
}
child = [child resolveWithParent:self];
if (child == nil) {
- [self logWithFormat:@"Could not resolve component fault: %@", _name];
+ [self warnWithFormat:@"Could not resolve component fault: %@", _name];
return nil;
}
if (parent == nil) {
parent = [self parent];
- NSLog(@"WARNING: tried to set value of binding '%@' in component '%@' "
- @"without parent component (parent is '%@') !",
- _name, [self name], [parent name]);
+ [self warnWithFormat:@"tried to set value of binding '%@' in component "
+ @"'%@' without parent component (parent is '%@') !",
+ _name, [self name], [parent name]];
}
[[self retain] autorelease];
if (parent == nil) {
parent = [self parent];
- NSLog(@"WARNING: tried to retrieve value of binding '%@' in"
- @" component '%@' without parent component (parent is '%@') !",
- _name, [self name], [parent name]);
+ [self warnWithFormat:@"tried to retrieve value of binding '%@' in"
+ @" component '%@' without parent component (parent is '%@') !",
+ _name, [self name], [parent name]];
}
[[self retain] autorelease];
NSAssert(parent != self, @"parent component equals current component");
if (![parent respondsToSelector:action]) {
- [self logWithFormat:@"parent %@ doesn't respond to %@",
- [parent name], _name];
+ [self debugWithFormat:@"parent %@ doesn't respond to %@",
+ [parent name], _name];
return nil;
}
@"component %@ is not awake !", self);
if (debugOn) {
if (self->context != _ctx) {
- [self debugWithFormat:@"WARNING(%s): component ctx != ctx (%@ vs %@)",
+ [self debugWithFormat:@"%s: component ctx != ctx (%@ vs %@)",
__PRETTY_FUNCTION__, self->context, _ctx];
}
}
return;
}
- if (profElements)
+ if (perfLogger)
st = [[NSDateClass date] timeIntervalSince1970];
if (template->appendResponse) {
else
[template appendToResponse:_response inContext:_ctx];
- if (profElements) {
+ if (perfLogger) {
NSTimeInterval diff;
int i;
diff = [[NSDateClass date] timeIntervalSince1970] - st;
for (i = [_ctx componentStackCount]; i >= 0; i--)
printf(" ");
#endif
- printf("Template %s (comp %s): %0.3fs\n",
- [[_ctx elementID] cString],
- [[self name] cString],
- diff);
+ [perfLogger logWithFormat:@"Template %@ (comp %@): %0.3fs\n",
+ [_ctx elementID],
+ [self name],
+ diff];
}
}
response = [WOResponse responseWithRequest:[ctx request]];
if (ctxID == nil) {
- [self logWithFormat:@"missing ctx-id for context %@", ctx];
+ [self debugWithFormat:@"missing ctx-id for context %@", ctx];
ctxID = @"noctx";
}
if ([self logComponentVariableCreations]) {
/* only if we have a subclass, we can store values in ivars ... */
if (![[self->wocVariables objectForKey:_key] isNotNull]) {
- [self logWithFormat:@"Created component variable (class=%@): '%@'.",
+ [self debugWithFormat:
+ @"Created component variable (class=%@): '%@'.",
NSStringFromClass(self->isa), _key];
}
}
return;
}
- [self logWithFormat:
+ [self debugWithFormat:
@"value %@ could not set via method or KVC "
@"(self responds to %@: %s).",
- _key, _key,
+ _key, _key,
[self respondsToSelector:NSSelectorFromString(_key)] ? "yes" : "no"];
#if 0
return NO;
return value;
#if DEBUG && 0
- [self logWithFormat:@"KVC: accessed the component variable %@", _key];
+ [self debugWithFormat:@"KVC: accessed the component variable %@", _key];
#endif
if ((value = [self objectForKey:_key]))
return value;
if ([self logComponentVariableCreations]) {
/* only if we have a subclass, we can store values in ivars ... */
if (![[self->wocVariables objectForKey:_key] isNotNull]) {
- [self logWithFormat:@"Created component variable (class=%@): '%@'.",
- NSStringFromClass(self->isa), _key];
+ [self debugWithFormat:@"Created component variable (class=%@): '%@'.",
+ NSStringFromClass(self->isa), _key];
}
}
#endif
- (id)valueForUndefinedKey:(NSString *)_key {
// Note: this is not used on libFoundation, insufficient KVC implementation
#if DEBUG && 0
- [self logWithFormat:@"KVC: accessed the component variable %@", _key];
+ [self debugWithFormat:@"KVC: accessed the component variable %@", _key];
#endif
return [self objectForKey:_key];
}
- (void)unableToSetNilForKey:(NSString *)_key {
// TODO: should we call setValue:NSNull forKey?
- [self logWithFormat:@"ERROR: unable to set 'nil' for key: '%@'", _key];
+ [self errorWithFormat:@"unable to set 'nil' for key: '%@'", _key];
}
#endif /* KVC */
- (void)validationFailedWithException:(NSException *)_exception
value:(id)_value keyPath:(NSString *)_keyPath
{
- [self logWithFormat:
- @"WARNING: formatter failed for value %@ (keyPath=%@): %@",
+ [self warnWithFormat:
+ @"formatter failed for value %@ (keyPath=%@): %@",
_value, _keyPath, [_exception reason]];
}