]> err.no Git - sope/blob - sope-appserver/NGObjWeb/WOChildComponentReference.m
removed bogus line
[sope] / sope-appserver / NGObjWeb / WOChildComponentReference.m
1 /*
2   Copyright (C) 2000-2003 SKYRIX Software AG
3
4   This file is part of OGo
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21 // $Id: WOChildComponentReference.m 1 2004-08-20 10:08:27Z znek $
22
23 #include "WOChildComponentReference.h"
24 #include "WOComponent+private.h"
25 #include "WOContext+private.h"
26 #include <NGObjWeb/WOSession.h>
27 #include <NGObjWeb/WOResponse.h>
28 #include "common.h"
29
30 @interface WOContext(ComponentStackCount)
31 - (unsigned)componentStackCount;
32 @end
33
34 @implementation WOChildComponentReference
35
36 static int profileComponents = -1;
37 static Class NSDateClass = Nil;
38
39 + (int)version {
40   return 2;
41 }
42 + (void)initialize {
43   NSAssert2([super version] == 2,
44             @"invalid superclass (%@) version %i !",
45             NSStringFromClass([self superclass]), [super version]);
46
47   if (profileComponents == -1) {
48     profileComponents = [[[NSUserDefaults standardUserDefaults]
49                                           objectForKey:@"WOProfileComponents"]
50                                           boolValue] ? 1 : 0;
51   }
52   if (NSDateClass == Nil)
53     NSDateClass = [NSDate class];
54 }
55
56 - (id)initWithName:(NSString *)_name
57   associations:(NSDictionary *)_associations
58   template:(WOElement *)_template
59 {
60   self = [super initWithName:_name associations:nil template:_template];
61   if (self) {
62     self->childName = [_name copyWithZone:[self zone]];
63     self->template  = RETAIN(_template);
64   }
65   return self;
66 }
67
68 #if !LIB_FOUNDATION_BOEHM_GC
69 - (void)dealloc {
70   RELEASE(self->childName);
71   RELEASE(self->template);
72   [super dealloc];
73 }
74 #endif
75
76 /* accessors */
77
78 - (NSString *)childName {
79   return self->childName;
80 }
81
82 - (WOElement *)template {
83   return self->template;
84 }
85
86 /* responder */
87
88 - (void)takeValuesFromRequest:(WORequest *)_request
89   inContext:(WOContext *)_ctx
90 {
91   WOComponent *parent, *child;
92   NSTimeInterval st = 0.0;
93   
94   if ((parent = [_ctx component]) == nil) {
95     [self warnWithFormat:
96             @"%s: did not find parent component of child %@",
97             __PRETTY_FUNCTION__, self->childName];
98     return;
99   }
100   if ((child = [parent childComponentWithName:self->childName]) == nil) {
101     [self warnWithFormat:
102             @"did not find child component %@ of parent %@",
103             self->childName, [parent name]];
104     return;
105   }
106   
107   if (profileComponents)
108     st = [[NSDateClass date] timeIntervalSince1970];
109
110   WOContext_enterComponent(_ctx, child, self->template);
111   [child takeValuesFromRequest:_request inContext:_ctx];
112   WOContext_leaveComponent(_ctx, child);
113   
114   if (profileComponents) {
115     NSTimeInterval diff;
116     int i;
117     diff = [[NSDateClass date] timeIntervalSince1970] - st;
118     for (i = [_ctx componentStackCount]; i >= 0; i--)
119       printf("  ");
120     printf("[%s %s]: %0.3fs\n",
121            [[child name] cString], sel_get_name(_cmd), diff);
122   }
123 }
124
125 - (id)invokeActionForRequest:(WORequest *)_request inContext:(WOContext *)_ctx {
126   WOComponent    *parent, *child;
127   id             result = nil;
128   NSTimeInterval st = 0.0;
129
130   if ((parent = [_ctx component]) == nil) {
131     [[_ctx session]
132            warnWithFormat:@"did not find parent component of child %@",
133              self->childName];
134     return nil;
135   }
136   if ((child = [parent childComponentWithName:self->childName]) == nil) {
137     [[_ctx session]
138            warnWithFormat:
139              @"did not find child component %@ of parent %@",
140              self->childName, [parent name]];
141     return nil;
142   }
143   
144   if (profileComponents)
145     st = [[NSDateClass date] timeIntervalSince1970];
146   
147   WOContext_enterComponent(_ctx, child, self->template);
148   result = [child invokeActionForRequest:_request inContext:_ctx];
149   WOContext_leaveComponent(_ctx, child);
150
151   if (profileComponents) {
152     NSTimeInterval diff;
153     int i;
154     diff = [[NSDateClass date] timeIntervalSince1970] - st;
155     for (i = [_ctx componentStackCount]; i >= 0; i--)
156       printf("  ");
157     printf("[%s %s]: %0.3fs\n",
158            [[child name] cString], sel_get_name(_cmd), diff);
159   }
160
161   return result;
162 }
163
164 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
165   WOComponent *parent, *child;
166   NSTimeInterval st = 0.0;
167   
168   if ((parent = [_ctx component]) == nil) {
169     [self warnWithFormat:
170             @"%s: did not find parent component of child %@",
171             __PRETTY_FUNCTION__, self->childName];
172     return;
173   }
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>"];
181     return;
182   }
183   
184   if (profileComponents)
185     st = [[NSDateClass date] timeIntervalSince1970];
186   
187   WOContext_enterComponent(_ctx, child, self->template);
188   [child appendToResponse:_response inContext:_ctx];
189   WOContext_leaveComponent(_ctx, child);
190   
191   if (profileComponents) {
192     NSTimeInterval diff;
193     int i;
194     diff = [[NSDateClass date] timeIntervalSince1970] - st;
195     for (i = [_ctx componentStackCount]; i >= 0; i--)
196       printf("  ");
197     printf("[%s %s]: %0.3fs\n",
198            [[child name] cString], sel_get_name(_cmd), diff);
199   }
200 }
201
202 @end /* WOChildComponentReference */