/* 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;
_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];
_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];
return result;
}
+/* generate response */
+
- (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
WOComponent *parent;
_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)
/* 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]];
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)
return component;
}
-// responder
+/* handling requests */
- (void)takeValuesFromRequest:(WORequest *)_req inContext:(WOContext *)_ctx {
WOComponent *c;
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;
}
return result;
}
+/* generate response */
+
- (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
WOComponent *c;
NSString *cname;