]> err.no Git - sope/blob - sope-appserver/NGObjWeb/SoObjects/SoComponent.m
fixed OGo bug #888
[sope] / sope-appserver / NGObjWeb / SoObjects / SoComponent.m
1 /*
2   Copyright (C) 2000-2004 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
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 "SoComponent.h"
24 #include "SoProductResourceManager.h"
25 #include "SoProductRegistry.h"
26 #include "SoProduct.h"
27 #include <NGObjWeb/WOApplication.h>
28 #include "common.h"
29
30 @implementation SoComponent
31
32 + (int)version {
33   return [super version] + 0 /* v2 */;
34 }
35 + (void)initialize {
36   static BOOL didInit = NO;
37   
38   if (didInit) return;
39   NSAssert2([super version] == 2,
40             @"invalid superclass (%@) version %i !",
41             NSStringFromClass([self superclass]), [super version]);
42   didInit = YES;
43 }
44
45 - (void)dealloc {
46   [self->soResourceManager release];
47   [self->soTemplate        release];
48   [self->soBaseURL         release];
49   [super dealloc];
50 }
51
52 /* resource manager */
53
54 - (NSBundle *)componentBundle {
55   return [NSBundle bundleForClass:[self class]];
56 }
57 - (SoProduct *)componentProduct {
58   static SoProductRegistry *reg = nil;
59   SoProduct *product;
60   NSBundle  *bundle;
61   
62   if (reg == nil)
63     reg = [[SoProductRegistry sharedProductRegistry] retain];
64   if (reg == nil)
65     [self logWithFormat:@"ERROR: missing product registry!"];
66   
67   if ((bundle = [self componentBundle]) == nil)
68     [self logWithFormat:@"WARNING: did not find bundle of component !"];
69   
70   if ((product = [reg productForBundle:bundle]) == nil)
71     [self logWithFormat:
72             @"WARNING: did not find product of component (bundle=%@)", bundle];
73   return product;
74 }
75
76 - (void)setResourceManager:(WOResourceManager *)_rm {
77   ASSIGN(self->soResourceManager, _rm);
78 }
79 - (WOResourceManager *)resourceManager {
80   if (self->soResourceManager)
81     return self->soResourceManager;
82   
83   self->soResourceManager = [[[self componentProduct] resourceManager] retain];
84   if (self->soResourceManager)
85     return self->soResourceManager;
86   
87   return [super resourceManager];
88 }
89
90 /* move some extra vars into ivars */
91
92 - (void)setBaseURL:(NSURL *)_url {
93   ASSIGN(self->soBaseURL, _url);
94 }
95 - (NSURL *)baseURL {
96   NSURL *url;
97   
98   if (self->soBaseURL)
99     return self->soBaseURL;
100   
101   url = [(WOApplication *)[self application] baseURL];
102   url = [NSURL URLWithString:@"WebServerResources" relativeToURL:url];
103   self->soBaseURL = [url copy];
104   return self->soBaseURL;
105 }
106
107 - (void)setTemplate:(id)_template {
108   /*
109     WO has private API for this:
110       - (void)setTemplate:(WOElement *)template;
111     As mentioned in the OmniGroup WO mailing list ...
112   */
113   ASSIGN(self->soTemplate, _template);
114 }
115 - (WOElement *)_woComponentTemplate {
116   WOElement *tmpl;
117   
118   if (self->soTemplate)
119     return self->soTemplate;
120   
121   tmpl = [self templateWithName:[self name]];
122   if (tmpl == nil) {
123     [self logWithFormat:
124             @"WARNING: found not template named '%@' for component.",
125             [self name]];
126   }
127   return tmpl;
128 }
129
130 @end /* SoComponent */