appjam 0.1.0.pre4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE.txt +20 -0
- data/README.rdoc +27 -0
- data/bin/appjam +17 -0
- data/lib/appjam.rb +50 -0
- data/lib/appjam/generators/Classes/ContactsAppDelegate.h.tt +18 -0
- data/lib/appjam/generators/Classes/ContactsAppDelegate.m.tt +88 -0
- data/lib/appjam/generators/Classes/org/puremvc/objectivec/core/Controller.h +54 -0
- data/lib/appjam/generators/Classes/org/puremvc/objectivec/core/Controller.m +145 -0
- data/lib/appjam/generators/Classes/org/puremvc/objectivec/core/Model.h +47 -0
- data/lib/appjam/generators/Classes/org/puremvc/objectivec/core/Model.m +117 -0
- data/lib/appjam/generators/Classes/org/puremvc/objectivec/core/View.h +39 -0
- data/lib/appjam/generators/Classes/org/puremvc/objectivec/core/View.m +207 -0
- data/lib/appjam/generators/Classes/org/puremvc/objectivec/interfaces/ICommand.h +16 -0
- data/lib/appjam/generators/Classes/org/puremvc/objectivec/interfaces/IController.h +57 -0
- data/lib/appjam/generators/Classes/org/puremvc/objectivec/interfaces/IFacade.h +135 -0
- data/lib/appjam/generators/Classes/org/puremvc/objectivec/interfaces/IMediator.h +84 -0
- data/lib/appjam/generators/Classes/org/puremvc/objectivec/interfaces/IModel.h +50 -0
- data/lib/appjam/generators/Classes/org/puremvc/objectivec/interfaces/INotification.h +57 -0
- data/lib/appjam/generators/Classes/org/puremvc/objectivec/interfaces/INotifier.h +41 -0
- data/lib/appjam/generators/Classes/org/puremvc/objectivec/interfaces/IObserver.h +67 -0
- data/lib/appjam/generators/Classes/org/puremvc/objectivec/interfaces/IProxy.h +53 -0
- data/lib/appjam/generators/Classes/org/puremvc/objectivec/interfaces/IView.h +96 -0
- data/lib/appjam/generators/Classes/org/puremvc/objectivec/patterns/command/MacroCommand.h +50 -0
- data/lib/appjam/generators/Classes/org/puremvc/objectivec/patterns/command/MacroCommand.m +101 -0
- data/lib/appjam/generators/Classes/org/puremvc/objectivec/patterns/command/SimpleCommand.h +28 -0
- data/lib/appjam/generators/Classes/org/puremvc/objectivec/patterns/command/SimpleCommand.m +34 -0
- data/lib/appjam/generators/Classes/org/puremvc/objectivec/patterns/facade/Facade.h +52 -0
- data/lib/appjam/generators/Classes/org/puremvc/objectivec/patterns/facade/Facade.m +304 -0
- data/lib/appjam/generators/Classes/org/puremvc/objectivec/patterns/mediator/Mediator.h +35 -0
- data/lib/appjam/generators/Classes/org/puremvc/objectivec/patterns/mediator/Mediator.m +101 -0
- data/lib/appjam/generators/Classes/org/puremvc/objectivec/patterns/observer/Notification.h +52 -0
- data/lib/appjam/generators/Classes/org/puremvc/objectivec/patterns/observer/Notification.m +71 -0
- data/lib/appjam/generators/Classes/org/puremvc/objectivec/patterns/observer/Notifier.h +40 -0
- data/lib/appjam/generators/Classes/org/puremvc/objectivec/patterns/observer/Notifier.m +54 -0
- data/lib/appjam/generators/Classes/org/puremvc/objectivec/patterns/observer/Observer.h +42 -0
- data/lib/appjam/generators/Classes/org/puremvc/objectivec/patterns/observer/Observer.m +67 -0
- data/lib/appjam/generators/Classes/org/puremvc/objectivec/patterns/proxy/Proxy.h +51 -0
- data/lib/appjam/generators/Classes/org/puremvc/objectivec/patterns/proxy/Proxy.m +73 -0
- data/lib/appjam/generators/Classes/users/ApplicationFacade.h.tt +31 -0
- data/lib/appjam/generators/Classes/users/ApplicationFacade.m.tt +33 -0
- data/lib/appjam/generators/Classes/users/controller/CreateUserCommand.h.tt +16 -0
- data/lib/appjam/generators/Classes/users/controller/CreateUserCommand.m.tt +27 -0
- data/lib/appjam/generators/Classes/users/controller/DeleteUserCommand.h.tt +16 -0
- data/lib/appjam/generators/Classes/users/controller/DeleteUserCommand.m.tt +21 -0
- data/lib/appjam/generators/Classes/users/controller/GetUsersCommand.h.tt +17 -0
- data/lib/appjam/generators/Classes/users/controller/GetUsersCommand.m.tt +21 -0
- data/lib/appjam/generators/Classes/users/controller/StartupCommand.h.tt +16 -0
- data/lib/appjam/generators/Classes/users/controller/StartupCommand.m.tt +29 -0
- data/lib/appjam/generators/Classes/users/controller/UpdateUserCommand.h.tt +16 -0
- data/lib/appjam/generators/Classes/users/controller/UpdateUserCommand.m.tt +27 -0
- data/lib/appjam/generators/Classes/users/model/UserProxy.h.tt +19 -0
- data/lib/appjam/generators/Classes/users/model/UserProxy.m.tt +59 -0
- data/lib/appjam/generators/Classes/users/model/vo/UserVO.h.tt +22 -0
- data/lib/appjam/generators/Classes/users/model/vo/UserVO.m.tt +47 -0
- data/lib/appjam/generators/Classes/users/view/ContactsMediator.h.tt +15 -0
- data/lib/appjam/generators/Classes/users/view/ContactsMediator.m.tt +43 -0
- data/lib/appjam/generators/Classes/users/view/UserFormMediator.h.tt +17 -0
- data/lib/appjam/generators/Classes/users/view/UserFormMediator.m.tt +57 -0
- data/lib/appjam/generators/Classes/users/view/UserListMediator.h.tt +17 -0
- data/lib/appjam/generators/Classes/users/view/UserListMediator.m.tt +59 -0
- data/lib/appjam/generators/Classes/users/view/components/Contacts.h.tt +27 -0
- data/lib/appjam/generators/Classes/users/view/components/Contacts.m.tt +46 -0
- data/lib/appjam/generators/Classes/users/view/components/UserForm.h.tt +37 -0
- data/lib/appjam/generators/Classes/users/view/components/UserForm.m.tt +118 -0
- data/lib/appjam/generators/Classes/users/view/components/UserList.h.tt +31 -0
- data/lib/appjam/generators/Classes/users/view/components/UserList.m.tt +77 -0
- data/lib/appjam/generators/Contacts-Info.plist.tt +28 -0
- data/lib/appjam/generators/Contacts.xcodeproj/eiffel.pbxuser +1671 -0
- data/lib/appjam/generators/Contacts.xcodeproj/eiffel.perspectivev3 +1638 -0
- data/lib/appjam/generators/Contacts.xcodeproj/project.pbxproj +574 -0
- data/lib/appjam/generators/Contacts_Prefix.pch.tt +8 -0
- data/lib/appjam/generators/app.rb +78 -0
- data/lib/appjam/generators/main.m.tt +17 -0
- data/lib/appjam/generators/utils/NSStringWhiteSpace.h +17 -0
- data/lib/appjam/generators/utils/NSStringWhiteSpace.m +31 -0
- data/lib/appjam/generators/utils/UIDevice.h +17 -0
- data/lib/appjam/generators/utils/UIDevice.m +83 -0
- data/lib/appjam/generators/utils/URLEncodeString.h +16 -0
- data/lib/appjam/generators/utils/URLEncodeString.m +29 -0
- data/lib/appjam/version.rb +10 -0
- data/spec/appjam_spec.rb +7 -0
- data/spec/spec_helper.rb +12 -0
- metadata +270 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
//
|
|
2
|
+
// MacroCommand.h
|
|
3
|
+
// PureMVC_ObjectiveC
|
|
4
|
+
//
|
|
5
|
+
// PureMVC Port to ObjectiveC by Brian Knorr <brian.knorr@puremvc.org>
|
|
6
|
+
// PureMVC - Copyright(c) 2006-2008 Futurescale, Inc., Some rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#import <Foundation/Foundation.h>
|
|
10
|
+
#import "INotification.h"
|
|
11
|
+
#import "Notifier.h"
|
|
12
|
+
#import "ICommand.h"
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A base <code>ICommand</code> implementation that executes other <code>ICommand</code>s.
|
|
16
|
+
*
|
|
17
|
+
* <P>
|
|
18
|
+
* A <code>MacroCommand</code> maintains an list of
|
|
19
|
+
* <code>ICommand</code> Class references called <i>SubCommands</i>.</P>
|
|
20
|
+
*
|
|
21
|
+
* <P>
|
|
22
|
+
* When <code>execute</code> is called, the <code>MacroCommand</code>
|
|
23
|
+
* instantiates and calls <code>execute</code> on each of its <i>SubCommands</i> turn.
|
|
24
|
+
* Each <i>SubCommand</i> will be passed a reference to the original
|
|
25
|
+
* <code>INotification</code> that was passed to the <code>MacroCommand</code>'s
|
|
26
|
+
* <code>execute</code> method.</P>
|
|
27
|
+
*
|
|
28
|
+
* <P>
|
|
29
|
+
* Unlike <code>SimpleCommand</code>, your subclass
|
|
30
|
+
* should not override <code>execute</code>, but instead, should
|
|
31
|
+
* override the <code>initializeMacroCommand</code> method,
|
|
32
|
+
* calling <code>addSubCommand</code> once for each <i>SubCommand</i>
|
|
33
|
+
* to be executed.</P>
|
|
34
|
+
*
|
|
35
|
+
* <P>
|
|
36
|
+
*
|
|
37
|
+
* @see Controller, Notification, SimpleCommand
|
|
38
|
+
*/
|
|
39
|
+
@interface MacroCommand : Notifier <ICommand> {
|
|
40
|
+
NSMutableArray *subCommands;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@property(nonatomic, retain) NSMutableArray *subCommands;
|
|
44
|
+
|
|
45
|
+
-(id)init;
|
|
46
|
+
-(void)initializeMacroCommand;
|
|
47
|
+
-(void)addSubCommand:(Class)commandClassRef;
|
|
48
|
+
+(id)command;
|
|
49
|
+
|
|
50
|
+
@end
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
//
|
|
2
|
+
// MacroCommand.m
|
|
3
|
+
// PureMVC_ObjectiveC
|
|
4
|
+
//
|
|
5
|
+
// PureMVC Port to ObjectiveC by Brian Knorr <brian.knorr@puremvc.org>
|
|
6
|
+
// PureMVC - Copyright(c) 2006-2008 Futurescale, Inc., Some rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#import "MacroCommand.h"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@implementation MacroCommand
|
|
13
|
+
|
|
14
|
+
@synthesize subCommands;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Static Convenience Constructor.
|
|
18
|
+
*/
|
|
19
|
+
+(id)command {
|
|
20
|
+
return [[[self alloc] init] autorelease];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Constructor.
|
|
25
|
+
*
|
|
26
|
+
* <P>
|
|
27
|
+
* You should not need to define a constructor,
|
|
28
|
+
* instead, override the <code>initializeMacroCommand</code>
|
|
29
|
+
* method.</P>
|
|
30
|
+
*
|
|
31
|
+
* <P>
|
|
32
|
+
* If your subclass does define a constructor, be
|
|
33
|
+
* sure to call <code>[super init]</code>.</P>
|
|
34
|
+
*/
|
|
35
|
+
-(id)init {
|
|
36
|
+
if (self = [super init]) {
|
|
37
|
+
self.subCommands = [NSMutableArray array];
|
|
38
|
+
[self initializeMacroCommand];
|
|
39
|
+
}
|
|
40
|
+
return self;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Initialize the <code>MacroCommand</code>.
|
|
45
|
+
*
|
|
46
|
+
* <P>
|
|
47
|
+
* In your subclass, override this method to
|
|
48
|
+
* initialize the <code>MacroCommand</code>'s <i>SubCommand</i>
|
|
49
|
+
* list with <code>ICommand</code> class references like
|
|
50
|
+
* this:</P>
|
|
51
|
+
*
|
|
52
|
+
* @code
|
|
53
|
+
* // Initialize MyMacroCommand
|
|
54
|
+
* -(void)initializeMacroCommand {
|
|
55
|
+
* [self addSubCommand:[FirstCommand class]];
|
|
56
|
+
* [self addSubCommand:[SecondCommand class]];
|
|
57
|
+
* [self addSubCommand:[ThirdCommand class]];
|
|
58
|
+
* }
|
|
59
|
+
* @endcode
|
|
60
|
+
*
|
|
61
|
+
* <P>
|
|
62
|
+
* Note that <i>SubCommand</i>s may be any <code>ICommand</code> implementor,
|
|
63
|
+
* <code>MacroCommand</code>s or <code>SimpleCommands</code> are both acceptable.
|
|
64
|
+
*/
|
|
65
|
+
-(void)initializeMacroCommand {
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Add a <i>SubCommand</i>.
|
|
70
|
+
*
|
|
71
|
+
* <P>
|
|
72
|
+
* The <i>SubCommands</i> will be called in First In/First Out (FIFO)
|
|
73
|
+
* order.</P>
|
|
74
|
+
*
|
|
75
|
+
* @param commandClassRef a reference to the <code>Class</code> of the <code>ICommand</code>.
|
|
76
|
+
*/
|
|
77
|
+
-(void)addSubCommand:(Class)commandClassRef {
|
|
78
|
+
[subCommands addObject:commandClassRef];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Execute this <code>MacroCommand</code>'s <i>SubCommands</i>.
|
|
83
|
+
*
|
|
84
|
+
* <P>
|
|
85
|
+
* The <i>SubCommands</i> will be called in First In/First Out (FIFO)
|
|
86
|
+
* order.
|
|
87
|
+
*
|
|
88
|
+
* @param notification the <code>INotification</code> object to be passsed to each <i>SubCommand</i>.
|
|
89
|
+
*/
|
|
90
|
+
-(void)execute:(id<INotification>)notification {
|
|
91
|
+
for (Class commandClassRef in subCommands) {
|
|
92
|
+
[[[[commandClassRef alloc] init] autorelease] execute:notification];
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
-(void)dealloc {
|
|
97
|
+
self.subCommands = nil;
|
|
98
|
+
[super dealloc];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
@end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//
|
|
2
|
+
// SimpleCommand.h
|
|
3
|
+
// PureMVC_ObjectiveC
|
|
4
|
+
//
|
|
5
|
+
// PureMVC Port to ObjectiveC by Brian Knorr <brian.knorr@puremvc.org>
|
|
6
|
+
// PureMVC - Copyright(c) 2006-2008 Futurescale, Inc., Some rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#import <Foundation/Foundation.h>
|
|
10
|
+
#import "INotification.h"
|
|
11
|
+
#import "Notifier.h"
|
|
12
|
+
#import "ICommand.h"
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A base <code>ICommand</code> implementation.
|
|
16
|
+
*
|
|
17
|
+
* <P>
|
|
18
|
+
* Your subclass should override the <code>execute</code>
|
|
19
|
+
* method where your business logic will handle the <code>INotification</code>. </P>
|
|
20
|
+
*
|
|
21
|
+
* @see Controller, Notification, MacroCommand
|
|
22
|
+
*/
|
|
23
|
+
@interface SimpleCommand : Notifier <ICommand> {
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
+(id)command;
|
|
27
|
+
|
|
28
|
+
@end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
//
|
|
2
|
+
// SimpleCommand.m
|
|
3
|
+
// PureMVC_ObjectiveC
|
|
4
|
+
//
|
|
5
|
+
// PureMVC Port to ObjectiveC by Brian Knorr <brian.knorr@puremvc.org>
|
|
6
|
+
// PureMVC - Copyright(c) 2006-2008 Futurescale, Inc., Some rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#import "SimpleCommand.h"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@implementation SimpleCommand
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Static Convenience Constructor.
|
|
16
|
+
*/
|
|
17
|
+
+(id)command {
|
|
18
|
+
return [[[self alloc] init] autorelease];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Fulfill the use-case initiated by the given <code>INotification</code>.
|
|
23
|
+
*
|
|
24
|
+
* <P>
|
|
25
|
+
* In the Command Pattern, an application use-case typically
|
|
26
|
+
* begins with some user action, which results in an <code>INotification</code> being broadcast, which
|
|
27
|
+
* is handled by business logic in the <code>execute</code> method of an
|
|
28
|
+
* <code>ICommand</code>.</P>
|
|
29
|
+
*
|
|
30
|
+
* @param notification the <code>INotification</code> to handle.
|
|
31
|
+
*/
|
|
32
|
+
-(void)execute:(id<INotification>)notification {}
|
|
33
|
+
|
|
34
|
+
@end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Facade.h
|
|
3
|
+
// PureMVC_ObjectiveC
|
|
4
|
+
//
|
|
5
|
+
// PureMVC Port to ObjectiveC by Brian Knorr <brian.knorr@puremvc.org>
|
|
6
|
+
// PureMVC - Copyright(c) 2006-2008 Futurescale, Inc., Some rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#import <Foundation/Foundation.h>
|
|
10
|
+
#import "IFacade.h"
|
|
11
|
+
#import "IController.h"
|
|
12
|
+
#import "IModel.h"
|
|
13
|
+
#import "IView.h"
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A base Singleton <code>IFacade</code> implementation.
|
|
17
|
+
*
|
|
18
|
+
* <P>
|
|
19
|
+
* In PureMVC, the <code>Facade</code> class assumes these
|
|
20
|
+
* responsibilities:
|
|
21
|
+
* <UL>
|
|
22
|
+
* <LI>Initializing the <code>Model</code>, <code>View</code>
|
|
23
|
+
* and <code>Controller</code> Singletons.</LI>
|
|
24
|
+
* <LI>Providing all the methods defined by the <code>IModel,
|
|
25
|
+
* IView, & IController</code> interfaces.</LI>
|
|
26
|
+
* <LI>Providing the ability to override the specific <code>Model</code>,
|
|
27
|
+
* <code>View</code> and <code>Controller</code> Singletons created.</LI>
|
|
28
|
+
* <LI>Providing a single point of contact to the application for
|
|
29
|
+
* registering <code>Commands</code> and notifying <code>Observers</code></LI>
|
|
30
|
+
* </UL>
|
|
31
|
+
* <P>
|
|
32
|
+
*
|
|
33
|
+
* @see Model, View, Controller, Notification, Mediator, Proxy, SimpleCommand, MacroCommand
|
|
34
|
+
*/
|
|
35
|
+
@interface Facade : NSObject <IFacade> {
|
|
36
|
+
id<IController> controller;
|
|
37
|
+
id<IModel> model;
|
|
38
|
+
id<IView> view;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@property(nonatomic, retain) id<IController> controller;
|
|
42
|
+
@property(nonatomic, retain) id<IModel> model;
|
|
43
|
+
@property(nonatomic, retain) id<IView> view;
|
|
44
|
+
|
|
45
|
+
-(id)init;
|
|
46
|
+
-(void)initializeFacade;
|
|
47
|
+
+(id<IFacade>)getInstance;
|
|
48
|
+
-(void)initializeController;
|
|
49
|
+
-(void)initializeView;
|
|
50
|
+
-(void)initializeModel;
|
|
51
|
+
|
|
52
|
+
@end
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Facade.m
|
|
3
|
+
// PureMVC_ObjectiveC
|
|
4
|
+
//
|
|
5
|
+
// PureMVC Port to ObjectiveC by Brian Knorr <brian.knorr@puremvc.org>
|
|
6
|
+
// PureMVC - Copyright(c) 2006-2008 Futurescale, Inc., Some rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#import "Facade.h"
|
|
10
|
+
#import "Model.h"
|
|
11
|
+
#import "View.h"
|
|
12
|
+
#import "Controller.h"
|
|
13
|
+
#import "Notification.h"
|
|
14
|
+
|
|
15
|
+
static id<IFacade> instance;
|
|
16
|
+
|
|
17
|
+
@implementation Facade
|
|
18
|
+
|
|
19
|
+
@synthesize model, controller, view;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Constructor.
|
|
23
|
+
*
|
|
24
|
+
* <P>
|
|
25
|
+
* This <code>IFacade</code> implementation is a Singleton,
|
|
26
|
+
* so you should not call the constructor
|
|
27
|
+
* directly, but instead call the static Singleton
|
|
28
|
+
* Factory method <code>[Facade getInstance]</code>
|
|
29
|
+
*
|
|
30
|
+
* @throws NSException if Singleton instance has already been constructed
|
|
31
|
+
*
|
|
32
|
+
*/
|
|
33
|
+
-(id)init {
|
|
34
|
+
if (instance != nil) {
|
|
35
|
+
[NSException raise:@"Facade Singleton already constructed! Use getInstance instead." format:@""];
|
|
36
|
+
} else if (self = [super init]) {
|
|
37
|
+
[self initializeFacade];
|
|
38
|
+
}
|
|
39
|
+
return self;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Initialize the Singleton <code>Facade</code> instance.
|
|
44
|
+
*
|
|
45
|
+
* <P>
|
|
46
|
+
* Called automatically by the constructor. Override in your
|
|
47
|
+
* subclass to do any subclass specific initializations. Be
|
|
48
|
+
* sure to call <code>[super initializeFacade]</code>, though.</P>
|
|
49
|
+
*/
|
|
50
|
+
-(void)initializeFacade {
|
|
51
|
+
[self initializeModel];
|
|
52
|
+
[self initializeController];
|
|
53
|
+
[self initializeView];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Facade Singleton Factory method
|
|
58
|
+
*
|
|
59
|
+
* @return the Singleton instance of the Facade
|
|
60
|
+
*/
|
|
61
|
+
+(id<IFacade>)getInstance {
|
|
62
|
+
if (instance == nil) {
|
|
63
|
+
instance = [[self alloc] init];
|
|
64
|
+
}
|
|
65
|
+
return instance;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Initialize the <code>Model</code>.
|
|
70
|
+
*
|
|
71
|
+
* <P>
|
|
72
|
+
* Called by the <code>initializeFacade</code> method.
|
|
73
|
+
* Override this method in your subclass of <code>Facade</code>
|
|
74
|
+
* if one or both of the following are true:
|
|
75
|
+
* <UL>
|
|
76
|
+
* <LI> You wish to initialize a different <code>IModel</code>.</LI>
|
|
77
|
+
* <LI> You have <code>Proxy</code>s to register with the Model that do not
|
|
78
|
+
* retrieve a reference to the Facade at construction time.</code></LI>
|
|
79
|
+
* </UL>
|
|
80
|
+
* If you don't want to initialize a different <code>IModel</code>,
|
|
81
|
+
* call <code>[super initializeModel]</code> at the beginning of your
|
|
82
|
+
* method, then register <code>Proxy</code>s.
|
|
83
|
+
* <P>
|
|
84
|
+
* Note: This method is <i>rarely</i> overridden; in practice you are more
|
|
85
|
+
* likely to use a <code>Command</code> to create and register <code>Proxy</code>s
|
|
86
|
+
* with the <code>Model</code>, since <code>Proxy</code>s with mutable data will likely
|
|
87
|
+
* need to send <code>INotification</code>s and thus will likely want to fetch a reference to
|
|
88
|
+
* the <code>Facade</code> during their construction.
|
|
89
|
+
* </P>
|
|
90
|
+
*/
|
|
91
|
+
-(void)initializeModel {
|
|
92
|
+
if (model != nil) return;
|
|
93
|
+
self.model = [Model getInstance];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Initialize the <code>Controller</code>.
|
|
98
|
+
*
|
|
99
|
+
* <P>
|
|
100
|
+
* Called by the <code>initializeFacade</code> method.
|
|
101
|
+
* Override this method in your subclass of <code>Facade</code>
|
|
102
|
+
* if one or both of the following are true:
|
|
103
|
+
* <UL>
|
|
104
|
+
* <LI> You wish to initialize a different <code>IController</code>.</LI>
|
|
105
|
+
* <LI> You have <code>Commands</code> to register with the <code>Controller</code> at startup.</code>. </LI>
|
|
106
|
+
* </UL>
|
|
107
|
+
* If you don't want to initialize a different <code>IController</code>,
|
|
108
|
+
* call <code>[super initializeController]</code> at the beginning of your
|
|
109
|
+
* method, then register <code>Command</code>s.
|
|
110
|
+
* </P>
|
|
111
|
+
*/
|
|
112
|
+
-(void)initializeController {
|
|
113
|
+
if (controller != nil) return;
|
|
114
|
+
self.controller = [Controller getInstance];
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Initialize the <code>View</code>.
|
|
119
|
+
*
|
|
120
|
+
* <P>
|
|
121
|
+
* Called by the <code>initializeFacade</code> method.
|
|
122
|
+
* Override this method in your subclass of <code>Facade</code>
|
|
123
|
+
* if one or both of the following are true:
|
|
124
|
+
* <UL>
|
|
125
|
+
* <LI> You wish to initialize a different <code>IView</code>.</LI>
|
|
126
|
+
* <LI> You have <code>Observers</code> to register with the <code>View</code></LI>
|
|
127
|
+
* </UL>
|
|
128
|
+
* If you don't want to initialize a different <code>IView</code>,
|
|
129
|
+
* call <code>[super initializeView]</code> at the beginning of your
|
|
130
|
+
* method, then register <code>IMediator</code> instances.
|
|
131
|
+
* <P>
|
|
132
|
+
* Note: This method is <i>rarely</i> overridden; in practice you are more
|
|
133
|
+
* likely to use a <code>Command</code> to create and register <code>Mediator</code>s
|
|
134
|
+
* with the <code>View</code>, since <code>IMediator</code> instances will need to send
|
|
135
|
+
* <code>INotification</code>s and thus will likely want to fetch a reference
|
|
136
|
+
* to the <code>Facade</code> during their construction.
|
|
137
|
+
* </P>
|
|
138
|
+
*/
|
|
139
|
+
-(void)initializeView {
|
|
140
|
+
if (view != nil) return;
|
|
141
|
+
self.view = [View getInstance];
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Create and send an <code>INotification</code>.
|
|
147
|
+
*
|
|
148
|
+
* <P>
|
|
149
|
+
* Keeps us from having to construct new notification
|
|
150
|
+
* instances in our implementation code.
|
|
151
|
+
* @param notificationName the name of the notiification to send
|
|
152
|
+
* @param body the body of the notification
|
|
153
|
+
* @param type the type of the notification
|
|
154
|
+
*/
|
|
155
|
+
-(void)sendNotification:(NSString *)notificationName body:(id)body type:(NSString *)type {
|
|
156
|
+
[self notifyObservers:[Notification withName:notificationName body:body type:type]];
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
-(void)sendNotification:(NSString *)notificationName {
|
|
160
|
+
[self sendNotification:notificationName body:nil type:nil];
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
-(void)sendNotification:(NSString *)notificationName body:(id)body {
|
|
164
|
+
[self sendNotification:notificationName body:body type:nil];
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
-(void)sendNotification:(NSString *)notificationName type:(NSString *)type {
|
|
168
|
+
[self sendNotification:notificationName body:nil type:type];
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Check if a Command is registered for a given Notification
|
|
173
|
+
*
|
|
174
|
+
* @param notificationName
|
|
175
|
+
* @return whether a Command is currently registered for the given <code>notificationName</code>.
|
|
176
|
+
*/
|
|
177
|
+
-(BOOL)hasCommand:(NSString *)notificationName {
|
|
178
|
+
return [controller hasCommand:notificationName];
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Check if a Mediator is registered or not
|
|
183
|
+
*
|
|
184
|
+
* @param mediatorName
|
|
185
|
+
* @return whether a Mediator is registered with the given <code>mediatorName</code>.
|
|
186
|
+
*/
|
|
187
|
+
-(BOOL)hasMediator:(NSString *)mediatorName {
|
|
188
|
+
return [view hasMediator:mediatorName];
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Check if a Proxy is registered
|
|
193
|
+
*
|
|
194
|
+
* @param proxyName
|
|
195
|
+
* @return whether a Proxy is currently registered with the given <code>proxyName</code>.
|
|
196
|
+
*/
|
|
197
|
+
-(BOOL)hasProxy:(NSString *)proxyName {
|
|
198
|
+
return [model hasProxy:proxyName];
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Notify <code>Observer</code>s.
|
|
203
|
+
* <P>
|
|
204
|
+
* This method is left public mostly for backward
|
|
205
|
+
* compatibility, and to allow you to send custom
|
|
206
|
+
* notification classes using the facade.</P>
|
|
207
|
+
*<P>
|
|
208
|
+
* Usually you should just call sendNotification
|
|
209
|
+
* and pass the parameters, never having to
|
|
210
|
+
* construct the notification yourself.</P>
|
|
211
|
+
*
|
|
212
|
+
* @param notification the <code>INotification</code> to have the <code>View</code> notify <code>Observers</code> of.
|
|
213
|
+
*/
|
|
214
|
+
-(void)notifyObservers:(id<INotification>)notification {
|
|
215
|
+
[view notifyObservers:notification];
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Register an <code>ICommand</code> with the <code>Controller</code> by Notification name.
|
|
220
|
+
*
|
|
221
|
+
* @param notificationName the name of the <code>INotification</code> to associate the <code>ICommand</code> with
|
|
222
|
+
* @param commandClassRef a reference to the Class of the <code>ICommand</code>
|
|
223
|
+
*/
|
|
224
|
+
-(void)registerCommand:(NSString *)notificationName commandClassRef:(Class)commandClassRef {
|
|
225
|
+
[controller registerCommand:notificationName commandClassRef:commandClassRef];
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Register a <code>IMediator</code> with the <code>View</code>.
|
|
230
|
+
*
|
|
231
|
+
* @param mediator a reference to the <code>IMediator</code>
|
|
232
|
+
*/
|
|
233
|
+
-(void)registerMediator:(id<IMediator>)mediator {
|
|
234
|
+
[view registerMediator:mediator];
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Register an <code>IProxy</code> with the <code>Model</code> by name.
|
|
239
|
+
*
|
|
240
|
+
* @param proxy the <code>IProxy</code> instance to be registered with the <code>Model</code>.
|
|
241
|
+
*/
|
|
242
|
+
-(void)registerProxy:(id<IProxy>)proxy {
|
|
243
|
+
[model registerProxy:proxy];
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Remove a previously registered <code>ICommand</code> to <code>INotification</code> mapping from the Controller.
|
|
248
|
+
*
|
|
249
|
+
* @param notificationName the name of the <code>INotification</code> to remove the <code>ICommand</code> mapping for
|
|
250
|
+
*/
|
|
251
|
+
-(void)removeCommand:(NSString *)notificationName {
|
|
252
|
+
[controller removeCommand:notificationName];
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Remove an <code>IMediator</code> from the <code>View</code>.
|
|
257
|
+
*
|
|
258
|
+
* @param mediatorName name of the <code>IMediator</code> to be removed.
|
|
259
|
+
* @return the <code>IMediator</code> that was removed from the <code>View</code>
|
|
260
|
+
*/
|
|
261
|
+
-(id<IMediator>)removeMediator:(NSString *)mediatorName {
|
|
262
|
+
return [view removeMediator:mediatorName];
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Remove an <code>IProxy</code> from the <code>Model</code> by name.
|
|
267
|
+
*
|
|
268
|
+
* @param proxyName the <code>IProxy</code> to remove from the <code>Model</code>.
|
|
269
|
+
* @return the <code>IProxy</code> that was removed from the <code>Model</code>
|
|
270
|
+
*/
|
|
271
|
+
-(id<IProxy>)removeProxy:(NSString *)proxyName {
|
|
272
|
+
return [model removeProxy:proxyName];
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Retrieve an <code>IMediator</code> from the <code>View</code>.
|
|
277
|
+
*
|
|
278
|
+
* @param mediatorName
|
|
279
|
+
* @return the <code>IMediator</code> previously registered with the given <code>mediatorName</code>.
|
|
280
|
+
*/
|
|
281
|
+
-(id<IMediator>)retrieveMediator:(NSString *)mediatorName {
|
|
282
|
+
return [view retrieveMediator:mediatorName];
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Retrieve an <code>IProxy</code> from the <code>Model</code> by name.
|
|
287
|
+
*
|
|
288
|
+
* @param proxyName the name of the proxy to be retrieved.
|
|
289
|
+
* @return the <code>IProxy</code> instance previously registered with the given <code>proxyName</code>.
|
|
290
|
+
*/
|
|
291
|
+
-(id<IProxy>)retrieveProxy:(NSString *)proxyName {
|
|
292
|
+
return [model retrieveProxy:proxyName];
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
-(void)dealloc {
|
|
296
|
+
self.model = nil;
|
|
297
|
+
self.controller = nil;
|
|
298
|
+
self.view = nil;
|
|
299
|
+
[(id)instance release];
|
|
300
|
+
instance = nil;
|
|
301
|
+
[super dealloc];
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
@end
|