]> err.no Git - sope/blob - sope-appserver/NGObjWeb/WOComponentFault.m
improved SOPE security exceptions
[sope] / sope-appserver / NGObjWeb / WOComponentFault.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$
22
23 #include "WOComponentFault.h"
24 #include "WOComponent+private.h"
25 #include <NGObjWeb/WOResourceManager.h>
26 #include <NGObjWeb/WOContext.h>
27 #include <NGObjWeb/WOApplication.h>
28 #include "common.h"
29
30 @implementation WOComponentFault
31
32 + (int)version {
33   return 2;
34 }
35
36 - (id)initWithResourceManager:(WOResourceManager *)_rm
37   pageName:(NSString *)_name
38   languages:(NSArray *)_langs
39   bindings:(NSDictionary *)_bindings
40 {
41   NSZone *z = [self zone];
42   self->resourceManager = RETAIN(_rm);
43   self->pageName        = [_name     copyWithZone:z];
44   self->languages       = [_langs    copyWithZone:z];
45   self->bindings        = [_bindings copyWithZone:z];
46   
47   [[NSNotificationCenter defaultCenter]
48                          addObserver:self
49                          selector:@selector(_contextWillDealloc:)
50                          name:@"WOContextWillDeallocate" object:nil];
51   
52   return self;
53 }
54
55 - (void)dealloc {
56   [[NSNotificationCenter defaultCenter] removeObserver:self];
57   RELEASE(self->bindings);
58   RELEASE(self->resourceManager);
59   RELEASE(self->pageName);
60   RELEASE(self->languages);
61   [super dealloc];
62 }
63
64 /* ctx dealloc */
65
66 - (void)_contextWillDealloc:(NSNotification *)_notification {
67 #if DEBUG
68   NSAssert(_notification, @"missing valid notification arg ...");
69 #endif
70   
71   if (self->ctx == nil)
72     /* component isn't interested in context anyway ... */
73     return;
74   if (![[self->ctx contextID] isEqualToString:[_notification object]])
75     /* not the component's context ... */
76     return;
77   
78   self->ctx = nil;
79 }
80
81 /* cached awake & sleep */
82
83 - (void)ensureAwakeInContext:(WOContext *)_ctx {
84   self->ctx = _ctx;
85 }
86 - (void)_awakeWithContext:(WOContext *)_ctx {
87   [self ensureAwakeInContext:_ctx];
88 }
89 - (void)_sleepWithContext:(WOContext *)_ctx {
90   self->ctx = nil;
91 }
92
93 /* resolve */
94
95 - (WOComponent *)resolveWithParent:(WOComponent *)_parent {
96   WOComponent *c;
97   WOResourceManager *rm;
98   
99 #if DEBUG && 0
100   [self logWithFormat:@"resolving fault for component %@", self->pageName];
101 #endif
102
103   if ((rm = self->resourceManager))
104     ;
105   else if ((rm = [_parent resourceManager]))
106     ;
107   else
108     rm = [[WOApplication application] resourceManager];
109   
110   c = [rm pageWithName:self->pageName languages:self->languages];
111   //[self logWithFormat:@"  rm:   %@", rm];
112   //[self logWithFormat:@"  c:    %@", c];
113   
114   [c setBindings:self->bindings];
115   [c setParent:_parent];
116   if (self->ctx) [c _awakeWithContext:self->ctx];
117   
118   if (c == NULL) {
119     [self logWithFormat:@"could not resolve fault for component: %@",
120             self->pageName];
121     [self logWithFormat:@"  resource-manager: %@", rm];
122     [self logWithFormat:@"  parent:           %@", _parent];
123   }
124   
125   return c;
126 }
127
128 - (void)setParent:(id)_parent {
129   /*
130     Not attached to a parent, this is called by WOComponent -dealloc on
131     each child (which can be a fault).
132   */
133 }
134
135 - (BOOL)isComponentFault {
136   return YES;
137 }
138
139 /* NSCoding */
140
141 - (void)encodeWithCoder:(NSCoder *)_coder {
142   [_coder encodeObject:self->pageName];
143   [_coder encodeObject:self->languages];
144   [_coder encodeObject:self->bindings];
145 }
146 - (id)initWithCoder:(NSCoder *)_decoder {
147   if ((self = [super init])) {
148     self->pageName  = [[_decoder decodeObject] copy];
149     self->languages = [[_decoder decodeObject] retain];
150     self->bindings  = [[_decoder decodeObject] retain];
151   }
152   return self;
153 }
154
155 /* NSCopying */
156
157 - (id)copyWithZone:(NSZone *)_zone {
158   return [self retain];
159 }
160
161 @end /* WOComponentFault */
162
163 @implementation WOComponent(WOComponentFault)
164
165 - (BOOL)isComponentFault {
166   return NO;
167 }
168
169 @end /* WOComponent(WOComponentFault) */