Quantcast
Channel: Adobe Community : Popular Discussions - LiveCycle Data Services
Viewing all articles
Browse latest Browse all 58696

Updated Groovy template for GraniteDS Builder (gas3)

$
0
0

Just wanted to post this here in case anyone else was getting frustrated by the use of iExternalizable from the gas3 system from GraniteDS.  Just save the template as a .gsp file and update your GraniteDS nature to point the Entity template to your file (note: don't get confused by their docs, when you edit the location just put the DIRECT path to your file, and use forward slashes only...don't prefix it with 'file:' as they misleadingly insinuate (they are not wrong, just misleading)...i.e. c:/myTemplates/myTemplate.gsp)

 

In addition to that, I also stripped out the specialized GraniteDS datatypes in favor of the LCDS serialization convention that Adobe uses (i.e. a Java map should translate to an 'Object' type, a Java enum should translate to a 'String', and Java collections should always serialize as 'ArrayCollection')

 

For our application, we didn't do a 'base' version and a version that doesnt get touched by the code generator, but you could easily do so by modifying this template...it's not difficult...But if you just need a template that generates a LCDS compatible Actionscript class for your remoting service, this will do the trick:

 

I have two versions, this one is meant for Managed entities:

<%--

  GRANITE DATA SERVICES

  Copyright (C) 2011 GRANITE DATA SERVICES S.A.S.

 

 

  This file is part of Granite Data Services.

 

 

  Granite Data Services is free software; you can redistribute it and/or modify

  it under the terms of the GNU Library General Public License as published by

  the Free Software Foundation; either version 2 of the License, or (at your

  option) any later version.

 

 

  Granite Data Services is distributed in the hope that it will be useful, but

  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or

  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License

  for more details.

 

 

  You should have received a copy of the GNU Library General Public License

  along with this library; if not, see <http://www.gnu.org/licenses/>.

 

 

  @author Franck WOLFF

  Updated by Robert Petz

          Removed iExternalizable interface

          Switched 'Bindable' for 'Managed'

          Switched to Adobe's preferred serialization of Java to Actionscript

--%><%

    Set as3Imports = new TreeSet();

 

 

    if (jClass.hasEnumProperty())

        as3Imports.add("org.granite.util.Enum");

 

 

    for (jImport in jClass.imports) {

        if (jImport.as3Type.hasPackage() && jImport.as3Type.packageName != jClass.as3Type.packageName)

            as3Imports.add(jImport.as3Type.qualifiedName);

    }

 

 

%>/**

* WARNING: DO NOT CHANGE THIS FILE. IT WILL BE OVERWRITTEN EACH TIME YOU USE THE GENERATOR.

* Modified by: Robert Petz, May 2012

*/

 

 

package ${jClass.as3Type.packageName}

{<%

////////////////////////////////////////////////////////////////////// /////////

// Write Import Statements.

    for (as3Import in as3Imports) { if (as3Import != "org.granite.math" && as3Import != "org.granite.collections") { if (as3Import == "mx.collections.ListCollectionView" || as3Import == "IList") { as3Import = "mx.collections.ArrayCollection" }%>

    import ${as3Import};<%

    }}

    if (jClass.as3Superclass != null) {%>

    import ${jClass.as3Superclass.qualifiedName};<%

    }

 

 

////////////////////////////////////////////////////////////////////// /////////

// Write Class Declaration.%>

 

 

    [Managed]

    [RemoteClass(alias="${jClass.qualifiedName}")]

    public class ${jClass.as3Type.name}<%

 

 

        boolean implementsWritten = false;

        if (jClass.superclass != null) {

            %> extends ${jClass.superclass.as3Type.name}<%

        } else {

                  if (jClass.as3Superclass != null) {

                  %> extends ${jClass.as3Superclass.name}<%

                  }

        }

 

 

        for (jInterface in jClass.interfaces) {

            if (!implementsWritten) {

                %> implements ${jInterface.as3Type.name}<%

 

 

                implementsWritten = true;

            } else {

                %>, ${jInterface.as3Type.name}<%

            }

        }

    %>

    {<%  ///////////////////////////////////////////////////////////////////// //////

    // Write Private Fields.

    for (jProperty in jClass.properties) {

          aName = jProperty.as3Type.name

          if (aName == "IList") { aName = "ArrayCollection" }

          if (aName == "ListCollectionView") { aName = "ArrayCollection" }

          if (aName == "IMap") { aName = "Object" }

          if (aName == "Long") { aName = "Number" }

          if (aName == "BigInteger") { aName = "Number" }

          if (aName == "BigDecimal") { aName = "Number" }

          if (aName == "MathContext") { aName = "Number" }

          if (aName == "RoundingMode") { aName = "Number" }

        if (jProperty instanceof org.granite.generator.as3.reflect.JavaMember) {%>

        ${jProperty.access} var _${jProperty.name}:${aName};<%

        }

        else {%>

        private var _${jProperty.name}:${aName};<%

        }

    }

 

 

    ///////////////////////////////////////////////////////////////////// //////

    // Write Public Getter/Setter.

 

 

    for (jProperty in jClass.properties) {

          aName = jProperty.as3Type.name

          if (aName == "IList") { aName = "ArrayCollection" }

          if (aName == "ListCollectionView") { aName = "ArrayCollection" }

          if (aName == "IMap") { aName = "Object" }

          if (aName == "Long") { aName = "Number" }

          if (aName == "BigInteger") { aName = "Number" }

          if (aName == "BigDecimal") { aName = "Number" }

          if (aName == "MathContext") { aName = "Number" }

          if (aName == "RoundingMode") { aName = "Number" }

 

 

        if (jProperty.readable || jProperty.writable) {%>

 

 

          /**

           * @public ${jProperty.name}

           */<%

            if (jProperty.writable) {%>

        public <%= jProperty.writeOverride ? "override " : "" %>function set ${jProperty.name}<% if (jProperty.name == aName) { %>_<% } %>(value:${aName}):void

                    { _${jProperty.name} = value; }<%

            }

            if (jProperty.readable) {

                if (!jProperty.writable) {%>

        [Bindable(event="unused")]<%

                                  }

                if (jClass.metaClass.hasProperty(jClass, 'constraints') && jClass.constraints[jProperty] != null) {

                          for (cons in jClass.constraints[jProperty]) {%>

              [${cons.name}<%

                                                      if (!cons.properties.empty) {%>(<%}

                                                      cons.properties.eachWithIndex{ p, i -> if (i > 0) {%>, <%}%>${p[0]}="${p[1]}"<%}

                                                      if (!cons.properties.empty) {%>)<%}%>]<%

                                            }

                }%>

        public <%= jProperty.readOverride ? "override " : "" %>function get ${jProperty.name}<% if (jProperty.name == aName) { %>_<% } %>():${aName}

                    { return _${jProperty.name}; }<%

            }

        }

    }

 

 

    ///////////////////////////////////////////////////////////////////// //////

    // Write Public Getters/Setters for Implemented Interfaces.

 

 

    if (jClass.hasInterfaces()) {

        for (jProperty in jClass.interfacesProperties) {

            if (jProperty.readable || jProperty.writable) {%>

<%

                if (jProperty.writable) {%>

        public function set ${jProperty.name}(value:${jProperty.as3Type.name}):void {

        }<%

                }

                if (jProperty.readable) {%>

        public function get ${jProperty.name}():${jProperty.as3Type.name} {

            return ${jProperty.as3Type.nullValue};

        }<%

                }

            }

        }

    }%>

    }

}

 

And this one is meant for non managed entities:

 

<%--

  GRANITE DATA SERVICES

  Copyright (C) 2011 GRANITE DATA SERVICES S.A.S.

 

 

  This file is part of Granite Data Services.

 

 

  Granite Data Services is free software; you can redistribute it and/or modify

  it under the terms of the GNU Library General Public License as published by

  the Free Software Foundation; either version 2 of the License, or (at your

  option) any later version.

 

 

  Granite Data Services is distributed in the hope that it will be useful, but

  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or

  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License

  for more details.

 

 

  You should have received a copy of the GNU Library General Public License

  along with this library; if not, see <http://www.gnu.org/licenses/>.

 

 

  @author Franck WOLFF

  Updated by Robert Petz

          Removed iExternalizable interface

          Switched to Adobe's preferred serialization of Java to Actionscript

--%><%

    Set as3Imports = new TreeSet();

 

 

    if (jClass.hasEnumProperty())

        as3Imports.add("org.granite.util.Enum");

 

 

    for (jImport in jClass.imports) {

        if (jImport.as3Type.hasPackage() && jImport.as3Type.packageName != jClass.as3Type.packageName)

            as3Imports.add(jImport.as3Type.qualifiedName);

    }

 

 

%>/**

* WARNING: DO NOT CHANGE THIS FILE. IT WILL BE OVERWRITTEN EACH TIME YOU USE THE GENERATOR.

* Modified by: Robert Petz, May 2012

*/

 

 

package ${jClass.as3Type.packageName}

{<%

////////////////////////////////////////////////////////////////////// /////////

// Write Import Statements.

    for (as3Import in as3Imports) { if (as3Import != "org.granite.math" && as3Import != "org.granite.collections") { if (as3Import == "mx.collections.ListCollectionView" || as3Import == "IList") { as3Import = "mx.collections.ArrayCollection" }%>

    import ${as3Import};<%

    }}

    if (jClass.as3Superclass != null) {%>

    import ${jClass.as3Superclass.qualifiedName};<%

    }

 

 

////////////////////////////////////////////////////////////////////// /////////

// Write Class Declaration.%>

 

 

    [Bindable]

    [RemoteClass(alias="${jClass.qualifiedName}")]

    public class ${jClass.as3Type.name}<%

 

 

        boolean implementsWritten = false;

        if (jClass.superclass != null) {

            %> extends ${jClass.superclass.as3Type.name}<%

        } else {

                  if (jClass.as3Superclass != null) {

                  %> extends ${jClass.as3Superclass.name}<%

                  }

        }

 

 

        for (jInterface in jClass.interfaces) {

            if (!implementsWritten) {

                %> implements ${jInterface.as3Type.name}<%

 

 

                implementsWritten = true;

            } else {

                %>, ${jInterface.as3Type.name}<%

            }

        }

    %>

    {<%  ///////////////////////////////////////////////////////////////////// //////

    // Write Private Fields.

    for (jProperty in jClass.properties) {

          aName = jProperty.as3Type.name

          if (aName == "IList") { aName = "ArrayCollection" }

          if (aName == "ListCollectionView") { aName = "ArrayCollection" }

          if (aName == "IMap") { aName = "Object" }

          if (aName == "Long") { aName = "Number" }

          if (aName == "BigInteger") { aName = "Number" }

          if (aName == "BigDecimal") { aName = "Number" }

          if (aName == "MathContext") { aName = "Number" }

          if (aName == "RoundingMode") { aName = "Number" }

        if (jProperty instanceof org.granite.generator.as3.reflect.JavaMember) {%>

        ${jProperty.access} var _${jProperty.name}:${aName};<%

        }

        else {%>

        private var _${jProperty.name}:${aName};<%

        }

    }

 

 

    ///////////////////////////////////////////////////////////////////// //////

    // Write Public Getter/Setter.

 

 

    for (jProperty in jClass.properties) {

          aName = jProperty.as3Type.name

          if (aName == "IList") { aName = "ArrayCollection" }

          if (aName == "ListCollectionView") { aName = "ArrayCollection" }

          if (aName == "IMap") { aName = "Object" }

          if (aName == "Long") { aName = "Number" }

          if (aName == "BigInteger") { aName = "Number" }

          if (aName == "BigDecimal") { aName = "Number" }

          if (aName == "MathContext") { aName = "Number" }

          if (aName == "RoundingMode") { aName = "Number" }

 

 

        if (jProperty.readable || jProperty.writable) {%>

 

 

          /**

           * @public ${jProperty.name}

           */<%

            if (jProperty.writable) {%>

        public <%= jProperty.writeOverride ? "override " : "" %>function set ${jProperty.name}<% if (jProperty.name == aName) { %>_<% } %>(value:${aName}):void

                    { _${jProperty.name} = value; }<%

            }

            if (jProperty.readable) {

                if (!jProperty.writable) {%>

        [Bindable(event="unused")]<%

                                  }

                if (jClass.metaClass.hasProperty(jClass, 'constraints') && jClass.constraints[jProperty] != null) {

                          for (cons in jClass.constraints[jProperty]) {%>

              [${cons.name}<%

                                                      if (!cons.properties.empty) {%>(<%}

                                                      cons.properties.eachWithIndex{ p, i -> if (i > 0) {%>, <%}%>${p[0]}="${p[1]}"<%}

                                                      if (!cons.properties.empty) {%>)<%}%>]<%

                                            }

                }%>

        public <%= jProperty.readOverride ? "override " : "" %>function get ${jProperty.name}<% if (jProperty.name == aName) { %>_<% } %>():${aName}

                    { return _${jProperty.name}; }<%

            }

        }

    }

 

 

    ///////////////////////////////////////////////////////////////////// //////

    // Write Public Getters/Setters for Implemented Interfaces.

 

 

    if (jClass.hasInterfaces()) {

        for (jProperty in jClass.interfacesProperties) {

            if (jProperty.readable || jProperty.writable) {%>

<%

                if (jProperty.writable) {%>

        public function set ${jProperty.name}(value:${jProperty.as3Type.name}):void {

        }<%

                }

                if (jProperty.readable) {%>

        public function get ${jProperty.name}():${jProperty.as3Type.name} {

            return ${jProperty.as3Type.nullValue};

        }<%

                }

            }

        }

    }%>

    }

}

 

 

Hope this saves someone some time, I just threw this together pretty quickly for my own uses (using my preferred brace formatting) but feel free to expand upon it...I should note that this is a modified version of Granite DS's stock template, and all credit goes to them for gas3 and the template and such and such

 

When I get around to it I'll go ahead and add in some more data to the type ahead as well...


Viewing all articles
Browse latest Browse all 58696

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>