Permalink
Browse files

Refactored the code, introducing a common abstract class for processo…

…rs, with a static factory method
  • Loading branch information...
1 parent 6f6488d commit 267d21a475e692cd68e78c25a00f2e0373fef433 Adrian Kosmaczewski committed Mar 16, 2009
Showing with 147 additions and 82 deletions.
  1. +2 −35 NibProcessor.m
  2. +30 −0 Processors/Processor.h
  3. +106 −0 Processors/Processor.m
  4. +2 −14 Processors/UIViewProcessor.h
  5. +1 −33 Processors/UIViewProcessor.m
  6. +6 −0 nib2objc.xcodeproj/project.pbxproj
View
@@ -7,23 +7,8 @@
//
#import "NibProcessor.h"
+#import "Processor.h"
#import "UIViewProcessor.h"
-#import "UITextFieldProcessor.h"
-#import "UIProgressViewProcessor.h"
-#import "UISwitchProcessor.h"
-#import "UISliderProcessor.h"
-#import "UILabelProcessor.h"
-#import "UIActivityIndicatorViewProcessor.h"
-#import "UIPageControlProcessor.h"
-#import "UIButtonProcessor.h"
-#import "UISegmentedControlProcessor.h"
-#import "UIScrollViewProcessor.h"
-#import "UITableViewProcessor.h"
-#import "UIImageViewProcessor.h"
-#import "UITextViewProcessor.h"
-#import "UIPickerViewProcessor.h"
-#import "UIWebViewProcessor.h"
-#import "UITableViewCellProcessor.h"
@interface NibProcessor (Private)
@@ -127,25 +112,7 @@ - (void)process
id object = [nibObjects objectForKey:key];
NSString *klass = [object objectForKey:@"class"];
- UIViewProcessor *processor = nil;
-
- if ([klass isEqualToString:@"IBUIView"]) processor = [[UIViewProcessor alloc] init];
- else if ([klass isEqualToString:@"IBUITextField"]) processor = [[UITextFieldProcessor alloc] init];
- else if ([klass isEqualToString:@"IBUIProgressView"]) processor = [[UIProgressViewProcessor alloc] init];
- else if ([klass isEqualToString:@"IBUISwitch"]) processor = [[UISwitchProcessor alloc] init];
- else if ([klass isEqualToString:@"IBUISlider"]) processor = [[UISliderProcessor alloc] init];
- else if ([klass isEqualToString:@"IBUILabel"]) processor = [[UILabelProcessor alloc] init];
- else if ([klass isEqualToString:@"IBUIActivityIndicatorView"]) processor = [[UIActivityIndicatorViewProcessor alloc] init];
- else if ([klass isEqualToString:@"IBUIPageControl"]) processor = [[UIPageControlProcessor alloc] init];
- else if ([klass isEqualToString:@"IBUIButton"]) processor = [[UIButtonProcessor alloc] init];
- else if ([klass isEqualToString:@"IBUISegmentedControl"]) processor = [[UISegmentedControlProcessor alloc] init];
- else if ([klass isEqualToString:@"IBUIScrollView"]) processor = [[UIScrollViewProcessor alloc] init];
- else if ([klass isEqualToString:@"IBUITableView"]) processor = [[UITableViewProcessor alloc] init];
- else if ([klass isEqualToString:@"IBUIImageView"]) processor = [[UIImageViewProcessor alloc] init];
- else if ([klass isEqualToString:@"IBUITextView"]) processor = [[UITextViewProcessor alloc] init];
- else if ([klass isEqualToString:@"IBUIPickerView"]) processor = [[UIPickerViewProcessor alloc] init];
- else if ([klass isEqualToString:@"IBUIWebView"]) processor = [[UIWebViewProcessor alloc] init];
- else if ([klass isEqualToString:@"IBUITableViewCell"]) processor = [[UITableViewCellProcessor alloc] init];
+ UIViewProcessor *processor = [Processor processorForClass:klass];
if (processor == nil)
{
View
@@ -0,0 +1,30 @@
+//
+// Processor.h
+// nib2objc
+//
+// Created by Adrian on 3/16/09.
+// Copyright 2009 __MyCompanyName__. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+@class UIViewProcessor;
+
+@interface Processor : NSObject
+{
+@protected
+ NSMutableDictionary *output;
+@private
+ NSDictionary *input;
+}
+
+@property (nonatomic, readonly) NSDictionary *input;
+
++ (UIViewProcessor *)processorForClass:(NSString *)klass;
+
+- (NSDictionary *)processObject:(NSDictionary *)object;
+- (void)processKey:(id)item value:(id)value;
+- (NSString *)frameString;
+
+
+@end
View
@@ -0,0 +1,106 @@
+//
+// Processor.m
+// nib2objc
+//
+// Created by Adrian on 3/16/09.
+// Copyright 2009 __MyCompanyName__. All rights reserved.
+//
+
+#import "Processor.h"
+
+#import "NSString+Nib2ObjcExtensions.h"
+#import "NSNumber+Nib2ObjcExtensions.h"
+
+#import "UIViewProcessor.h"
+#import "UITextFieldProcessor.h"
+#import "UIProgressViewProcessor.h"
+#import "UISwitchProcessor.h"
+#import "UISliderProcessor.h"
+#import "UILabelProcessor.h"
+#import "UIActivityIndicatorViewProcessor.h"
+#import "UIPageControlProcessor.h"
+#import "UIButtonProcessor.h"
+#import "UISegmentedControlProcessor.h"
+#import "UIScrollViewProcessor.h"
+#import "UITableViewProcessor.h"
+#import "UIImageViewProcessor.h"
+#import "UITextViewProcessor.h"
+#import "UIPickerViewProcessor.h"
+#import "UIWebViewProcessor.h"
+#import "UITableViewCellProcessor.h"
+
+@interface Processor (Protected)
+
+- (NSString *)getProcessedClassName;
+- (NSString *)constructorString;
+
+@end
+
+@implementation Processor
+
+@synthesize input;
+
++ (UIViewProcessor *)processorForClass:(NSString *)klass
+{
+ UIViewProcessor *processor = nil;
+
+ if ([klass isEqualToString:@"IBUIView"]) processor = [[UIViewProcessor alloc] init];
+ else if ([klass isEqualToString:@"IBUITextField"]) processor = [[UITextFieldProcessor alloc] init];
+ else if ([klass isEqualToString:@"IBUIProgressView"]) processor = [[UIProgressViewProcessor alloc] init];
+ else if ([klass isEqualToString:@"IBUISwitch"]) processor = [[UISwitchProcessor alloc] init];
+ else if ([klass isEqualToString:@"IBUISlider"]) processor = [[UISliderProcessor alloc] init];
+ else if ([klass isEqualToString:@"IBUILabel"]) processor = [[UILabelProcessor alloc] init];
+ else if ([klass isEqualToString:@"IBUIActivityIndicatorView"]) processor = [[UIActivityIndicatorViewProcessor alloc] init];
+ else if ([klass isEqualToString:@"IBUIPageControl"]) processor = [[UIPageControlProcessor alloc] init];
+ else if ([klass isEqualToString:@"IBUIButton"]) processor = [[UIButtonProcessor alloc] init];
+ else if ([klass isEqualToString:@"IBUISegmentedControl"]) processor = [[UISegmentedControlProcessor alloc] init];
+ else if ([klass isEqualToString:@"IBUIScrollView"]) processor = [[UIScrollViewProcessor alloc] init];
+ else if ([klass isEqualToString:@"IBUITableView"]) processor = [[UITableViewProcessor alloc] init];
+ else if ([klass isEqualToString:@"IBUIImageView"]) processor = [[UIImageViewProcessor alloc] init];
+ else if ([klass isEqualToString:@"IBUITextView"]) processor = [[UITextViewProcessor alloc] init];
+ else if ([klass isEqualToString:@"IBUIPickerView"]) processor = [[UIPickerViewProcessor alloc] init];
+ else if ([klass isEqualToString:@"IBUIWebView"]) processor = [[UIWebViewProcessor alloc] init];
+ else if ([klass isEqualToString:@"IBUITableViewCell"]) processor = [[UITableViewCellProcessor alloc] init];
+
+ return processor;
+}
+
+- (void)dealloc
+{
+ [output release];
+ [input release];
+ [super dealloc];
+}
+
+#pragma mark -
+#pragma mark Public method
+
+- (NSDictionary *)processObject:(NSDictionary *)object
+{
+ input = [object retain];
+ [output release];
+ output = [[NSMutableDictionary alloc] init];
+ [output setObject:[self constructorString] forKey:@"constructor"];
+ [output setObject:[self frameString] forKey:@"frame"];
+
+ for (id item in input)
+ {
+ id value = [input objectForKey:item];
+ [self processKey:item value:value];
+ }
+
+ return output;
+}
+
+- (void)processKey:(id)item value:(id)value
+{
+ // Overridden in subclasses
+}
+
+- (NSString *)frameString
+{
+ // Overridden in subclasses
+ return nil;
+}
+
+@end
@@ -6,20 +6,8 @@
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
-#import <Cocoa/Cocoa.h>
+#import "Processor.h"
-@interface UIViewProcessor : NSObject
-{
-@protected
- NSMutableDictionary *output;
-@private
- NSDictionary *input;
-}
-
-@property (nonatomic, readonly) NSDictionary *input;
-
-- (NSDictionary *)processObject:(NSDictionary *)object;
-- (void)processKey:(id)item value:(id)value;
-- (NSString *)frameString;
+@interface UIViewProcessor : Processor
@end
@@ -10,45 +10,13 @@
#import "NSString+Nib2ObjcExtensions.h"
#import "NSNumber+Nib2ObjcExtensions.h"
-@interface UIViewProcessor (Protected)
-
-- (NSString *)getProcessedClassName;
-- (NSString *)constructorString;
-
-@end
-
-
@implementation UIViewProcessor
-@synthesize input;
-
- (void)dealloc
{
- [output release];
- [input release];
[super dealloc];
}
-#pragma mark -
-#pragma mark Public method
-
-- (NSDictionary *)processObject:(NSDictionary *)object
-{
- input = [object retain];
- [output release];
- output = [[NSMutableDictionary alloc] init];
- [output setObject:[self constructorString] forKey:@"constructor"];
- [output setObject:[self frameString] forKey:@"frame"];
-
- for (id item in input)
- {
- id value = [input objectForKey:item];
- [self processKey:item value:value];
- }
-
- return output;
-}
-
#pragma mark -
#pragma mark Private methods
@@ -59,7 +27,7 @@ - (NSString *)getProcessedClassName
- (NSString *)frameString
{
- NSString *rect = [NSString rectStringFromPoint:[input objectForKey:@"frameOrigin"] size:[input objectForKey:@"frameSize"]];
+ NSString *rect = [NSString rectStringFromPoint:[self.input objectForKey:@"frameOrigin"] size:[self.input objectForKey:@"frameSize"]];
return rect;
}
@@ -20,6 +20,7 @@
3A0517EF0F6BFF510049FCB8 /* UIPageControlProcessor.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A0517EE0F6BFF510049FCB8 /* UIPageControlProcessor.m */; };
3A0517FD0F6C00590049FCB8 /* UIButtonProcessor.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A0517FC0F6C00590049FCB8 /* UIButtonProcessor.m */; };
3A0518430F6C0B380049FCB8 /* UISegmentedControlProcessor.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A0518420F6C0B380049FCB8 /* UISegmentedControlProcessor.m */; };
+ 3A672E4D0F6E949000715857 /* Processor.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A672E4C0F6E949000715857 /* Processor.m */; };
3A8897CB0F6E7C4D00A537A3 /* UITableViewCellProcessor.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A8897CA0F6E7C4D00A537A3 /* UITableViewCellProcessor.m */; };
3A927CC50F6D55BD00C7C3B1 /* UITableViewProcessor.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A927CC40F6D55BD00C7C3B1 /* UITableViewProcessor.m */; };
3A927CF20F6D5BA700C7C3B1 /* UIImageViewProcessor.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A927CF10F6D5BA700C7C3B1 /* UIImageViewProcessor.m */; };
@@ -75,6 +76,8 @@
3A0517FC0F6C00590049FCB8 /* UIButtonProcessor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UIButtonProcessor.m; sourceTree = "<group>"; };
3A0518410F6C0B380049FCB8 /* UISegmentedControlProcessor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UISegmentedControlProcessor.h; sourceTree = "<group>"; };
3A0518420F6C0B380049FCB8 /* UISegmentedControlProcessor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UISegmentedControlProcessor.m; sourceTree = "<group>"; };
+ 3A672E4B0F6E949000715857 /* Processor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Processor.h; sourceTree = "<group>"; };
+ 3A672E4C0F6E949000715857 /* Processor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Processor.m; sourceTree = "<group>"; };
3A8897C90F6E7C4D00A537A3 /* UITableViewCellProcessor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UITableViewCellProcessor.h; sourceTree = "<group>"; };
3A8897CA0F6E7C4D00A537A3 /* UITableViewCellProcessor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UITableViewCellProcessor.m; sourceTree = "<group>"; };
3A927CC30F6D55BD00C7C3B1 /* UITableViewProcessor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UITableViewProcessor.h; sourceTree = "<group>"; };
@@ -173,6 +176,8 @@
3AD51EDA0F6AF0B9002D7519 /* Processors */ = {
isa = PBXGroup;
children = (
+ 3A672E4B0F6E949000715857 /* Processor.h */,
+ 3A672E4C0F6E949000715857 /* Processor.m */,
3AD51EDB0F6AF0D1002D7519 /* UIViewProcessor.h */,
3AD51EDC0F6AF0D1002D7519 /* UIViewProcessor.m */,
3A0515C80F6BBA140049FCB8 /* UIControlProcessor.h */,
@@ -279,6 +284,7 @@
3A927D1F0F6D60F000C7C3B1 /* UIPickerViewProcessor.m in Sources */,
3A927D2D0F6D61E200C7C3B1 /* UIWebViewProcessor.m in Sources */,
3A8897CB0F6E7C4D00A537A3 /* UITableViewCellProcessor.m in Sources */,
+ 3A672E4D0F6E949000715857 /* Processor.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

0 comments on commit 267d21a

Please sign in to comment.