appjam 0.1.0.pre4
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Eiffel Q
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
= appjam
|
2
|
+
|
3
|
+
appjam is iphone app generator, generate iphone app skeleton based on pure mvc framework.
|
4
|
+
|
5
|
+
== Usage
|
6
|
+
|
7
|
+
run command below in your favorite shell, appjam will generate your iphone app skeleton.
|
8
|
+
|
9
|
+
$ gem install appjam
|
10
|
+
|
11
|
+
$ appjam User # Model name(like User)
|
12
|
+
|
13
|
+
== Contributing to appjam
|
14
|
+
|
15
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
16
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
17
|
+
* Fork the project
|
18
|
+
* Start a feature/bugfix branch
|
19
|
+
* Commit and push until you are happy with your contribution
|
20
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
21
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
22
|
+
|
23
|
+
== Copyright
|
24
|
+
|
25
|
+
Copyright (c) 2011 Eiffel Q. See LICENSE.txt for
|
26
|
+
further details.
|
27
|
+
|
data/bin/appjam
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems' unless defined?(Gem)
|
3
|
+
|
4
|
+
lib_dir = File.expand_path(File.join(File.dirname(__FILE__),'..','lib'))
|
5
|
+
unless $LOAD_PATH.include?(lib_dir)
|
6
|
+
$LOAD_PATH << lib_dir
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'appjam'
|
10
|
+
require File.expand_path(File.dirname(__FILE__) + '/../lib/appjam/generators/app')
|
11
|
+
|
12
|
+
begin
|
13
|
+
Appjam::Generators::App.start(ARGV)
|
14
|
+
rescue => e
|
15
|
+
STDERR.puts "Error: #{e}\n"
|
16
|
+
exit -1
|
17
|
+
end
|
data/lib/appjam.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'appjam/version.rb'
|
2
|
+
require 'active_support'
|
3
|
+
|
4
|
+
module Appjam
|
5
|
+
##
|
6
|
+
# This method return the correct location of mvc-gen bin or
|
7
|
+
# exec it using Kernel#system with the given args
|
8
|
+
#
|
9
|
+
def self.bin_gen(*args)
|
10
|
+
@_mvc_gen_bin ||= [IphoneMvc.ruby_command, File.expand_path("../bin/appjam", __FILE__)]
|
11
|
+
args.empty? ? @_mvc_gen_bin : system(args.unshift(@_mvc_gen_bin).join(" "))
|
12
|
+
end
|
13
|
+
|
14
|
+
##
|
15
|
+
# This module it's used for register generators
|
16
|
+
#
|
17
|
+
module Generators
|
18
|
+
|
19
|
+
DEV_PATH = File.expand_path("../../", File.dirname(__FILE__))
|
20
|
+
|
21
|
+
class << self
|
22
|
+
|
23
|
+
##
|
24
|
+
# Here we store our generators paths
|
25
|
+
#
|
26
|
+
def load_paths
|
27
|
+
@_files ||= []
|
28
|
+
end
|
29
|
+
|
30
|
+
##
|
31
|
+
# Return a ordered list of task with their class
|
32
|
+
#
|
33
|
+
def mappings
|
34
|
+
@_mappings ||= ActiveSupport::OrderedHash.new
|
35
|
+
end
|
36
|
+
|
37
|
+
##
|
38
|
+
# Gloabl add a new generator class
|
39
|
+
#
|
40
|
+
def add_generator(name, klass)
|
41
|
+
mappings[name] = klass
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end # Generators
|
45
|
+
end # IphoneMvc
|
46
|
+
|
47
|
+
##
|
48
|
+
# We add our generators to Appjam::Genererator
|
49
|
+
#
|
50
|
+
Appjam::Generators.load_paths << Dir[File.dirname(__FILE__) + '/appjam/generators/app.rb']
|
@@ -0,0 +1,18 @@
|
|
1
|
+
//
|
2
|
+
// ContactsAppDelegate.h
|
3
|
+
// Contacts
|
4
|
+
//
|
5
|
+
// Created by eiffel on 11-2-16.
|
6
|
+
// Copyright 2011 Redsafi. All rights reserved.
|
7
|
+
//
|
8
|
+
|
9
|
+
#import <UIKit/UIKit.h>
|
10
|
+
|
11
|
+
@interface ContactsAppDelegate : NSObject <UIApplicationDelegate> {
|
12
|
+
UIWindow *window;
|
13
|
+
}
|
14
|
+
|
15
|
+
@property (nonatomic, retain) IBOutlet UIWindow *window;
|
16
|
+
|
17
|
+
@end
|
18
|
+
|
@@ -0,0 +1,88 @@
|
|
1
|
+
//
|
2
|
+
// ContactsAppDelegate.m
|
3
|
+
// Contacts
|
4
|
+
//
|
5
|
+
// Created by eiffel on 11-2-16.
|
6
|
+
// Copyright 2011 Redsafi. All rights reserved.
|
7
|
+
//
|
8
|
+
|
9
|
+
#import "ContactsAppDelegate.h"
|
10
|
+
#import "ApplicationFacade.h"
|
11
|
+
#import "Contacts.h"
|
12
|
+
|
13
|
+
@implementation ContactsAppDelegate
|
14
|
+
|
15
|
+
@synthesize window;
|
16
|
+
|
17
|
+
|
18
|
+
#pragma mark -
|
19
|
+
#pragma mark Application lifecycle
|
20
|
+
|
21
|
+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
22
|
+
|
23
|
+
// Override point for customization after application launch.
|
24
|
+
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
|
25
|
+
Contacts *contacts = [[[Contacts alloc] initWithFrame:[window frame]] autorelease];
|
26
|
+
[[ApplicationFacade getInstance] startup:contacts];
|
27
|
+
[window addSubview:contacts];
|
28
|
+
[window makeKeyAndVisible];
|
29
|
+
|
30
|
+
return YES;
|
31
|
+
}
|
32
|
+
|
33
|
+
|
34
|
+
- (void)applicationWillResignActive:(UIApplication *)application {
|
35
|
+
/*
|
36
|
+
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
37
|
+
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
|
38
|
+
*/
|
39
|
+
}
|
40
|
+
|
41
|
+
|
42
|
+
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
43
|
+
/*
|
44
|
+
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
|
45
|
+
If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
|
46
|
+
*/
|
47
|
+
}
|
48
|
+
|
49
|
+
|
50
|
+
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
51
|
+
/*
|
52
|
+
Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
|
53
|
+
*/
|
54
|
+
}
|
55
|
+
|
56
|
+
|
57
|
+
- (void)applicationDidBecomeActive:(UIApplication *)application {
|
58
|
+
/*
|
59
|
+
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
60
|
+
*/
|
61
|
+
}
|
62
|
+
|
63
|
+
|
64
|
+
- (void)applicationWillTerminate:(UIApplication *)application {
|
65
|
+
/*
|
66
|
+
Called when the application is about to terminate.
|
67
|
+
See also applicationDidEnterBackground:.
|
68
|
+
*/
|
69
|
+
}
|
70
|
+
|
71
|
+
|
72
|
+
#pragma mark -
|
73
|
+
#pragma mark Memory management
|
74
|
+
|
75
|
+
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
|
76
|
+
/*
|
77
|
+
Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
|
78
|
+
*/
|
79
|
+
}
|
80
|
+
|
81
|
+
|
82
|
+
- (void)dealloc {
|
83
|
+
[window release];
|
84
|
+
[super dealloc];
|
85
|
+
}
|
86
|
+
|
87
|
+
|
88
|
+
@end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
//
|
2
|
+
// Controller.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 "IController.h"
|
11
|
+
#import "IView.h"
|
12
|
+
|
13
|
+
/**
|
14
|
+
* A Singleton <code>IController</code> implementation.
|
15
|
+
*
|
16
|
+
* <P>
|
17
|
+
* In PureMVC, the <code>Controller</code> class follows the
|
18
|
+
* 'Command and Controller' strategy, and assumes these
|
19
|
+
* responsibilities:
|
20
|
+
* <UL>
|
21
|
+
* <LI> Remembering which <code>ICommand</code>s
|
22
|
+
* are intended to handle which <code>INotifications</code>.</LI>
|
23
|
+
* <LI> Registering itself as an <code>IObserver</code> with
|
24
|
+
* the <code>View</code> for each <code>INotification</code>
|
25
|
+
* that it has an <code>ICommand</code> mapping for.</LI>
|
26
|
+
* <LI> Creating a new instance of the proper <code>ICommand</code>
|
27
|
+
* to handle a given <code>INotification</code> when notified by the <code>View</code>.</LI>
|
28
|
+
* <LI> Calling the <code>ICommand</code>'s <code>execute</code>
|
29
|
+
* method, passing in the <code>INotification</code>.</LI>
|
30
|
+
* </UL>
|
31
|
+
*
|
32
|
+
* <P>
|
33
|
+
* Your application must register <code>ICommands</code> with the
|
34
|
+
* Controller.
|
35
|
+
* <P>
|
36
|
+
* The simplest way is to subclass </code>Facade</code>,
|
37
|
+
* and use its <code>initializeController</code> method to add your
|
38
|
+
* registrations.
|
39
|
+
*
|
40
|
+
* @see View, Observer, Notification, SimpleCommand, MacroCommand
|
41
|
+
*/
|
42
|
+
@interface Controller : NSObject <IController> {
|
43
|
+
NSMutableDictionary *commandMap;
|
44
|
+
id<IView> view;
|
45
|
+
}
|
46
|
+
|
47
|
+
@property(nonatomic, retain) NSMutableDictionary *commandMap;
|
48
|
+
@property(nonatomic, retain) id<IView> view;
|
49
|
+
|
50
|
+
-(id)init;
|
51
|
+
-(void)initializeController;
|
52
|
+
+(id<IController>)getInstance;
|
53
|
+
|
54
|
+
@end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
//
|
2
|
+
// Controller.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 "Controller.h"
|
10
|
+
#import "View.h"
|
11
|
+
#import "IObserver.h"
|
12
|
+
#import "Observer.h"
|
13
|
+
#import "ICommand.h"
|
14
|
+
|
15
|
+
static id<IController> instance;
|
16
|
+
|
17
|
+
@implementation Controller
|
18
|
+
|
19
|
+
@synthesize commandMap, view;
|
20
|
+
|
21
|
+
/**
|
22
|
+
* Constructor.
|
23
|
+
*
|
24
|
+
* <P>
|
25
|
+
* This <code>IController</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>[Controller 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:@"Controller Singleton already constructed! Use getInstance instead." format:@""];
|
36
|
+
} else if (self = [super init]) {
|
37
|
+
self.commandMap = [NSMutableDictionary dictionary];
|
38
|
+
[self initializeController];
|
39
|
+
}
|
40
|
+
return self;
|
41
|
+
}
|
42
|
+
|
43
|
+
/**
|
44
|
+
* Initialize the Singleton <code>Controller</code> instance.
|
45
|
+
*
|
46
|
+
* <P>Called automatically by the constructor.</P>
|
47
|
+
*
|
48
|
+
* <P>Note that if you are using a subclass of <code>View</code>
|
49
|
+
* in your application, you should <i>also</i> subclass <code>Controller</code>
|
50
|
+
* and override the <code>initializeController</code> method in the
|
51
|
+
* following way:</P>
|
52
|
+
*
|
53
|
+
* @code
|
54
|
+
* // ensure that the Controller is talking to my IView implementation
|
55
|
+
* -(void)initializeController {
|
56
|
+
* self.view = [MyView getInstance];
|
57
|
+
* }
|
58
|
+
* @endcode
|
59
|
+
*
|
60
|
+
* @return void
|
61
|
+
*/
|
62
|
+
-(void)initializeController {
|
63
|
+
self.view = [View getInstance];
|
64
|
+
}
|
65
|
+
|
66
|
+
/**
|
67
|
+
* <code>Controller</code> Singleton Factory method.
|
68
|
+
*
|
69
|
+
* @return the Singleton instance of <code>Controller</code>
|
70
|
+
*/
|
71
|
+
+(id<IController>)getInstance {
|
72
|
+
if (instance == nil) {
|
73
|
+
instance = [[self alloc] init];
|
74
|
+
}
|
75
|
+
return instance;
|
76
|
+
}
|
77
|
+
|
78
|
+
/**
|
79
|
+
* If an <code>ICommand</code> has previously been registered
|
80
|
+
* to handle a the given <code>INotification</code>, then it is executed.
|
81
|
+
*
|
82
|
+
* @param notification an <code>INotification</code>
|
83
|
+
*/
|
84
|
+
-(void)executeCommand:(id<INotification>)notification {
|
85
|
+
Class commandClassRef = [commandMap objectForKey:[notification name]];
|
86
|
+
if (commandClassRef == nil) {
|
87
|
+
return;
|
88
|
+
}
|
89
|
+
[[[[commandClassRef alloc] init] autorelease] execute:notification];
|
90
|
+
}
|
91
|
+
|
92
|
+
/**
|
93
|
+
* Check if a Command is registered for a given Notification
|
94
|
+
*
|
95
|
+
* @param notificationName
|
96
|
+
* @return whether a Command is currently registered for the given <code>notificationName</code>.
|
97
|
+
*/
|
98
|
+
-(BOOL)hasCommand:(NSString *)notificationName {
|
99
|
+
return [commandMap objectForKey:notificationName] != nil;
|
100
|
+
}
|
101
|
+
|
102
|
+
/**
|
103
|
+
* Register a particular <code>ICommand</code> class as the handler
|
104
|
+
* for a particular <code>INotification</code>.
|
105
|
+
*
|
106
|
+
* <P>
|
107
|
+
* If an <code>ICommand</code> has already been registered to
|
108
|
+
* handle <code>INotification</code>s with this name, it is no longer
|
109
|
+
* used, the new <code>ICommand</code> is used instead.</P>
|
110
|
+
*
|
111
|
+
* The Observer for the new ICommand is only created if this the
|
112
|
+
* first time an ICommand has been regisered for this Notification name.
|
113
|
+
*
|
114
|
+
* @param notificationName the name of the <code>INotification</code>
|
115
|
+
* @param commandClassRef the <code>Class</code> of the <code>ICommand</code>
|
116
|
+
*/
|
117
|
+
-(void)registerCommand:(NSString *)notificationName commandClassRef:(Class)commandClassRef {
|
118
|
+
if ([commandMap objectForKey:notificationName] == nil) {
|
119
|
+
id<IObserver> observer = [Observer withNotifyMethod:@selector(executeCommand:) notifyContext:self];
|
120
|
+
[view registerObserver:notificationName observer:observer];
|
121
|
+
}
|
122
|
+
[commandMap setObject:commandClassRef forKey:notificationName];
|
123
|
+
}
|
124
|
+
|
125
|
+
/**
|
126
|
+
* Remove a previously registered <code>ICommand</code> to <code>INotification</code> mapping.
|
127
|
+
*
|
128
|
+
* @param notificationName the name of the <code>INotification</code> to remove the <code>ICommand</code> mapping for
|
129
|
+
*/
|
130
|
+
-(void)removeCommand:(NSString *)notificationName {
|
131
|
+
if ([self hasCommand:notificationName]) {
|
132
|
+
[view removeObserver:notificationName notifyContext:self];
|
133
|
+
[commandMap removeObjectForKey:notificationName];
|
134
|
+
}
|
135
|
+
}
|
136
|
+
|
137
|
+
-(void)dealloc {
|
138
|
+
self.commandMap = nil;
|
139
|
+
self.view = nil;
|
140
|
+
[(id)instance release];
|
141
|
+
instance = nil;
|
142
|
+
[super dealloc];
|
143
|
+
}
|
144
|
+
|
145
|
+
@end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
//
|
2
|
+
// Model.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 "IModel.h"
|
11
|
+
|
12
|
+
/**
|
13
|
+
* A Singleton <code>IModel</code> implementation.
|
14
|
+
*
|
15
|
+
* <P>
|
16
|
+
* In PureMVC, the <code>Model</code> class provides
|
17
|
+
* access to model objects (Proxies) by named lookup.
|
18
|
+
*
|
19
|
+
* <P>
|
20
|
+
* The <code>Model</code> assumes these responsibilities:</P>
|
21
|
+
*
|
22
|
+
* <UL>
|
23
|
+
* <LI>Maintain a cache of <code>IProxy</code> instances.</LI>
|
24
|
+
* <LI>Provide methods for registering, retrieving, and removing
|
25
|
+
* <code>IProxy</code> instances.</LI>
|
26
|
+
* </UL>
|
27
|
+
*
|
28
|
+
* <P>
|
29
|
+
* Your application must register <code>IProxy</code> instances
|
30
|
+
* with the <code>Model</code>. Typically, you use an
|
31
|
+
* <code>ICommand</code> to create and register <code>IProxy</code>
|
32
|
+
* instances once the <code>Facade</code> has initialized the Core
|
33
|
+
* actors.</p>
|
34
|
+
*
|
35
|
+
* @see Proxy, IProxy
|
36
|
+
*/
|
37
|
+
@interface Model : NSObject <IModel> {
|
38
|
+
NSMutableDictionary *proxyMap;
|
39
|
+
}
|
40
|
+
|
41
|
+
@property(nonatomic, retain) NSMutableDictionary *proxyMap;
|
42
|
+
|
43
|
+
-(id)init;
|
44
|
+
-(void)initializeModel;
|
45
|
+
+(id<IModel>)getInstance;
|
46
|
+
|
47
|
+
@end
|