-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: How to create a custom Exporter class
PostPosted: Fri Jun 30, 2006 5:58 pm 
Newbie

Joined: Fri Jun 30, 2006 5:02 pm
Posts: 7
Location: Vista, CA
Hibernate version:3.1 beta5

Full stack trace of any exception that occurs:No exception

Hi guys,

I'm a total Newbie to customizing the tools, so bear with me.

I've been reading other posts here about custom templates, but most are with regards to customizing existing operations (hbm2java,hbm2dao)

I am trying to make a set of templates for creating ActionScript classes.

I have started by extracting the POJO*.ftl templates from the pojo directory in the tools jar, and customizing them to write out ActionScript syntax.

For now I'm using the POJOClass as it is already built and compiled, and I just wanted to get a Proof Of Concept working. I have done this, and got some classes built.

Now I would like to write a custom actionscript helper class. Is there any way I can easily extend some of the core classes? (I want something with similar functionality to EntityPOJOClass and BasicPOJOClass)

Do I need to compile the entire HibernateExt branch? Thanks for any high-level guidance to getting this going.

ThunderStumpges


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 10, 2006 1:52 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you should be able to just use <hbmtemplate> to do this.

See http://www.hibernate.org/hib_docs/tools ... bmtemplate for an example.

it is still possible to use the templates from hbm2java if you like that layout; something completely different is also possible.

put something like the following inside a hibernatetool task:
Code:
<hbmtemplate
     template="theroottemplatefile.ftl"
     filepattern="{package-name}/{class-name}.as"/>


and it will generate a .as file per enity and component.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 10, 2006 10:46 pm 
Newbie

Joined: Fri Jun 30, 2006 5:02 pm
Posts: 7
Location: Vista, CA
Hey Max,

I am using hbmtemplate to do it. What I'm talking about is the helper
class that is used for the POJO templates. My current ANT task looks like the following:

Quote:
<hbmtemplate
filepattern="{package-name}/{class-name}.as"
templatepath="templates"
template="actionscript/AS.ftl"
>
<property key="jdk5" value="false" />
<property key="ejb3" value="false" />
</hbmtemplate>


Most of the functionality in the POJO helper classes work fine for
ActionScript.. such as:

- getAllPropertiesIterator
- getPropertyName
- getPropertyClosureForFullConstructor (and other similar)
- isInterface

I just need to tweak a few of the functions to return the ActionScript forms
of stuff... such as:

- getJavaTypeName (this I need to customize for ActionScript Types)
- generateImports (need to generate ActionScript library imports)
- getExtendsDeclaration (need custom ActionScript base classes as
opposed to 'java.io.Serializable')

Can I extend the EntityPOJOClass to customize these (and possibly other)
methods? How much of the HibernateExt branch do I need to compile?

Alternatively, is there a simple enough way to get this functionality using
just the templates? (avoiding these helper methods)

thanks in advance,
Thunder


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 11, 2006 8:44 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Hi Thunder,

hmm...you can always install your own tool and call out to it to get what you want/need.

See http://www.hibernate.org/hib_docs/tools ... e/#d0e1162

It's not perfect; but should at least give you enough to work with.

I'm not sure if allowing you to override $pojo's behavior will be maintainable; but could you let me know what exactly you want do in the scenarios you listed ?

getJavaTypeName - what is needed here ?

generateImports - you do know that if you do $pojo.importType('blablah') will generate an import for you ?

getExtendsDeclaration - here you could add extra imports in hbm.xml; but i guess you don't want those into your java code...

Maybe it is time to generalize and open some of this up...but would like to see some concrete examples for its need; so show me your concrete examples.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: custom ActionScript ExporterClass
PostPosted: Thu Jul 13, 2006 12:23 pm 
Newbie

Joined: Fri Jun 30, 2006 5:02 pm
Posts: 7
Location: Vista, CA
Hey Max, I really appreciate your time and help on this. I apologize in advance if I'm asking too much. Feel free to tell me that I need to go figure it out on my own. But let me address your comments...

Quote:
hmm...you can always install your own tool and call out to it to get what you want/need.


This is basically what I'm trying to do. I would like to write a class that will do the things that $pojo is doing that are specific to Java and don't quite have the same syntax for ActionScript. I understand from the documentation how to load my class, I just don't know where to start on writing it. That's why I was asking about extending the POJO classes. I don't really know what libraries, imports, etc I need to write this helper class.

Quote:
getJavaTypeName - what is needed here ?


This function returns Java types that are mapped from the hibernate type. I need to define a map for ActionScript types, and return the ActionScript type (so the function would be getActionScriptTypeName) For example, my IDs are put as 'java.math.BigDecimal', where I would want the ActionScript primitive type 'Number'

Quote:
generateImports - you do know that if you do $pojo.importType('blablah') will generate an import for you ?


I did not know that... that definitely helps. What I don't understand is how $pojo (or the ImportContext) knows all the types used in the class. I saw from the code that it is somehow filling the 'imports' TreeSet, but doesn't the imports section happen before the 'Fields' or 'PropertyAccessors' ? How do I generate or keep track of the list of imports necessary? Using generateImports() I get java imports like:

import java.math.BigDecimal;
import java.util.HashSet;
import java.util.Set;

where I would want

import mx.collections.ArrayCollection


Quote:
getExtendsDeclaration - here you could add extra imports in hbm.xml; but i guess you don't want those into your java code...


Yeah, I think this one will solve itself, as I think all my hibernate classes will inherit from a common custom class of my own. In this way, I'll only have to correct the 'java.io.Serializable' extends on one class (the base class).

I think I could solve a lot of my problems with a "search and replace" task after the code generation, but if I could do this the "right" way, I think I'd be 99% there on generating ActionScript classes.

Thanks in advance,
Thunder[/quote]


Top
 Profile  
 
 Post subject: Re: custom ActionScript ExporterClass
PostPosted: Thu Jul 13, 2006 1:26 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
ThunderStumpges wrote:
Quote:
hmm...you can always install your own tool and call out to it to get what you want/need.


This is basically what I'm trying to do. I would like to write a class that will do the things that $pojo is doing that are specific to Java and don't quite have the same syntax for ActionScript. I understand from the documentation how to load my class, I just don't know where to start on writing it. That's why I was asking about extending the POJO classes. I don't really know what libraries, imports, etc I need to write this helper class.


...but what do you want it to do ? It is just a small class that generates strings from some input :)

Quote:
Quote:
generateImports - you do know that if you do $pojo.importType('blablah') will generate an import for you ?


I did not know that... that definitely helps. What I don't understand is how $pojo (or the ImportContext) knows all the types used in the class. I saw from the code that it is somehow filling the 'imports' TreeSet, but doesn't the imports section happen before the 'Fields' or 'PropertyAccessors' ? How do I generate or keep track of the list of imports necessary? Using generateImports() I get java imports like:

import java.math.BigDecimal;
import java.util.HashSet;
import java.util.Set;

where I would want

import mx.collections.ArrayCollection


every time you call $pojo.importType(fqn) the class is registred in the $pojo and thus $pojo.generateImports() output the full list.

If you look at the template code we actually generate the body before the imports, store it, generate the imports, inject the body and we are done.

...i'll think about the possibility of opening up some of this, but it is not high priority. (note, i need some of this too; so just knowing your extra requirements might as well make it in there - keep the ideas coming ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.