Here is a patch to allow the DJN generated api to be loaded as a Direct Resource in Sencha Architect 3.0.
In the patch the fact that SA3 is to be used is hardcoded.
pagullo: It would be great if you could apply this. It would be awesome if you could spend a few more minutes and cater for a further configuration parameter in web.xml to provide a means of indicating that SA is in use.
Code:
diff -u -r /Users/seade/Downloads/directjngine.2.2/src/prod/com/softwarementors/extjs/djn/jscodegen/ApiCodeGenerator.java ./src/prod/com/softwarementors/extjs/djn/jscodegen/ApiCodeGenerator.java
--- /Users/seade/Downloads/directjngine.2.2/src/prod/com/softwarementors/extjs/djn/jscodegen/ApiCodeGenerator.java 2012-07-03 10:57:04.000000000 +1000
+++ ./src/prod/com/softwarementors/extjs/djn/jscodegen/ApiCodeGenerator.java 2013-11-14 11:24:32.000000000 +1100
@@ -44,6 +44,10 @@
@NonNull private RegisteredApi api;
@NonNull private GlobalConfiguration globalConfiguration;
+ /** Allow for changes to output to allow the generated api to be consumed by SA3 */
+ // TODO Retrieve this from web.xml
+ private static final boolean SA3 = true;
+
public ApiCodeGenerator( GlobalConfiguration globalConfiguration, RegisteredApi api ) {
assert globalConfiguration != null;
assert api != null;
@@ -70,8 +74,15 @@
result.append( " **********************************************************************/\n");
result.append( "\n");
}
- appendNamespaceAndProviderUrlSection(result);
- appendPollingUrlsSection(result, minify);
+
+ // Sencha Architect 3.0 customisation
+ if (!SA3) {
+ // SA3 does not like the namespace and provider URL sections to be specified within the file.
+ appendNamespaceAndProviderUrlSection(result);
+ // SA3 does not like this approach to including polling URLs
+ // TODO Figure out what SA3 does like
+ appendPollingUrlsSection(result, minify);
+ }
appendActionsSection(result, minify);
}
@@ -159,11 +170,31 @@
assert result != null;
result.append( this.api.getApiNamespace() ); result.append( ".REMOTING_API"); result.append( " = {\n" );
+
+ result.append(" url: ");
+ if (SA3) {
+ // By using a relative URL we can skip the base URL
+ // SA3 also requires the URL to be quoted, perhaps this is acceptable for non-SA3 use as well?
+ result.append( "'" ).append( this.globalConfiguration.getProvidersUrl() ).append( "'" );
+ }
+ else {
+ // The following code depends on appendNamespaceAndProviderUrlSection() which is not invoked for SA3
+ result.append( this.api.getApiNamespace() ); result.append( ".PROVIDER_BASE_URL") ;
+ }
+ result.append( ",\n" );
- result.append(" url: " ); result.append( this.api.getApiNamespace() ); result.append( ".PROVIDER_BASE_URL") ; result.append( ",\n" );
result.append(" type: '" ); result.append( REMOTING_TYPE ); result.append( "',\n" );
if( !this.api.getActionsNamespace().equals("")) {
- result.append( " namespace: " ); result.append( this.api.getActionsNamespace()); result.append( ",\n");
+ // SA3 requires the namespace to be quoted, perhaps this is acceptable for non-SA3 use as well?
+ result.append( " namespace: " );
+ if (SA3) {
+ result.append( "'" );
+ }
+ result.append( this.api.getActionsNamespace());
+ if (SA3) {
+ result.append( "'" );
+ }
+ result.append( ",\n");
}
result.append(" actions: {\n" );
}
Thanks, Scott