]> err.no Git - sope/blob - sope-appserver/NGObjWeb/SoObjects/WODirectAction+SoObjects.m
added some WebDrive WebDAV properties
[sope] / sope-appserver / NGObjWeb / SoObjects / WODirectAction+SoObjects.m
1 /*
2   Copyright (C) 2002-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 <NGObjWeb/WODirectAction.h>
23 #include "WOContext+SoObjects.h"
24 #include "SoObject.h"
25 #include "common.h"
26
27 /*
28   WODirectActionPubInvocation
29   
30   This invocation is used if you have a direct action in the lookup path, this
31   can be configured by setting a WODirectAction subclass as a 'slot' of a
32   class.
33 */
34
35 @interface WODirectActionPubInvocation : NSObject
36 {
37 @public
38   WODirectAction *parent;
39   NSString *daName;
40 }
41 @end
42
43 @implementation WODirectAction(SoObjectRequestHandler)
44
45 - (id)clientObject {
46   return [[(id)self context] clientObject];
47 }
48
49 - (id)lookupName:(NSString *)_name inContext:(id)_ctx acquire:(BOOL)_flag {
50   WODirectActionPubInvocation *inv;
51   NSString *daName;
52   SEL sel;
53   
54   daName = [_name stringByAppendingString:@"Action"];
55   sel    = daName ? NSSelectorFromString(daName) : NULL;
56   
57   if (![self respondsToSelector:sel])
58     return [super lookupName:_name inContext:_ctx acquire:_flag];
59     
60   inv = [[WODirectActionPubInvocation alloc] init];
61   inv->daName = [_name copy];
62   inv->parent = [self retain];
63   return [inv autorelease];
64 }
65
66 @end /* WODirectAction(SoObjectRequestHandler) */
67
68 @implementation WODirectActionPubInvocation
69
70 - (void)dealloc {
71   [self->daName release];
72   [self->parent release];
73   [super dealloc];
74 }
75
76 - (id)parentObject {
77   return self->parent;
78 }
79
80 - (BOOL)isCallable {
81   return YES;
82 }
83 - (id)callOnObject:(id)_object inContext:(id)_ctx {
84   return [_object ? _object : self->parent performActionNamed:self->daName];
85 }
86
87 /* description */
88
89 - (NSString *)description {
90   NSMutableString *ms;
91   
92   ms = [NSMutableString stringWithCapacity:64];
93   [ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])];
94   [ms appendFormat:@" action=%@", self->daName];
95   [ms appendFormat:@" class=%@", NSStringFromClass([self->parent class])];
96   [ms appendString:@">"];
97   return ms;
98 }
99
100 @end /* WODirectActionPubInvocation */