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 "WOComponentFault.h"
23 #include "WOComponent+private.h"
24 #include <NGObjWeb/WOResourceManager.h>
25 #include <NGObjWeb/WOContext.h>
26 #include <NGObjWeb/WOApplication.h>
29 @implementation WOComponentFault
35 - (id)initWithResourceManager:(WOResourceManager *)_rm
36 pageName:(NSString *)_name
37 languages:(NSArray *)_langs
38 bindings:(NSDictionary *)_bindings
40 NSZone *z = [self zone];
41 self->resourceManager = RETAIN(_rm);
42 self->pageName = [_name copyWithZone:z];
43 self->languages = [_langs copyWithZone:z];
44 self->bindings = [_bindings copyWithZone:z];
46 [[NSNotificationCenter defaultCenter]
48 selector:@selector(_contextWillDealloc:)
49 name:@"WOContextWillDeallocate" object:nil];
55 [[NSNotificationCenter defaultCenter] removeObserver:self];
56 RELEASE(self->bindings);
57 RELEASE(self->resourceManager);
58 RELEASE(self->pageName);
59 RELEASE(self->languages);
65 - (void)_contextWillDealloc:(NSNotification *)_notification {
67 NSAssert(_notification, @"missing valid notification arg ...");
71 /* component isn't interested in context anyway ... */
73 if (![[self->ctx contextID] isEqualToString:[_notification object]])
74 /* not the component's context ... */
80 /* cached awake & sleep */
82 - (void)ensureAwakeInContext:(WOContext *)_ctx {
85 - (void)_awakeWithContext:(WOContext *)_ctx {
86 [self ensureAwakeInContext:_ctx];
88 - (void)_sleepWithContext:(WOContext *)_ctx {
94 - (WOComponent *)resolveWithParent:(WOComponent *)_parent {
96 WOResourceManager *rm;
99 [self logWithFormat:@"resolving fault for component %@", self->pageName];
102 if ((rm = self->resourceManager))
104 else if ((rm = [_parent resourceManager]))
107 rm = [[WOApplication application] resourceManager];
109 c = [rm pageWithName:self->pageName languages:self->languages];
110 //[self logWithFormat:@" rm: %@", rm];
111 //[self logWithFormat:@" c: %@", c];
113 [c setBindings:self->bindings];
114 [c setParent:_parent];
115 if (self->ctx) [c _awakeWithContext:self->ctx];
118 [self logWithFormat:@"could not resolve fault for component: %@",
120 [self logWithFormat:@" resource-manager: %@", rm];
121 [self logWithFormat:@" parent: %@", _parent];
127 - (void)setParent:(id)_parent {
129 Not attached to a parent, this is called by WOComponent -dealloc on
130 each child (which can be a fault).
134 - (BOOL)isComponentFault {
140 - (void)encodeWithCoder:(NSCoder *)_coder {
141 [_coder encodeObject:self->pageName];
142 [_coder encodeObject:self->languages];
143 [_coder encodeObject:self->bindings];
145 - (id)initWithCoder:(NSCoder *)_decoder {
146 if ((self = [super init])) {
147 self->pageName = [[_decoder decodeObject] copy];
148 self->languages = [[_decoder decodeObject] retain];
149 self->bindings = [[_decoder decodeObject] retain];
156 - (id)copyWithZone:(NSZone *)_zone {
157 return [self retain];
160 @end /* WOComponentFault */
162 @implementation WOComponent(WOComponentFault)
164 - (BOOL)isComponentFault {
168 @end /* WOComponent(WOComponentFault) */