~ubuntu-branches/ubuntu/edgy/sope/edgy

« back to all changes in this revision

Viewing changes to sope-appserver/NGObjWeb/SoObjects/SoComponent.m

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Ley
  • Date: 2005-08-19 16:53:31 UTC
  • Revision ID: james.westby@ubuntu.com-20050819165331-hs683wz1osm708pw
Tags: upstream-4.4rc.2
ImportĀ upstreamĀ versionĀ 4.4rc.2

Show diffs side-by-side

added added

removed removed

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