From 0d5c2c120ddc5434ed85652e52f2880fffb27fef Mon Sep 17 00:00:00 2001 From: helge Date: Tue, 6 Sep 2005 10:02:31 +0000 Subject: [PATCH] minor code cleanups git-svn-id: http://svn.opengroupware.org/SOPE/trunk@1100 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-appserver/NGObjWeb/ChangeLog | 6 ++ .../DynamicElements/WOComponentReference.h | 3 +- .../DynamicElements/WOComponentReference.m | 66 +++++++++++-------- .../DynamicElements/WOSwitchComponent.m | 28 ++++---- sope-appserver/NGObjWeb/Version | 2 +- 5 files changed, 64 insertions(+), 41 deletions(-) diff --git a/sope-appserver/NGObjWeb/ChangeLog b/sope-appserver/NGObjWeb/ChangeLog index 1f8dd546..32c1819e 100644 --- a/sope-appserver/NGObjWeb/ChangeLog +++ b/sope-appserver/NGObjWeb/ChangeLog @@ -1,3 +1,9 @@ +2005-09-06 Helge Hess + + * DynamicElements/WOSwitchComponent.m, + DynamicElements/WOComponentReference.m: minor code cleanups + (v4.5.196) + 2005-09-05 Marcus Mueller * v4.5.195 diff --git a/sope-appserver/NGObjWeb/DynamicElements/WOComponentReference.h b/sope-appserver/NGObjWeb/DynamicElements/WOComponentReference.h index 400a50ca..1a4fb4fb 100644 --- a/sope-appserver/NGObjWeb/DynamicElements/WOComponentReference.h +++ b/sope-appserver/NGObjWeb/DynamicElements/WOComponentReference.h @@ -30,7 +30,6 @@ It's very complicated and uses a lot of black magic ... Associations: - component the component to embed */ @@ -42,7 +41,7 @@ // WODynamicElement: otherTagString @protected WOAssociation *activeComponent; // attribute 'component' - WOComponent *child; // child component + WOComponent *child; // child component THREAD! NSDictionary *bindings; WOElement *template; } diff --git a/sope-appserver/NGObjWeb/DynamicElements/WOComponentReference.m b/sope-appserver/NGObjWeb/DynamicElements/WOComponentReference.m index bf8f5c26..0c9e969e 100644 --- a/sope-appserver/NGObjWeb/DynamicElements/WOComponentReference.m +++ b/sope-appserver/NGObjWeb/DynamicElements/WOComponentReference.m @@ -71,38 +71,49 @@ static Class NSDateClass = Nil; /* accessors */ - (WOComponent *)childComponent { - return self->child; + return self->child; // THREAD } static inline void _updateComponent(WOComponentReference *self, WOContext *_ctx) { - if (self->activeComponent) { - WOComponent *newChild; - - newChild = [self->activeComponent valueInComponent:[_ctx component]]; + /* + Note: this is rather dangerous. We keep a processing state - the 'child' + ivar containing the component - inside the dynamic element. Yet + elements are supposed to be stateless. + + As long as we are single-threaded this should not be a problem, but + keep in mind that this element is NOT reentrant. + */ + // THREAD + WOComponent *newChild; + + if (self->activeComponent == nil) + return; + newChild = [self->activeComponent valueInComponent:[_ctx component]]; #if 0 - if (newChild == nil) { - [[_ctx component] logWithFormat: - @"missing child (got nil) " - @"(element=%@, association=%@, component=%@).", - self, self->activeComponent, - [[_ctx component] name]]; - } + if (newChild == nil) { + [[_ctx component] logWithFormat: + @"missing child (got nil) " + @"(element=%@, association=%@, component=%@).", + self, self->activeComponent, + [[_ctx component] name]]; + } #endif - if (newChild != self->child) { - //NSLog(@"switched component %@ => %@ ...", - // [self->child name], [newChild name]); - ASSIGN(self->child, newChild); - [newChild setParent:[_ctx component]]; - [newChild setBindings:self->bindings]; - } + if (newChild != self->child) { // THREAD +#if 0 + NSLog(@"switched component %@ => %@ ...", + [self->child name], [newChild name]); +#endif + ASSIGN(self->child, newChild); + [newChild setParent:[_ctx component]]; + [newChild setBindings:self->bindings]; } } -// ******************** responder ******************** +/* handling requests */ - (void)takeValuesFromRequest:(WORequest *)_req inContext:(WOContext *)_ctx { WOComponent *parent; @@ -111,7 +122,7 @@ _updateComponent(WOComponentReference *self, WOContext *_ctx) _updateComponent(self, _ctx); - if (self->child) { + if (self->child != nil) { [_ctx enterComponent:self->child content:self->template]; [self->child takeValuesFromRequest:_req inContext:_ctx]; [_ctx leaveComponent:self->child]; @@ -126,7 +137,7 @@ _updateComponent(WOComponentReference *self, WOContext *_ctx) _updateComponent(self, _ctx); - if (self->child) { + if (self->child != nil) { [_ctx enterComponent:self->child content:self->template]; result = [self->child invokeActionForRequest:_req inContext:_ctx]; [_ctx leaveComponent:self->child]; @@ -135,6 +146,8 @@ _updateComponent(WOComponentReference *self, WOContext *_ctx) return result; } +/* generate response */ + - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx { WOComponent *parent; @@ -143,12 +156,12 @@ _updateComponent(WOComponentReference *self, WOContext *_ctx) _updateComponent(self, _ctx); if (self->child == parent) { - [self debugWithFormat:@"WARNING: recursive call of component: %@", parent]; + [self warnWithFormat:@"recursive call of component: %@", parent]; if (coreOnRecursion) abort(); } - if (self->child) { + if (self->child != nil) { NSTimeInterval st = 0.0; if (profileComponents) @@ -186,11 +199,12 @@ _updateComponent(WOComponentReference *self, WOContext *_ctx) /* description */ - (NSString *)description { - NSMutableString *desc = [NSMutableString stringWithCapacity:64]; + NSMutableString *desc; + desc = [NSMutableString stringWithCapacity:64]; [desc appendFormat:@"<%@[0x%08X]:", NSStringFromClass([self class]), self]; - if (self->child) { + if (self->child != nil) { [desc appendFormat:@" child=%@[0x%08X] childName=%@", NSStringFromClass([self->child class]), self->child, [self->child name]]; diff --git a/sope-appserver/NGObjWeb/DynamicElements/WOSwitchComponent.m b/sope-appserver/NGObjWeb/DynamicElements/WOSwitchComponent.m index 8b18d5b6..eaa06f29 100644 --- a/sope-appserver/NGObjWeb/DynamicElements/WOSwitchComponent.m +++ b/sope-appserver/NGObjWeb/DynamicElements/WOSwitchComponent.m @@ -53,24 +53,26 @@ if ((self = [super initWithName:_name associations:_config template:_c])) { self->containsForm = YES; self->componentName = OWGetProperty(_config, @"WOComponentName"); - self->bindings = [_config copyWithZone:[self zone]]; + self->bindings = [_config copy]; [(NSMutableDictionary *)_config removeAllObjects]; - self->template = RETAIN(_c); + self->template = [_c retain]; } return self; } -#if !LIB_FOUNDATION_BOEHM_GC - (void)dealloc { - RELEASE(self->template); - RELEASE(self->componentName); - RELEASE(self->bindings); + [self->template release]; + [self->componentName release]; + [self->bindings release]; [super dealloc]; } -#endif -- (WOComponent *)lookupComponent:(NSString *)cname inContext:(WOContext *)_ctx { +/* component lookup */ + +- (WOComponent *)lookupComponent:(NSString *)cname + inContext:(WOContext *)_ctx +{ WOComponent *component; if (cname == nil) @@ -87,7 +89,7 @@ return component; } -// responder +/* handling requests */ - (void)takeValuesFromRequest:(WORequest *)_req inContext:(WOContext *)_ctx { WOComponent *c; @@ -115,12 +117,12 @@ return nil; cname = [self->componentName stringValueInComponent:[_ctx component]]; - + if (![cname isEqualToString:reqname]) { /* component mismatch */ [[_ctx component] logWithFormat: - @"WOSwitchComponent: component name mismatch (%@ vs %@)," - @"ignoring action.", + @"WOSwitchComponent: component name mismatch" + @" (%@ vs %@), ignoring action.", cname, reqname]; return nil; } @@ -137,6 +139,8 @@ return result; } +/* generate response */ + - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx { WOComponent *c; NSString *cname; diff --git a/sope-appserver/NGObjWeb/Version b/sope-appserver/NGObjWeb/Version index 5d022c4a..32c56ce2 100644 --- a/sope-appserver/NGObjWeb/Version +++ b/sope-appserver/NGObjWeb/Version @@ -1,6 +1,6 @@ # version file -SUBMINOR_VERSION:=195 +SUBMINOR_VERSION:=196 # v4.5.122 requires libNGExtensions v4.5.153 # v4.5.91 requires libNGExtensions v4.5.134 -- 2.39.5