cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Huss <johnth...@gmail.com>
Subject Re: Can I access metadata (InfoExtension) from my velocity templates
Date Wed, 29 Apr 2020 19:14:25 GMT
I haven't used the metadata / comments yet, so I can't help with that
specifically.

For the using a custom tool with cgen you need to define a
"tools.properties" file in your class path (I would just put it at the
root) with contents like this:


tools.toolbox = application

tools.application.*myUtils* = com.something.tools.MyCgenUtils


The referenced class (and the properties file) needs to be on the class
path when you invoke cgen. The class should contain public instance (not
static) methods in bean-style that work on parts of the DataMap, like an
ObjEntity or a ObjAttribute (or their properties). For example:


*public* *boolean* hasReverse(ObjRelationship rel) {}

Then when you invoke cgen you need to set a system property to point to the
location of your tools.properties file, like this if it is in the class
path root:

-Dorg.apache.velocity.tools=/tools.properties


Your template can reference an instance of your util class using the short
name defined for it in the tools.properties file:


${*myUtils*.getGwtType($attr.Type)}


This process has multiple points of failure, so it can be hard to
setup correctly, but hopefully you can get it working.

On Wed, Apr 29, 2020 at 11:29 AM Faizel Dakri <listfez@dakri.com> wrote:

> Hello all,
>
> Being fairly new to Cayenne, this may be an obvious question. I would like
> to know how I can access the metadata stored on an
> attribute/relationship/entity in the datamap from within my velocity
> templates (I think in CayenneModeler, this is how the comment field is
> stored for a datamap item). I think this is the metadata stored via the
> newish InfoExtension facility.
>
> I see that the DataChannelMetaData can be injected into a DataDomain (and
> I’m doing that at runtime in my server app), however I cannot see how to
> get to this metadata from an attribute or relationship or entity in the
> context of a velocity template. Is this possible? I would think it is since
> Modeler is able to read/write those comments, but I am having a hard time
> doing so in a template.
>
> I did see that there is a hook to provide my own tool into the cgen tool.
> Would this be a potential path to look into if the metadata is not
> accessible directly in the templates as is? If so, any pointers on where to
> start?
>
> Thanks for any advice.
>
> F
>
> --
> Faizel Dakri
> listfez@dakri.com
>
>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message