Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new templates to support ARC-compatible IOS pico bindings #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/java/com/leansoft/mxjc/Driver.java
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,10 @@ public int parseArgument(String[] args, int i) throws BadCommandLineException {
module = ModuleName.PICO;
return 1;
}
if (args[i].equals("-picoarc")) {
module = ModuleName.PICOARC;
return 1;
}

if (args[i].equals("-prefix")) {
prefix = super.requireArgument("-prefix", args, ++i);
Expand Down
Binary file not shown.
2 changes: 2 additions & 0 deletions src/main/java/com/leansoft/mxjc/module/ModuleFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public static ClientModule getModule(ModuleName name) {
module = new NanoClientModule();
} else if (name == ModuleName.PICO) {
module = new PicoClientModule();
}else if (name == ModuleName.PICOARC) {
module = new PicoClientModule().setUseARC(true);
}
return module;
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/leansoft/mxjc/module/ModuleName.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ public enum ModuleName {

NANO("nano"), // android java
MICRO("micro"), // php
PICO("pico"); // ios objective-c
PICO("pico"), // ios objective-c
PICOARC("picoarc"); // ios objective-c

private final String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class PicoClientModule extends AbstractClientModule {
private URL enumDeclarationTemplate;
private URL enumDefinitionTemplate;
private URL commonHeaderTemplate;
private boolean useARC = false;

@Override
public ModuleName getName() {
Expand Down Expand Up @@ -240,7 +241,12 @@ private void convertType(TypeInfo type) {

@Override
protected URL getTemplateURL(String template) throws XjcModuleException {
URL url = PicoClientModule.class.getResource("template/" + template);
URL url = PicoClientModule.class.getResource("template/" + template);
if(useARC){
debug("Using ARC templates.");
url = PicoClientModule.class.getResource("arc/template/" + template);
}

if (url == null) {
throw new XjcModuleException("Fail to load required template file : "
+ template);
Expand All @@ -249,5 +255,20 @@ protected URL getTemplateURL(String template) throws XjcModuleException {
return url;
}

/**
* @return the useARC
*/
public boolean shouldUseARC() {
return useARC;
}

/**
* @param useARC the useARC to set
*/
public PicoClientModule setUseARC(boolean useARC) {
this.useARC = useARC;
return this;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
[#ftl]
[#--template for the client-side complex/simple type interface.--]
// Generated by xsd compiler for ios/objective-c
// DO NOT CHANGE!

#import <Foundation/Foundation.h>
#import "${clazz.name}.h"
[#list fieldClassImports as import]
#import "${import}.h"
[/#list]

@implementation ${clazz.name}

[#list clazz.fields as field]
@synthesize ${field.name};
[/#list]

// class meta-data method
// note: this method is only for internal use, DO NOT CHANGE!
+(PicoClassSchema *)getClassMetaData {
[#if clazz.rootElementAnnotation?? && clazz.rootElementAnnotation.parameterProvided]
PicoClassSchema *cs = [[PicoClassSchema alloc] initWithXmlName:@"${clazz.rootElementAnnotation.name}" nsUri:@"${clazz.rootElementAnnotation.namespace}"];
return cs;
[#else]
return nil;
[/#if]
}

// property meta-data method
// note: this method is only for internal use, DO NOT CHANGE!
+(NSMutableDictionary *)getPropertyMetaData {
NSMutableDictionary *map = [NSMutableDictionary dictionary];
@autoreleasepool {
[#assign flag=false]

[#list clazz.fields as field]
[#assign xmlName = field.name]
[#if field.elementAnnotation?? && field.elementAnnotation.parameterProvided]
[#assign xmlName = field.elementAnnotation.name]
[#elseif field.attributeAnnotation?? && field.attributeAnnotation.parameterProvided]
[#assign xmlName = field.attributeAnnotation.name]
[/#if]
[#if field.attribute][#-- map to xml attribute --]
[#if !flag]
[#assign flag=true]
PicoPropertySchema *ps = nil;
[/#if]
ps = [[PicoPropertySchema alloc] initWithKind:PICO_KIND_ATTRIBUTE xmlName:@"${xmlName}" propertyName:@"${field.name}" type:${field.type.name} clazz:[#if !field.type.primitive][${field.type.fullName} class][#else]nil[/#if]];
[map setObject:ps forKey:@"${field.name}"];
[#elseif field.element][#-- map to xml element --]
[#if field.type.collection && (field.type.typeParameters)?? && field.type.typeParameters?size > 0]
[#assign type = field.type.typeParameters?first]
[#if !flag]
[#assign flag=true]
PicoPropertySchema *ps = nil;
[/#if]
ps = [[PicoPropertySchema alloc] initWithKind:PICO_KIND_ELEMENT_ARRAY xmlName:@"${xmlName}" propertyName:@"${field.name}" type:${type.name} clazz:[#if !type.primitive][${type.fullName} class][#else]nil[/#if]];
[map setObject:ps forKey:@"${field.name}"];
[#else]
[#if !flag]
[#assign flag=true]
PicoPropertySchema *ps = nil;
[/#if]
ps = [[PicoPropertySchema alloc] initWithKind:PICO_KIND_ELEMENT xmlName:@"${xmlName}" propertyName:@"${field.name}" type:${field.type.name} clazz:[#if !field.type.primitive][${field.type.fullName} class][#else]nil[/#if]];
[map setObject:ps forKey:@"${field.name}"];
[/#if]
[#elseif field.value][#-- map to xml value --]
[#if !flag]
[#assign flag=true]
PicoPropertySchema *ps = nil;
[/#if]
ps = [[PicoPropertySchema alloc] initWithKind:PICO_KIND_VALUE xmlName:nil propertyName:@"${field.name}" type:${field.type.name} clazz:[#if !field.type.primitive][${field.type.fullName} class][#else]nil[/#if]];
[map setObject:ps forKey:@"${field.name}"];
[#else][#-- map to xml any --]
[#if !flag]
[#assign flag=true]
PicoPropertySchema *ps = nil;
[/#if]
[#if field.type.collection && (field.type.typeParameters)?? && field.type.typeParameters?size > 0]
[#assign type = field.type.typeParameters?first]
[#else]
[#assign type = field.type]
[/#if]
ps = [[PicoPropertySchema alloc] initWithKind:PICO_KIND_ANY_ELEMENT xmlName:@"${xmlName}" propertyName:@"${field.name}" type:${type.name} clazz:[#if !type.primitive][${type.fullName} class][#else]nil[/#if]];
[map setObject:ps forKey:@"${field.name}"];
[/#if]
[/#list]
}return map;
}



-(void)dealloc {
[#list clazz.fields as field]
self.${field.name} = nil;
[/#list]
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
[#ftl]
[#--template for the client-side complex/simple type interface.--]
// Generated by xsd compiler for ios/objective-c
// DO NOT CHANGE!

#import <Foundation/Foundation.h>
#import "PicoClassSchema.h"
#import "PicoPropertySchema.h"
#import "PicoConstants.h"
#import "PicoBindable.h"
[#list superClassImports as import]
#import "${import}.h"
[/#list]

[#if clazz.abstract]
// abstract class
[/#if]

[#list fieldClassImports as import]
@class ${import};
[/#list]

/**
${clazz.docComment?default("(public class)")?replace("\n", "\n ")?replace("\t", "")}

[#if group??]
@ingroup ${group}
[/#if]
*/
@interface ${clazz.name} : [#if clazz.superClass??]${clazz.superClass.name}[#else]NSObject <PicoBindable>[/#if]



[#function getPrimitiveTypeName type]
[#assign index = type?last_index_of("_") ]
[#return type?substring(index + 1)?lower_case]
[/#function]

[#list clazz.fields as field]
[#if field.type.collection]
[#assign type = field.type.typeParameters?first]
/**
${field.docComment?default("(public property)")?replace("\n", "\n ")?replace("\t", "")}

[#if type.enum]
entry type : string constant in ${type.fullName}.h
[#elseif type.primitive]
entry type : ${type.fullName}, wrapper for primitive ${getPrimitiveTypeName(type.name)}
[#else]
entry type : class ${type.fullName}
[/#if]
*/

@property NSMutableArray *${field.name};
[#elseif field.type.enum]
/**
${field.docComment?default("(public property)")?replace("\n", "\n ")?replace("\t", "")}

type: string constant in ${field.type.fullName}.h
*/
@property NSString *${field.name};
[#elseif field.any]
/**
${field.docComment?default("(public property)")?replace("\n", "\n ")?replace("\t", "")}

entry type : ${field.type.fullName}, wrapper for primitive ${getPrimitiveTypeName(field.type.name)}
*/
@property NSMutableArray *${field.name};
[#else]
/**
${field.docComment?default("(public property)")?replace("\n", "\n ")?replace("\t", "")}

[#if field.type.primitive]
type : ${field.type.fullName}, wrapper for primitive ${getPrimitiveTypeName(field.type.name)}
[#else]
type : class ${field.type.fullName}
[/#if]
*/
@property ${field.type.fullName} *${field.name};
[/#if]

[/#list]

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[#ftl]
[#--template for the client-side common header file.--]
// Generated by xsd compiler for ios/objective-c
// DO NOT CHANGE!

/**
Common header file
*/

[#list classes as class]
#import "${class.name}.h"
[/#list]

[#list enums as enum]
#import "${enum.name}.h"
[/#list]
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[#ftl]
[#--template for the client-side enum declaration.--]
// Generated by xsd compiler for ios/objective-c
// DO NOT CHANGE!

#import <Foundation/Foundation.h>

[#if enum.docComment??]
/**
@file
${enum.docComment?chop_linebreak?replace("\n", "\n ")?replace("\t", "")}

[#if group??]
@ingroup ${group}
[/#if]
*/
[/#if]
[#list enum.enumConstants as constant]

[#if constant.docComment??]
/**
${constant.docComment?replace("\n", "\n ")?replace("\t", "")}
*/
[/#if]
extern NSString *const ${enum.name}_${constant.name};
[/#list]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[#ftl]
[#--template for the client-side enum declaration.--]
// Generated by xsd compiler for ios/objective-c
// DO NOT CHANGE!

#import "${enum.name}.h"

[#if enum.docComment??]
/**
@file
${enum.docComment?chop_linebreak?replace("\n", "\n ")?replace("\t", "")}
*/
[/#if]
[#list enum.enumConstants as constant]

[#if constant.docComment??]
/**
${constant.docComment?replace("\n", "\n ")?replace("\t", "")}
*/
[/#if]
NSString *const ${enum.name}_${constant.name} = @"${constant.value}";
[/#list]