2 Copyright (C) 2000-2003 SKYRIX Software AG
4 This file is part of OGo
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
21 // $Id: WOChildComponentReference.m 1 2004-08-20 10:08:27Z znek $
23 #include "WOChildComponentReference.h"
24 #include "WOComponent+private.h"
25 #include "WOContext+private.h"
26 #include <NGObjWeb/WOSession.h>
27 #include <NGObjWeb/WOResponse.h>
30 @interface WOContext(ComponentStackCount)
31 - (unsigned)componentStackCount;
34 @implementation WOChildComponentReference
36 static int profileComponents = -1;
37 static Class NSDateClass = Nil;
43 NSAssert2([super version] == 2,
44 @"invalid superclass (%@) version %i !",
45 NSStringFromClass([self superclass]), [super version]);
47 if (profileComponents == -1) {
48 profileComponents = [[[NSUserDefaults standardUserDefaults]
49 objectForKey:@"WOProfileComponents"]
52 if (NSDateClass == Nil)
53 NSDateClass = [NSDate class];
56 - (id)initWithName:(NSString *)_name
57 associations:(NSDictionary *)_associations
58 template:(WOElement *)_template
60 self = [super initWithName:_name associations:nil template:_template];
62 self->childName = [_name copyWithZone:[self zone]];
63 self->template = RETAIN(_template);
68 #if !LIB_FOUNDATION_BOEHM_GC
70 RELEASE(self->childName);
71 RELEASE(self->template);
78 - (NSString *)childName {
79 return self->childName;
82 - (WOElement *)template {
83 return self->template;
88 - (void)takeValuesFromRequest:(WORequest *)_request
89 inContext:(WOContext *)_ctx
91 WOComponent *parent, *child;
92 NSTimeInterval st = 0.0;
94 if ((parent = [_ctx component]) == nil) {
96 @"%s: did not find parent component of child %@",
97 __PRETTY_FUNCTION__, self->childName];
100 if ((child = [parent childComponentWithName:self->childName]) == nil) {
101 [self warnWithFormat:
102 @"did not find child component %@ of parent %@",
103 self->childName, [parent name]];
107 if (profileComponents)
108 st = [[NSDateClass date] timeIntervalSince1970];
110 WOContext_enterComponent(_ctx, child, self->template);
111 [child takeValuesFromRequest:_request inContext:_ctx];
112 WOContext_leaveComponent(_ctx, child);
114 if (profileComponents) {
117 diff = [[NSDateClass date] timeIntervalSince1970] - st;
118 for (i = [_ctx componentStackCount]; i >= 0; i--)
120 printf("[%s %s]: %0.3fs\n",
121 [[child name] cString], sel_get_name(_cmd), diff);
125 - (id)invokeActionForRequest:(WORequest *)_request inContext:(WOContext *)_ctx {
126 WOComponent *parent, *child;
128 NSTimeInterval st = 0.0;
130 if ((parent = [_ctx component]) == nil) {
132 warnWithFormat:@"did not find parent component of child %@",
136 if ((child = [parent childComponentWithName:self->childName]) == nil) {
139 @"did not find child component %@ of parent %@",
140 self->childName, [parent name]];
144 if (profileComponents)
145 st = [[NSDateClass date] timeIntervalSince1970];
147 WOContext_enterComponent(_ctx, child, self->template);
148 result = [child invokeActionForRequest:_request inContext:_ctx];
149 WOContext_leaveComponent(_ctx, child);
151 if (profileComponents) {
154 diff = [[NSDateClass date] timeIntervalSince1970] - st;
155 for (i = [_ctx componentStackCount]; i >= 0; i--)
157 printf("[%s %s]: %0.3fs\n",
158 [[child name] cString], sel_get_name(_cmd), diff);
164 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
165 WOComponent *parent, *child;
166 NSTimeInterval st = 0.0;
168 if ((parent = [_ctx component]) == nil) {
169 [self warnWithFormat:
170 @"%s: did not find parent component of child %@",
171 __PRETTY_FUNCTION__, self->childName];
174 if ((child = [parent childComponentWithName:self->childName]) == nil) {
175 [self warnWithFormat:
176 @"did not find child component %@ of parent %@",
177 self->childName, [parent name]];
178 [_response appendContentString:@"<pre>[missing component: "];
179 [_response appendContentHTMLString:self->childName];
180 [_response appendContentString:@"]</pre>"];
184 if (profileComponents)
185 st = [[NSDateClass date] timeIntervalSince1970];
187 WOContext_enterComponent(_ctx, child, self->template);
188 [child appendToResponse:_response inContext:_ctx];
189 WOContext_leaveComponent(_ctx, child);
191 if (profileComponents) {
194 diff = [[NSDateClass date] timeIntervalSince1970] - st;
195 for (i = [_ctx componentStackCount]; i >= 0; i--)
197 printf("[%s %s]: %0.3fs\n",
198 [[child name] cString], sel_get_name(_cmd), diff);
202 @end /* WOChildComponentReference */