2002-08-04 18:00:11 +00:00
|
|
|
/** GSWComponentDefinition.m - <title>GSWeb: Class GSWComponentDefinition</title>
|
|
|
|
|
|
|
|
Copyright (C) 1999-2002 Free Software Foundation, Inc.
|
2000-01-22 12:49:49 +00:00
|
|
|
|
2002-08-04 18:00:11 +00:00
|
|
|
Written by: Manuel Guesdon <mguesdon@orange-concept.com>
|
|
|
|
Date: Jan 1999
|
2000-01-22 12:49:49 +00:00
|
|
|
|
2002-08-04 18:00:11 +00:00
|
|
|
$Revision$
|
|
|
|
$Date$
|
2002-11-27 20:25:22 +00:00
|
|
|
$Id$
|
2002-08-04 18:00:11 +00:00
|
|
|
|
2000-01-22 12:49:49 +00:00
|
|
|
This file is part of the GNUstep Web Library.
|
|
|
|
|
2002-08-04 18:00:11 +00:00
|
|
|
<license>
|
2000-01-22 12:49:49 +00:00
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
License along with this library; if not, write to the Free
|
|
|
|
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
2002-08-04 18:00:11 +00:00
|
|
|
</license>
|
|
|
|
**/
|
2000-01-22 12:49:49 +00:00
|
|
|
|
2003-01-22 Manuel Guesdon <mguesdon@orange-concept.com>
* GSWeb.framework/Makefile.postamble:
o use $(LN_S) -f in install-WO-headers
o added $(MKDIRS) $(GNUSTEP_HEADERS)/$(GSWExtensions_wo_HEADER_FILES_INSTALL_DIR);
* GSWExtensionsGSW.framework/Makefile.postamble: use $(LN_S) -f in install-WO-headers
2003-01-20 David Ayers <d.ayers@inode.at>
* Makefile.postamble
o added support for make gswnames=(gsw,wo,all) (corrected
typo)
o reinserted support for $(INSTALL_ROOT_DIR)
* config.h.in
o added HAVE_GDL2
* configure
o added support for --with-gswnames=(gsw,wo,all)
o set LIBWRAP during configure
o added config.mak.in as configurable file
* configure.ac
o (see configure)
* config.mak: removed (replaced by config.mak.in)
* config.mak.in: new file
o added support for make gswnames=(gsw,wo,all)
* gsweb.make.in
o add GSANTLR as auxiliary lib
o add gsweb libs to AUXILIARY_GSW_LIBS
o include correct extensions for GSW/WO-libs
* gsweb_wo.make: new file
* GSWeb/GSWConfig.h
o changed support for GSWEB_WONAMES
o conditionally import file GSWWOCompatiblity
here instead of in GSWeb.h
* GSWeb/GNUMakefile
o added support for make gswnames=(gsw,wo,all)
o ensure each lib gets built with its own object files
o removed deactivated framework extension determination code
o removed reference to unused files:
GSWeb.m, GSWWOCompatibility.m
o added references to new files:
GSWExtenstions.h, GSWExtWOCompatibility.h
o added support to create WO header files
* GSWeb/Makefile.postamble
o changed support to install WO header files according to
make gswnames=(gsw,wo,all)
o remove Makefile.preamble during distclean
* GSWeb/Makefile.preamble.in
o fixed typo
* GSWeb/GSWeb.h
o moved GSW/WO-Name-mapping to GSWWOCompatibility.h
o replaced inclusions of
<GSWeb/file.h> with "file.h"
* GSWeb/GSWeb.m: removed
* GSWeb/GSWWOCompatibility.h
o changed GSWEB_WONAMES handling
o removed hybrid namespace WO subclasses
o moved & reorganized GSW/WO-Name-mapping from GSWeb.h
o inlucluded missing GSW/WO-Name-mappings
* GSWeb/GSWWOCompatibility.m: removed
* GSWeb/*.m
o replaced inclusions of
<GSWeb/file.h> with "file.h"
* GSWeb/GSWApplication.m
o remove special GSW/WO handling of WOApp
* GSWeb/WebObject/WO*: removed
* GSWeb/WebObject/WebObjects
o replaced inclusions of
<GSWeb/file.h> with "file.h"
* GSWExtensions/GNUMakefile
o added support for make gswnames=(gsw,wo,all)
o ensure each lib gets built with its own object files
o removed deactivated framework extension determination code
o added references to new files:
GSWExtenstions.h, GSWExtWOCompatibility.h
o added support to create WO header files
* GSWExtensions/Makefile.preamble
o let gnustep make figure whether to link agains debug libs
o added support for make gswnames=(gsw,wo,all)
* GSWExtensions/Makefile.postamble
o changed support to install WO header files according to
make gswnames=(gsw,wo,all)
* GSWExtensions/*.m
o replaced inclusions of
<GSWeb/GSWeb.h> with "GSWExtWOCompatibility.h"
o replaces inclusions of
<GSWExtensions/file.h> with "file.h"
* GSWExtensions/GSWExtensions.h: new file
* GSWExtensions/WOExtensions.h: new file
* GSWExtensions/GSWExtWOCompatibility.h: new file
* GSWExtensionsGSW/GNUMakefile
o added support for make gswnames=(gsw,wo,all)
o ensure each lib gets built with its own object files
o removed deactivated framework extension determination code
o added references to new file GSWExtGSWWOCompatibility.h
o added support to create WO header files
* GSWExtensionsGSW/Makefile.pramble
o let gnustep make figure whether to link agains debug libs
o added support for make gswnames=(gsw,wo,all)
o removed GSWExtensions from ADDITIONAL_LIB_DIRS
* GSWExtensionsGSW/*.m
o replaced inclusions of
<GSWeb/GSWeb.h> with "GSWExtGSWWOCompatibility.h"
* GSWExtensions/GSWExtGSWWOCompatibility.h: new file
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@15675 72102866-910b-0410-8b05-ffd578937521
2003-01-22 12:24:26 +00:00
|
|
|
#include "GSWeb.h"
|
2010-06-05 21:08:12 +00:00
|
|
|
#include <GNUstepBase/NSObject+GNUstepBase.h>
|
2010-06-22 05:02:29 +00:00
|
|
|
#include <GNUstepBase/GSMime.h>
|
2000-01-22 12:49:49 +00:00
|
|
|
|
|
|
|
//====================================================================
|
2007-04-13 18:32:02 +00:00
|
|
|
|
|
|
|
/* Static variables */
|
|
|
|
|
|
|
|
static NSLock * ComponentConstructorLock;
|
|
|
|
static NSLock * TemplateLock;
|
|
|
|
static GSWContext * TheTemporaryContext;
|
|
|
|
|
2000-01-22 12:49:49 +00:00
|
|
|
@implementation GSWComponentDefinition
|
|
|
|
|
2007-04-13 18:32:02 +00:00
|
|
|
+ (void) initialize
|
|
|
|
{
|
|
|
|
if (self == [GSWComponentDefinition class]) {
|
|
|
|
ComponentConstructorLock = [[NSLock alloc] init];
|
|
|
|
TemplateLock = [[NSLock alloc] init];
|
|
|
|
TheTemporaryContext = nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// that Method is used INTERNAL.
|
|
|
|
+ (GSWContext *) TheTemporaryContext
|
|
|
|
{
|
|
|
|
return TheTemporaryContext;
|
|
|
|
}
|
|
|
|
|
2000-01-22 12:49:49 +00:00
|
|
|
//--------------------------------------------------------------------
|
2007-04-13 18:32:02 +00:00
|
|
|
|
2008-08-20 20:32:10 +00:00
|
|
|
// CHECKME: missing Languages?
|
2007-04-13 18:32:02 +00:00
|
|
|
// we my have a different name and class?
|
|
|
|
// aName StartPage
|
|
|
|
// aPath /Users/dave/projects/new/PBXBilling/trunk/PBX.gswa/Resources/StartPage.wo
|
|
|
|
// baseURL /WebObjects/PBX.gswa/Resources/StartPage.wo
|
|
|
|
|
2002-08-04 18:00:11 +00:00
|
|
|
-(id)initWithName:(NSString*)aName
|
|
|
|
path:(NSString*)aPath
|
|
|
|
baseURL:(NSString*)baseURL
|
|
|
|
frameworkName:(NSString*)aFrameworkName
|
2000-01-22 12:49:49 +00:00
|
|
|
{
|
2007-04-13 18:32:02 +00:00
|
|
|
NSString * myBasePath = nil;
|
|
|
|
NSFileManager * defaultFileManager = nil;
|
|
|
|
|
|
|
|
[super init];
|
|
|
|
ASSIGN(_name, [aName stringByDeletingPathExtension]); // does it ever happen that
|
|
|
|
ASSIGN(_className, aName); // those are different? dw.
|
|
|
|
_componentClass = NSClassFromString(_className);
|
|
|
|
ASSIGN(_path, aPath);
|
|
|
|
ASSIGN(_url, baseURL);
|
|
|
|
ASSIGN(_frameworkName, aFrameworkName);
|
|
|
|
DESTROY(_language);
|
2010-06-22 05:02:29 +00:00
|
|
|
DESTROY(_wooReadDate);
|
|
|
|
DESTROY(_htmlReadDate);
|
2007-04-13 18:32:02 +00:00
|
|
|
_hasBeenAccessed = NO;
|
|
|
|
_hasContextConstructor = NO;
|
|
|
|
_isStateless = NO;
|
|
|
|
DESTROY(_instancePool);
|
|
|
|
_instancePool = [NSMutableArray new];
|
|
|
|
_lockInstancePool = [GSWApp isConcurrentRequestHandlingEnabled];
|
|
|
|
|
|
|
|
if ((_name != nil) && (_frameworkName != nil)) {
|
2010-06-22 05:02:29 +00:00
|
|
|
_componentClass = NSClassFromString(_className);
|
2007-04-13 18:32:02 +00:00
|
|
|
}
|
|
|
|
myBasePath = [aPath stringByAppendingPathComponent: aName];
|
|
|
|
ASSIGN(_htmlPath,[myBasePath stringByAppendingPathExtension:@"html"]);
|
|
|
|
ASSIGN(_wodPath,[myBasePath stringByAppendingPathExtension:GSWComponentDeclarationsSuffix[GSWebNamingConv]]);
|
|
|
|
ASSIGN(_wooPath,[myBasePath stringByAppendingPathExtension:GSWArchiveSuffix[GSWebNamingConv]]);
|
|
|
|
|
|
|
|
defaultFileManager = [NSFileManager defaultManager];
|
|
|
|
|
|
|
|
if (_componentClass == Nil) {
|
|
|
|
[self autorelease];
|
|
|
|
NSLog(@"%s: No component class for component named '%@' found", __PRETTY_FUNCTION__, _name);
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if (([defaultFileManager fileExistsAtPath: _htmlPath] == NO) ||
|
|
|
|
// ([defaultFileManager fileExistsAtPath: _wodPath] == NO) ||
|
|
|
|
// ([defaultFileManager fileExistsAtPath: _wooPath] == NO) ||
|
|
|
|
// (_componentClass == Nil)) {
|
|
|
|
//
|
|
|
|
// [NSException raise:NSInvalidArgumentException
|
|
|
|
// format:@"%s: No template found for component named '%@'",
|
|
|
|
// __PRETTY_FUNCTION__, _name];
|
|
|
|
// }
|
|
|
|
_archive = nil;
|
2010-06-22 05:02:29 +00:00
|
|
|
_encoding = 0; // to test for real value later
|
2007-04-13 18:32:02 +00:00
|
|
|
_template = nil;
|
|
|
|
[self setCachingEnabled:[[GSWApp class] isCachingEnabled]];
|
|
|
|
_isAwake = NO;
|
|
|
|
|
|
|
|
_instancePoolLock = [[NSLock alloc] init];
|
|
|
|
|
2000-01-22 12:49:49 +00:00
|
|
|
return self;
|
2007-04-13 18:32:02 +00:00
|
|
|
}
|
2000-01-22 12:49:49 +00:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
-(void)dealloc
|
|
|
|
{
|
2002-08-04 18:00:11 +00:00
|
|
|
DESTROY(_name);
|
2007-04-13 18:32:02 +00:00
|
|
|
DESTROY(_path);
|
|
|
|
DESTROY(_url);
|
2002-08-04 18:00:11 +00:00
|
|
|
DESTROY(_frameworkName);
|
2007-04-13 18:32:02 +00:00
|
|
|
DESTROY(_language);
|
|
|
|
DESTROY(_className);
|
|
|
|
_componentClass = Nil;
|
|
|
|
DESTROY(_template);
|
|
|
|
DESTROY(_htmlPath);
|
|
|
|
DESTROY(_wodPath);
|
|
|
|
DESTROY(_wooPath);
|
|
|
|
DESTROY(_archive);
|
|
|
|
DESTROY(_sharedInstance);
|
|
|
|
DESTROY(_instancePool);
|
|
|
|
|
2010-06-22 05:02:29 +00:00
|
|
|
DESTROY(_wooReadDate);
|
|
|
|
DESTROY(_htmlReadDate);
|
|
|
|
|
|
|
|
|
2000-01-22 12:49:49 +00:00
|
|
|
[super dealloc];
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
2007-04-13 18:32:02 +00:00
|
|
|
|
|
|
|
- (void) checkInComponentInstance:(GSWComponent*) component
|
2000-01-22 12:49:49 +00:00
|
|
|
{
|
2007-04-13 18:32:02 +00:00
|
|
|
if (_sharedInstance == nil)
|
|
|
|
{
|
|
|
|
_sharedInstance = component;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
[_instancePool addObject:component];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _checkInComponentInstance:(GSWComponent*) component
|
|
|
|
{
|
|
|
|
BOOL locked = NO;
|
|
|
|
|
|
|
|
if (_lockInstancePool) {
|
|
|
|
NS_DURING
|
|
|
|
[_instancePoolLock lock];
|
|
|
|
locked = YES;
|
|
|
|
[self checkInComponentInstance: component];
|
|
|
|
locked = NO;
|
|
|
|
[_instancePoolLock unlock];
|
|
|
|
|
|
|
|
NS_HANDLER
|
|
|
|
if (locked) {
|
|
|
|
[_instancePoolLock unlock];
|
|
|
|
}
|
|
|
|
localException=[localException exceptionByAddingUserInfoFrameInfoFormat:@"In %s",
|
|
|
|
__PRETTY_FUNCTION__];
|
|
|
|
[localException raise];
|
|
|
|
NS_ENDHANDLER;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
[self checkInComponentInstance: component];
|
|
|
|
}
|
|
|
|
}
|
2000-01-22 12:49:49 +00:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
-(NSString*)frameworkName
|
|
|
|
{
|
2002-08-04 18:00:11 +00:00
|
|
|
return _frameworkName;
|
2000-01-22 12:49:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
-(NSString*)baseURL
|
|
|
|
{
|
2007-04-13 18:32:02 +00:00
|
|
|
return _url;
|
|
|
|
}
|
2000-01-22 12:49:49 +00:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
-(NSString*)path
|
|
|
|
{
|
2007-04-13 18:32:02 +00:00
|
|
|
return _path;
|
2000-01-22 12:49:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
-(NSString*)name
|
|
|
|
{
|
2002-08-04 18:00:11 +00:00
|
|
|
return _name;
|
2000-01-22 12:49:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
-(NSString*)description
|
|
|
|
{
|
|
|
|
//TODO
|
2010-06-22 05:02:29 +00:00
|
|
|
return [NSString stringWithFormat:@"<%s %p - name:[%@] frameworkName=[%@] componentClass=[%@] isCachingEnabled=[%s] isAwake=[%s]>",
|
2010-04-22 04:28:50 +00:00
|
|
|
object_getClassName(self),
|
2000-01-22 12:49:49 +00:00
|
|
|
(void*)self,
|
2002-08-04 18:00:11 +00:00
|
|
|
_name,
|
|
|
|
_frameworkName,
|
|
|
|
_componentClass,
|
2007-04-13 18:32:02 +00:00
|
|
|
_caching ? "YES" : "NO",
|
2002-08-04 18:00:11 +00:00
|
|
|
_isAwake ? "YES" : "NO"];
|
2000-01-22 12:49:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
-(void)sleep
|
|
|
|
{
|
|
|
|
//OK
|
2002-08-04 18:00:11 +00:00
|
|
|
_isAwake=NO;
|
2000-01-22 12:49:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
2007-04-13 18:32:02 +00:00
|
|
|
// dw
|
2000-01-22 12:49:49 +00:00
|
|
|
-(void)awake
|
|
|
|
{
|
2007-04-13 18:32:02 +00:00
|
|
|
if (!_isAwake) {
|
|
|
|
_isAwake = YES;
|
|
|
|
if (! _caching) {
|
|
|
|
[self componentClass];
|
|
|
|
}
|
|
|
|
}
|
2000-01-22 12:49:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
-(BOOL)isCachingEnabled
|
|
|
|
{
|
2007-04-13 18:32:02 +00:00
|
|
|
return _caching;
|
2000-01-22 12:49:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
2002-08-04 18:00:11 +00:00
|
|
|
-(void)setCachingEnabled:(BOOL)flag
|
2000-01-22 12:49:49 +00:00
|
|
|
{
|
2007-04-13 18:32:02 +00:00
|
|
|
_caching = flag;
|
2000-01-22 12:49:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
-(void)_clearCache
|
|
|
|
{
|
2008-08-20 20:32:10 +00:00
|
|
|
}
|
2000-01-22 12:49:49 +00:00
|
|
|
|
2008-08-20 20:32:10 +00:00
|
|
|
// CHECKME
|
2000-01-22 12:49:49 +00:00
|
|
|
|
2007-04-13 18:32:02 +00:00
|
|
|
-(GSWComponent*) _componentInstanceInContext:(GSWContext*) aContext
|
2000-01-22 12:49:49 +00:00
|
|
|
{
|
2007-04-13 18:32:02 +00:00
|
|
|
Class myClass = [self componentClass];
|
|
|
|
GSWComponent * component = nil;
|
|
|
|
IMP instanceInitIMP = NULL;
|
|
|
|
IMP componentInitIMP = NULL;
|
|
|
|
GSWComponent * myInstance = nil;
|
|
|
|
BOOL locked = NO;
|
|
|
|
|
2010-04-14 13:20:16 +00:00
|
|
|
if ([myClass isSubclassOfClass: [GSWComponent class]]) {
|
2007-04-13 18:32:02 +00:00
|
|
|
[aContext _setComponentName:_className];
|
|
|
|
}
|
|
|
|
[aContext _setTempComponentDefinition:self];
|
|
|
|
|
2000-01-22 12:49:49 +00:00
|
|
|
NS_DURING
|
2007-04-13 18:32:02 +00:00
|
|
|
|
|
|
|
if (!_hasBeenAccessed) {
|
|
|
|
myInstance = [myClass alloc];
|
|
|
|
instanceInitIMP = [myInstance methodForSelector:@selector(init)];
|
|
|
|
componentInitIMP = [GSWComponent instanceMethodForSelector:@selector(init)];
|
|
|
|
|
|
|
|
if (instanceInitIMP != componentInitIMP) {
|
2010-04-22 04:28:50 +00:00
|
|
|
// NSLog(@"Class %s should implement initWithContext: and not init", object_getClassName(myClass));
|
2007-04-13 18:32:02 +00:00
|
|
|
[ComponentConstructorLock lock];
|
|
|
|
locked = YES;
|
|
|
|
TheTemporaryContext = aContext;
|
|
|
|
component = AUTORELEASE([myInstance init]);
|
|
|
|
TheTemporaryContext = nil;
|
|
|
|
locked = NO;
|
|
|
|
_hasContextConstructor = NO;
|
|
|
|
[ComponentConstructorLock unlock];
|
|
|
|
} else {
|
|
|
|
component = AUTORELEASE([myInstance initWithContext: aContext]);
|
|
|
|
_hasContextConstructor = YES;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// check if we can use some intelligent caching here.
|
|
|
|
myInstance = [myClass alloc];
|
|
|
|
|
|
|
|
if (_hasContextConstructor == NO) {
|
|
|
|
[ComponentConstructorLock lock];
|
|
|
|
locked = YES;
|
|
|
|
TheTemporaryContext = aContext;
|
|
|
|
component = AUTORELEASE([myInstance init]);
|
|
|
|
TheTemporaryContext = nil;
|
|
|
|
locked = NO;
|
|
|
|
[ComponentConstructorLock unlock];
|
|
|
|
} else {
|
|
|
|
component = AUTORELEASE([myInstance initWithContext: aContext]);
|
|
|
|
}
|
2002-08-04 18:00:11 +00:00
|
|
|
}
|
2000-01-22 12:49:49 +00:00
|
|
|
NS_HANDLER
|
2007-04-13 18:32:02 +00:00
|
|
|
if (locked) {
|
|
|
|
[ComponentConstructorLock unlock];
|
|
|
|
}
|
|
|
|
localException=[localException exceptionByAddingUserInfoFrameInfoFormat:@"In %s",
|
|
|
|
__PRETTY_FUNCTION__];
|
2002-08-04 18:00:11 +00:00
|
|
|
[localException raise];
|
2000-01-22 12:49:49 +00:00
|
|
|
NS_ENDHANDLER;
|
2007-04-13 18:32:02 +00:00
|
|
|
|
|
|
|
if ([component context] == nil) {
|
|
|
|
[NSException raise:NSInvalidArgumentException
|
|
|
|
format:@"Component '%@' was not properly initialized. Make sure [super initWithContext:] is called. In %s",
|
|
|
|
_className,
|
|
|
|
__PRETTY_FUNCTION__];
|
|
|
|
}
|
|
|
|
return component;
|
|
|
|
}
|
2002-11-18 11:14:55 +00:00
|
|
|
|
2007-04-13 18:32:02 +00:00
|
|
|
- (BOOL) isStateless
|
|
|
|
{
|
|
|
|
return _isStateless;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// this is called when we are already holding a lock.
|
|
|
|
|
|
|
|
-(GSWComponent*) _sharedInstanceInContext:(GSWContext*)aContext
|
|
|
|
{
|
|
|
|
GSWComponent * component = nil;
|
|
|
|
|
|
|
|
if (_sharedInstance != nil) {
|
|
|
|
component = _sharedInstance;
|
|
|
|
_sharedInstance = nil;
|
|
|
|
} else {
|
|
|
|
if ([_instancePool count] > 0) {
|
|
|
|
component = AUTORELEASE(RETAIN([_instancePool lastObject]));
|
|
|
|
[_instancePool removeLastObject];
|
|
|
|
} else {
|
|
|
|
component = [self _componentInstanceInContext:aContext];
|
|
|
|
}
|
|
|
|
}
|
2002-08-04 18:00:11 +00:00
|
|
|
return component;
|
2007-04-13 18:32:02 +00:00
|
|
|
}
|
|
|
|
|
2000-01-22 12:49:49 +00:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
2007-04-13 18:32:02 +00:00
|
|
|
-(GSWComponent*)componentInstanceInContext:(GSWContext*)aContext
|
2000-01-22 12:49:49 +00:00
|
|
|
{
|
2007-04-13 18:32:02 +00:00
|
|
|
GSWComponent* component=nil;
|
|
|
|
BOOL locked = NO;
|
|
|
|
|
|
|
|
if (aContext == nil) {
|
|
|
|
[NSException raise:NSInvalidArgumentException
|
|
|
|
format:@"Attempt to create component instance without a context. In %s",
|
|
|
|
__PRETTY_FUNCTION__];
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_DURING
|
|
|
|
|
|
|
|
if (!_hasBeenAccessed) {
|
|
|
|
component = [self _componentInstanceInContext: aContext];
|
|
|
|
_isStateless = [component isStateless];
|
|
|
|
_hasBeenAccessed = YES;
|
|
|
|
} else {
|
|
|
|
if (_isStateless) {
|
|
|
|
if (_lockInstancePool) {
|
|
|
|
[_instancePoolLock lock];
|
|
|
|
locked = YES;
|
|
|
|
component = [self _sharedInstanceInContext:aContext];
|
|
|
|
locked = NO;
|
|
|
|
[_instancePoolLock unlock];
|
|
|
|
} else {
|
|
|
|
component = [self _sharedInstanceInContext:aContext];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
component = [self _componentInstanceInContext:aContext];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_HANDLER
|
|
|
|
|
|
|
|
localException=[localException exceptionByAddingUserInfoFrameInfoFormat:@"In %s",
|
|
|
|
__PRETTY_FUNCTION__];
|
|
|
|
if (_lockInstancePool && locked) {
|
|
|
|
[_instancePoolLock unlock];
|
|
|
|
}
|
|
|
|
[localException raise];
|
|
|
|
|
|
|
|
NS_ENDHANDLER;
|
|
|
|
|
|
|
|
return component;
|
|
|
|
}
|
|
|
|
|
2000-01-22 12:49:49 +00:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
2002-11-18 11:14:55 +00:00
|
|
|
/** Find the class of the component **/
|
2007-04-13 18:32:02 +00:00
|
|
|
-(Class) componentClass
|
|
|
|
{
|
|
|
|
Class componentClass = Nil;
|
|
|
|
|
|
|
|
if (_componentClass) {
|
|
|
|
return _componentClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
componentClass = _componentClass;
|
|
|
|
if (!componentClass) {
|
2002-08-04 18:00:11 +00:00
|
|
|
componentClass=NSClassFromString(_name);//???
|
2007-04-13 18:32:02 +00:00
|
|
|
}
|
2002-11-18 11:14:55 +00:00
|
|
|
if (!componentClass) // There's no class with that name
|
2002-08-04 18:00:11 +00:00
|
|
|
{
|
|
|
|
BOOL createClassesOk=NO;
|
|
|
|
NSString* superClassName=nil;
|
2002-11-18 11:14:55 +00:00
|
|
|
// If we haven't found a superclass, use GSWComponent as the superclass
|
2002-08-04 18:00:11 +00:00
|
|
|
if (!superClassName)
|
2010-06-22 05:02:29 +00:00
|
|
|
superClassName=@"WOComponent";
|
2002-11-18 11:14:55 +00:00
|
|
|
// Create class
|
2002-08-04 18:00:11 +00:00
|
|
|
createClassesOk=[GSWApplication createUnknownComponentClasses:[NSArray arrayWithObject:_name]
|
|
|
|
superClassName:superClassName];
|
2002-11-18 11:14:55 +00:00
|
|
|
|
|
|
|
// Use it
|
2002-08-04 18:00:11 +00:00
|
|
|
componentClass=NSClassFromString(_name);
|
|
|
|
};
|
2002-11-18 11:14:55 +00:00
|
|
|
//call GSWApp isCaching
|
2007-04-13 18:32:02 +00:00
|
|
|
_componentClass=componentClass;
|
|
|
|
|
2002-08-04 18:00:11 +00:00
|
|
|
return componentClass;
|
2000-01-22 12:49:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
2002-08-04 18:00:11 +00:00
|
|
|
-(GSWComponentReference*)componentReferenceWithAssociations:(NSDictionary*)associations
|
|
|
|
template:(GSWElement*)template
|
2000-01-22 12:49:49 +00:00
|
|
|
{
|
|
|
|
//OK
|
2002-08-04 18:00:11 +00:00
|
|
|
GSWComponentReference* componentReference=nil;
|
|
|
|
componentReference=[[[GSWComponentReference alloc]initWithName:_name
|
|
|
|
associations:associations
|
|
|
|
template:template] autorelease];
|
|
|
|
return componentReference;
|
2000-01-22 12:49:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
2007-04-13 18:32:02 +00:00
|
|
|
-(void) finishInitializingComponent:(GSWComponent*)component
|
2000-01-22 12:49:49 +00:00
|
|
|
{
|
2010-06-22 05:02:29 +00:00
|
|
|
NSDictionary * archive=nil;
|
|
|
|
NSBundle * bundle = [NSBundle bundleForClass:NSClassFromString(_className)];
|
|
|
|
|
|
|
|
archive = [self archive];
|
2010-06-10 09:37:23 +00:00
|
|
|
|
|
|
|
if (archive) {
|
2010-06-22 05:02:29 +00:00
|
|
|
[bundle initializeObject:component
|
|
|
|
fromArchive:archive];
|
2010-06-10 09:37:23 +00:00
|
|
|
}
|
|
|
|
}
|
2000-01-22 12:49:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
2002-08-04 18:00:11 +00:00
|
|
|
-(void)_notifyObserversForDyingComponent:(GSWComponent*)aComponent
|
2000-01-22 12:49:49 +00:00
|
|
|
{
|
2010-06-05 21:08:12 +00:00
|
|
|
[self notImplemented: _cmd]; //TODOFN
|
2000-01-22 12:49:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
2002-08-04 18:00:11 +00:00
|
|
|
-(void)_awakeObserversForComponent:(GSWComponent*)aComponent
|
2000-01-22 12:49:49 +00:00
|
|
|
{
|
2010-06-05 21:08:12 +00:00
|
|
|
[self notImplemented: _cmd]; //TODOFN
|
2000-01-22 12:49:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
2002-08-04 18:00:11 +00:00
|
|
|
-(void)_deallocForComponent:(GSWComponent*)aComponent
|
2000-01-22 12:49:49 +00:00
|
|
|
{
|
2010-06-05 21:08:12 +00:00
|
|
|
[self notImplemented: _cmd]; //TODOFN
|
2000-01-22 12:49:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
2002-08-04 18:00:11 +00:00
|
|
|
-(void)_awakeForComponent:(GSWComponent*)aComponent
|
2000-01-22 12:49:49 +00:00
|
|
|
{
|
2010-06-05 21:08:12 +00:00
|
|
|
[self notImplemented: _cmd]; //TODOFN
|
2000-01-22 12:49:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
2002-08-04 18:00:11 +00:00
|
|
|
-(void)_registerObserver:(id)observer
|
2000-01-22 12:49:49 +00:00
|
|
|
{
|
2010-06-05 21:08:12 +00:00
|
|
|
[self notImplemented: _cmd]; //TODOFN
|
2000-01-22 12:49:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
2002-08-04 18:00:11 +00:00
|
|
|
+(void)_registerObserver:(id)observer
|
2000-01-22 12:49:49 +00:00
|
|
|
{
|
2010-06-05 21:08:12 +00:00
|
|
|
[self notImplemented: _cmd]; //TODOFN
|
2000-01-22 12:49:49 +00:00
|
|
|
};
|
|
|
|
|
2010-06-22 05:02:29 +00:00
|
|
|
/*
|
|
|
|
* returns the contents of the .woo
|
|
|
|
*/
|
|
|
|
- (NSDictionary *) archive
|
|
|
|
{
|
|
|
|
if ((_caching) && (_archive)) {
|
|
|
|
// nothing to waste time with.
|
|
|
|
return _archive;
|
|
|
|
} else {
|
|
|
|
NSFileManager * defaultManager = [NSFileManager defaultManager];
|
|
|
|
NSDictionary * attributes;
|
|
|
|
NSDate * modDate;
|
|
|
|
|
|
|
|
attributes = [defaultManager attributesOfItemAtPath:_wooPath error:NULL];
|
|
|
|
modDate = [attributes fileModificationDate];
|
|
|
|
|
|
|
|
|
|
|
|
// file not found.
|
|
|
|
if (!modDate) {
|
|
|
|
modDate = [NSDate date];
|
|
|
|
ASSIGN(_wooReadDate, modDate);
|
|
|
|
ASSIGN(_archive, [NSDictionary dictionary]);
|
|
|
|
return _archive;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((!_wooReadDate) || (([modDate compare:_wooReadDate] == NSOrderedDescending))) {
|
|
|
|
ASSIGN(_wooReadDate, [NSDate date]);
|
|
|
|
ASSIGN(_archive, [NSDictionary dictionaryWithContentsOfFile:_wooPath]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return _archive;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
-(NSStringEncoding) encoding
|
|
|
|
{
|
|
|
|
NSDictionary * archive = nil;
|
|
|
|
NSString * encodingName = nil;
|
|
|
|
|
|
|
|
if ((_encoding == 0)) {
|
|
|
|
|
|
|
|
_encoding = [GSWMessage defaultEncoding]; // safer, because we may not have a .woo file
|
|
|
|
|
|
|
|
archive = [self archive];
|
|
|
|
if (archive)
|
|
|
|
{
|
|
|
|
encodingName = [archive objectForKey:@"encoding"];
|
|
|
|
if (encodingName)
|
|
|
|
{
|
|
|
|
_encoding = [GSMimeDocument encodingFromCharset:encodingName];
|
|
|
|
|
|
|
|
if ((_encoding == 0)) {
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
format: @"%s %@ -- unknown encoding '%@'",__PRETTY_FUNCTION__, _wooPath, encodingName];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return _encoding;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (GSWElement *) _lockedTemplate
|
|
|
|
{
|
|
|
|
//OK
|
|
|
|
GSWElement* template=nil;
|
|
|
|
NSStringEncoding encoding = [self encoding];
|
|
|
|
|
|
|
|
NSString* pageDefString=nil;
|
|
|
|
NSString* htmlString = [NSString stringWithContentsOfFile:_htmlPath
|
|
|
|
encoding:encoding];
|
|
|
|
|
|
|
|
if (!htmlString)
|
|
|
|
{
|
|
|
|
[NSException raise:NSInvalidArgumentException
|
|
|
|
format:@"%s: No HTML file found at '%@'",
|
|
|
|
__PRETTY_FUNCTION__, _htmlPath];
|
|
|
|
}
|
|
|
|
|
|
|
|
pageDefString = [NSString stringWithContentsOfFile:_wodPath
|
|
|
|
encoding:encoding];
|
|
|
|
|
|
|
|
if (!pageDefString) {
|
|
|
|
[NSException raise:NSInvalidArgumentException
|
|
|
|
format:@"%s: No WOD file found at '%@'",
|
|
|
|
__PRETTY_FUNCTION__, _wodPath];
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_DURING
|
|
|
|
{
|
|
|
|
template=[GSWTemplateParser templateNamed:_name
|
|
|
|
inFrameworkNamed:nil
|
|
|
|
withParserType:GSWTemplateParserType_Default
|
|
|
|
parserClassName:nil
|
|
|
|
withString:htmlString
|
|
|
|
encoding:encoding
|
|
|
|
fromPath:nil
|
|
|
|
declarationsString:pageDefString
|
|
|
|
languages:nil
|
|
|
|
declarationsPath:nil];
|
|
|
|
}
|
|
|
|
NS_HANDLER
|
|
|
|
{
|
|
|
|
localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException,
|
|
|
|
@"In template Parsing");
|
|
|
|
[localException raise];
|
|
|
|
}
|
|
|
|
NS_ENDHANDLER;
|
|
|
|
|
|
|
|
return template;
|
|
|
|
}
|
|
|
|
|
2007-04-13 18:32:02 +00:00
|
|
|
- (GSWElement *) template
|
|
|
|
{
|
|
|
|
BOOL htmlChangedOnDisk = NO;
|
2010-06-22 05:02:29 +00:00
|
|
|
|
|
|
|
// _htmlReadDate
|
|
|
|
if (_caching == NO) {
|
|
|
|
htmlChangedOnDisk = YES;
|
|
|
|
} else {
|
|
|
|
NSFileManager * defaultManager = [NSFileManager defaultManager];
|
|
|
|
NSDictionary * attributes;
|
|
|
|
NSDate * modDate;
|
|
|
|
|
|
|
|
attributes = [defaultManager attributesOfItemAtPath:_wooPath error:NULL];
|
|
|
|
modDate = [attributes fileModificationDate];
|
|
|
|
|
|
|
|
if ((!_htmlReadDate) || (([modDate compare:_htmlReadDate] == NSOrderedDescending))) {
|
|
|
|
htmlChangedOnDisk = YES;
|
|
|
|
} else {
|
|
|
|
attributes = [defaultManager attributesOfItemAtPath:_wodPath error:NULL];
|
|
|
|
modDate = [attributes fileModificationDate];
|
|
|
|
|
|
|
|
if (([modDate compare:_htmlReadDate] == NSOrderedDescending)) {
|
|
|
|
htmlChangedOnDisk = YES;
|
|
|
|
}
|
2007-04-13 18:32:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-22 05:02:29 +00:00
|
|
|
if (_htmlPath != nil && (_template == nil || htmlChangedOnDisk)) {
|
|
|
|
ASSIGN(_htmlReadDate, [NSDate date]);
|
|
|
|
NS_DURING
|
2007-04-13 18:32:02 +00:00
|
|
|
[TemplateLock lock];
|
|
|
|
DESTROY(_template);
|
2010-06-22 05:02:29 +00:00
|
|
|
|
|
|
|
_template = RETAIN([self _lockedTemplate]);
|
2007-04-13 18:32:02 +00:00
|
|
|
[TemplateLock unlock];
|
2010-06-22 05:02:29 +00:00
|
|
|
NS_HANDLER
|
2007-04-13 18:32:02 +00:00
|
|
|
DESTROY(_template);
|
|
|
|
[TemplateLock unlock];
|
|
|
|
[localException raise];
|
2010-06-22 05:02:29 +00:00
|
|
|
NS_ENDHANDLER
|
|
|
|
|
2007-04-13 18:32:02 +00:00
|
|
|
}
|
|
|
|
return _template;
|
|
|
|
}
|
|
|
|
|
2008-08-20 20:32:10 +00:00
|
|
|
- (void) encodeWithCoder: (NSCoder*)aCoder
|
|
|
|
{
|
2010-06-05 21:08:12 +00:00
|
|
|
[self notImplemented: _cmd];
|
2008-08-20 20:32:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) initWithCoder: (NSCoder*)aDecoder
|
|
|
|
{
|
2010-06-05 21:08:12 +00:00
|
|
|
[self notImplemented: _cmd];
|
2008-08-20 20:32:10 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) copyWithZone: (NSZone*)z
|
|
|
|
{
|
|
|
|
|
2010-06-05 21:08:12 +00:00
|
|
|
[self notImplemented: _cmd];
|
2008-08-20 20:32:10 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2000-01-22 12:49:49 +00:00
|
|
|
@end
|