2 Replies Latest reply on Jul 17, 2008 1:36 PM by Francisco Jose Peredo Noguez

    Launch Files: Real control of Seam-Gen

    Francisco Jose Peredo Noguez Master

      Hi!

      Hi!

      We (in my project) have heavily modified and enhanced the functionality of seam-gen, but I think we are hitting a hard limit: we can not say "do not generate the EntityEdit.xhtml" because that is read-only. No matter what we do, all the *.ftl templates get called for all the our entites.

      We use JBossTools 2.1.1 and store our seam-gen configurations in Eclipse .launch files (and call them using the Code Generation Launcher).

      The initial from database to entities configuration is in a file named:projectname-generate-entities.launch, after that I create a file named: projectname-generate-pages.launch that creates from the entities to the pages .

      The difference is that projectname-generate-entities.launch only uses 1 exporter, the Domain code exporter (extract of projectname-generate-entities.launch):

       <booleanAttribute key="org.hibernate.tools.exporters.hbmtemplate0"
       value="true" />
       <stringAttribute
       key="org.hibernate.tools.exporters.hbmtemplate0.extension_id"
       value="org.hibernate.tools.hbm2java" />
       <mapAttribute
       key="org.hibernate.tools.exporters.hbmtemplate0.properties">
       <mapEntry key="template_path"
       value="\seam-templates\hibernate-tools" />
       </mapAttribute>
      


      On the other hand projectname-generate-pages.launch is much larger (here is only the part that generates the EntityEdit.xhtml:

      <mapAttribute
       key="org.hibernate.tools.exporters.hbmtemplate4.properties">
       <mapEntry key="outputdir" value="/applicationName/WebContent/" />
       <mapEntry key="for_each" value="entity" />
       <mapEntry key="template_name" value="view/edit.xhtml.ftl" />
       <mapEntry key="file_pattern" value="{class-name}Edit.xhtml" />
       <mapEntry key="hibernatetool.util.toolclass"
       value="org.hibernate.eclipse.launch.SeamUtil" />
       </mapAttribute>
      


      As you can see, the exporter configuration for EntityEdit.xhtml is very different, and one of themain differences is that it has a :

      <mapEntry key="for_each" value="entity" />
      


      now, i would like to extend this mechanism to make it possible to generate the EntityEdit.xhtml only for... for example non-readonly entities (or any other criteria that I choose):

      <mapEntry key="for_each" value="readonly-entity" />
      


      (And then create my own custom @ReadOnlyEntity annotation to control generation)

      My plan to achieve that effect was to create my own exporter, to do that, I need to configure a Generic Hibernate metamodel exporter and create my own exporter class (inheriting I think)... but here is my problem... the docs only explain how to set the exporter class for ant:

      <hbmtemplate
       filepattern="{package-name}/{class-name}.ftl"
       template="somename.ftl"
       exporterclass="Exporter classname"
      />
      


      Docs do not explain how to configure the exporterclass in a eclipse *.launch file (or if is even possible)...

      How can I do that? (Do I need to modify the Eclipse Jboss Tools code? or this features is available but undocumented?)

      Thanks
      Regards,

      P.D. Sorry for cross posting, but I posted this question at SeamFramework.org and nobody answered, and I am starting to think that maybe that is because this forum is a better match for this kind of question because it is more related to JBoss Tools than Seam



        • 1. Re: Launch Files: Real control of Seam-Gen
          Max Rydahl Andersen Master

           

          "luxspes" wrote:

          We (in my project) have heavily modified and enhanced the functionality of seam-gen, but I think we are hitting a hard limit: we can not say "do not generate the EntityEdit.xhtml" because that is read-only. No matter what we do, all the *.ftl templates get called for all the our entites.


          Yes, that is the default behavior.


          We use JBossTools 2.1.1 and store our seam-gen configurations in Eclipse .launch files (and call them using the Code Generation Launcher).


          Nice to see the .launch saving feature being used as intended (sharing of custom code generations)


          As you can see, the exporter configuration for EntityEdit.xhtml is very different, and one of themain differences is that it has a :

          <mapEntry key="for_each" value="entity" />
          


          now, i would like to extend this mechanism to make it possible to generate the EntityEdit.xhtml only for... for example non-readonly entities (or any other criteria that I choose):

          <mapEntry key="for_each" value="readonly-entity" />
          



          For the moment for_each is hardcoded to only understand the Configuration notions of Pojo's (e.g. entity and component)

          I have considered adding table, foreign_key etc. too since they are "concepts" in the Configuration API but it felt wrong to do so (entities and database level concepts being mixed up).

          What I have considered was to add some way to put an expression in for_each that could be iterated but that haven't been done yet (contributions welcome! :)

          That being said there is way to do what you want - read below.


          (And then create my own custom @ReadOnlyEntity annotation to control generation)


          Sounds doable - you could also use the mutable attribute of Hibernate to state it (if that fits the bill enough)


          My plan to achieve that effect was to <a href="http://www.hibernate.org/hib_docs/tools/reference/en/html/codegenarchitecture.html#d0e128">create my own exporter</a>, to do that, I need to configure a <a href="http://www.hibernate.org/hib_docs/tools/reference/en/html/ant.html#hbmtemplate">Generic Hibernate metamodel exporter</a> and create my own exporter class (inheriting I think)... but here is my problem... the docs only explain how to set the exporter class for ant:

          <hbmtemplate
           filepattern="{package-name}/{class-name}.ftl"
           template="somename.ftl"
           exporterclass="Exporter classname"
          />
          



          Custom exporters are only really needed if you want very specific iteration and setup of the contexts - you can do without it in this specific case.


          Docs do not explain how to configure the exporterclass in a eclipse *.launch file (or if is even possible)...

          How can I do that? (<b>Do I need to modify the Eclipse Jboss Tools code? or this features is available but undocumented?</b>)


          the hbmtemplate exporter has a property exporter_class you can set - just like ant ;)

          But now to how you can do it with less tweaks. I deliberatly made it so that if a template generates a trimmed empty string (e.g. a file with zero contents) then the file would not be generated.

          That means you can simply put an expression in the top of the template and decide if something needs generating or not.

          See http://freemarker.sourceforge.net/docs/ref_directive_if.html how to create and #if block.


          P.D. Sorry for cross posting, but I posted <a href="http://www.seamframework.org/Community/LauchFilesRealControlOfSeamGen">this question</a> at <a href="www.seamframework.org">SeamFramework.org</a> and nobody answered, and I am starting to think that maybe that is because this forum is a better match for this kind of question because it is more related to JBoss Tools than Seam


          No problem - you did the right thing by posting here.
          I try to monitor the Seam forum but I don't always catch the tool related questions, plus I just came back from vacation :)

          • 2. Re: Launch Files: Real control of Seam-Gen
            Francisco Jose Peredo Noguez Master

            Hi!

            Thanks a lot for answering! (I was starting to lose hope) it worked perfectly, I left the file empty by detecting if the entity was mutable, I used:

            @org.hibernate.annotations.Entity(mutable=false)


            and in the .ftl:

            <#if pojo.decoratedObject.mutable>


            I will try the exporter_class property for the launch file later, thanks for the tip. (It would be nice if you guys could document all the options available for .launch files).

            Thanks again!!

            Regards,

            P.D. I see that in version 3.3.1 of the annotations there is a new annotation @Immutable... I wonder what is the difference with Entity(mutable=false)