2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE 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 SOPE 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 SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include "WOChildComponentReference.h"
23 #include "WOComponent+private.h"
24 #include "WOContext+private.h"
25 #include <NGObjWeb/WOSession.h>
26 #include <NGObjWeb/WOResponse.h>
29 @interface WOContext(ComponentStackCount)
30 - (unsigned)componentStackCount;
33 @implementation WOChildComponentReference
35 static int profileComponents = -1;
36 static Class NSDateClass = Nil;
42 NSAssert2([super version] == 2,
43 @"invalid superclass (%@) version %i !",
44 NSStringFromClass([self superclass]), [super version]);
46 if (profileComponents == -1) {
47 profileComponents = [[[NSUserDefaults standardUserDefaults]
48 objectForKey:@"WOProfileComponents"]
51 if (NSDateClass == Nil)
52 NSDateClass = [NSDate class];
55 - (id)initWithName:(NSString *)_name
56 associations:(NSDictionary *)_associations
57 template:(WOElement *)_template
59 self = [super initWithName:_name associations:nil template:_template];
61 self->childName = [_name copyWithZone:[self zone]];
62 self->template = RETAIN(_template);
67 #if !LIB_FOUNDATION_BOEHM_GC
69 RELEASE(self->childName);
70 RELEASE(self->template);
77 - (NSString *)childName {
78 return self->childName;
81 - (WOElement *)template {
82 return self->template;
87 - (void)takeValuesFromRequest:(WORequest *)_request
88 inContext:(WOContext *)_ctx
90 WOComponent *parent, *child;
91 NSTimeInterval st = 0.0;
93 if ((parent = [_ctx component]) == nil) {
95 @"%s: did not find parent component of child %@",
96 __PRETTY_FUNCTION__, self->childName];
99 if ((child = [parent childComponentWithName:self->childName]) == nil) {
100 [self warnWithFormat:
101 @"did not find child component %@ of parent %@",
102 self->childName, [parent name]];
106 if (profileComponents)
107 st = [[NSDateClass date] timeIntervalSince1970];
109 WOContext_enterComponent(_ctx, child, self->template);
110 [child takeValuesFromRequest:_request inContext:_ctx];
111 WOContext_leaveComponent(_ctx, child);
113 if (profileComponents) {
116 diff = [[NSDateClass date] timeIntervalSince1970] - st;
117 for (i = [_ctx componentStackCount]; i >= 0; i--)
119 printf("[%s %s]: %0.3fs\n",
120 [[child name] cString], sel_get_name(_cmd), diff);
124 - (id)invokeActionForRequest:(WORequest *)_request inContext:(WOContext *)_ctx {
125 WOComponent *parent, *child;
127 NSTimeInterval st = 0.0;
129 if ((parent = [_ctx component]) == nil) {
131 warnWithFormat:@"did not find parent component of child %@",
135 if ((child = [parent childComponentWithName:self->childName]) == nil) {
138 @"did not find child component %@ of parent %@",
139 self->childName, [parent name]];
143 if (profileComponents)
144 st = [[NSDateClass date] timeIntervalSince1970];
146 WOContext_enterComponent(_ctx, child, self->template);
147 result = [child invokeActionForRequest:_request inContext:_ctx];
148 WOContext_leaveComponent(_ctx, child);
150 if (profileComponents) {
153 diff = [[NSDateClass date] timeIntervalSince1970] - st;
154 for (i = [_ctx componentStackCount]; i >= 0; i--)
156 printf("[%s %s]: %0.3fs\n",
157 [[child name] cString], sel_get_name(_cmd), diff);
163 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
164 WOComponent *parent, *child;
165 NSTimeInterval st = 0.0;
167 if ((parent = [_ctx component]) == nil) {
168 [self warnWithFormat:
169 @"%s: did not find parent component of child %@",
170 __PRETTY_FUNCTION__, self->childName];
173 if ((child = [parent childComponentWithName:self->childName]) == nil) {
174 [self warnWithFormat:
175 @"did not find child component %@ of parent %@",
176 self->childName, [parent name]];
177 [_response appendContentString:@"<pre>[missing component: "];
178 [_response appendContentHTMLString:self->childName];
179 [_response appendContentString:@"]</pre>"];
183 if (profileComponents)
184 st = [[NSDateClass date] timeIntervalSince1970];
186 WOContext_enterComponent(_ctx, child, self->template);
187 [child appendToResponse:_response inContext:_ctx];
188 WOContext_leaveComponent(_ctx, child);
190 if (profileComponents) {
193 diff = [[NSDateClass date] timeIntervalSince1970] - st;
194 for (i = [_ctx componentStackCount]; i >= 0; i--)
196 printf("[%s %s]: %0.3fs\n",
197 [[child name] cString], sel_get_name(_cmd), diff);
201 @end /* WOChildComponentReference */