--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes Gaelyk.
Pour envoyer un message à ce groupe, adressez un e-mail à gae...@googlegroups.com.
Pour vous désabonner de ce groupe, envoyez un e-mail à l'adresse gaelyk+un...@googlegroups.com.
Pour plus d'options, consultez la page de ce groupe : http://groups.google.com/group/gaelyk?hl=fr
I was a bit lazy hacking some code to show you that, but... it's
possible to use type coercion to convert your own classes to other
classes.
So you could have your POGO hierarchy, like Person, PersonWithAddress,
and then do person as Entity.
And vice-versa, have the reverse operation too, entity as Person.
You need to have a look at the asType(Class) method, that you can add
dynamically yourself, or in a base class for example.
--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one
Use GAE's own Entity class, of course.
And notice that I'm using a Groovy "category".
And a Gaelyk plugin allows you to add your own category, so that it's
transparent (ie. you don't even have to say use(MyCat) {} at all, it's
just available by default in all your groovlets and templates).
So you can create a plugin for that.
You'll have your own type hierarchy, and will be able to easily
convert back'n forth between that and the low-level Entity class.
I've copied it here too:
class Entity {
Map props = [:]
}
class Person {
String name
int age
}
class PersonWithAddress extends Person {
String address
}
def p = new Person(name: "Guillaume", age: 33)
def pa = new PersonWithAddress(name: "Marion", age: 2, address: "Paris")
class CoercionCategory {
static asType(Object self, Class clazz) {
if (clazz == Entity) {
def e = new Entity()
self.properties.each { k, v ->
if (!(k in ['class', 'metaClass'])) {
e.props[k] = v
}
}
return e
} else if (self.class == Entity) {
return clazz.newInstance(self.props)
} else throw new RuntimeException("Can't coerce
${self.class.name} into ${clazz}")
}
}
use (CoercionCategory) {
def pEntity = p as Entity
def paEntity = pa as Entity
assert pEntity.props.name == "Guillaume"
assert pEntity.props.age == 33
assert paEntity.props.name == "Marion"
assert paEntity.props.age == 2
assert paEntity.props.address == "Paris"
def person = new Entity(props: [name: "Guillaume", age: 33]) as Person
def personWA = new Entity(props: [name: "Marion", age: 2,
address: "Paris"]) as PersonWithAddress
assert person.name == "Guillaume"
assert person.age == 33
assert personWA.name == "Marion"
assert personWA.age == 2
assert personWA.address == "Paris"
If you use groovlets and templates, but delegate to pre-compiled
Groovy classes, I think you don't even need the use(MyCategory) {}
stuff, as automatically everything will be under that category, under
the scope of the request, in that thread.
And categories have nothing to do with package (or absence thereof).
On Mon, Jul 12, 2010 at 15:53, Jeff Schwartz <jeffts...@gmail.com> wrote:
> Hi,
>
> I familiarized myself a little with the plugin system by reading the doc on
> the gaelyk site. I think I understand how it works, both on the development
> side and the consumer side.
>
> So I can implement a plugin to provide the use category functionality in
> groovlets and templates and its functionality will also be available in my
> compiled groovy classes as well? It is this last part which is throwing me
> :(.
Groovy is a dynamic language, so there's always a runtime aspect to
any method call, even if the code is pre-compiled.
If a request comes in, to a groovlet or template, the code in those
scripts will be "under" the Gaelyk category, and your plugins'
categories.
The code that is called from within those groovlets and templates will
also fall under the categories.
So if you call your services or whatever from those artifacts, they
will "see" the new behaviour provided by the categories.
> How will its functionality be available in my packaged/compiled classes if
> gaelyk's binding only applies to groovlets and templates?
The bindings are another story.
The binding variables won't be available.
So you won't be able to call datastore, etc, but instead have to use
DatastoreServiceFactory.datastoreService.
BUT, the methods added to DatastoreService through the categories will
be available.
> If I do
> use(MyCategory) { /* do something */ } in my packaged classes how will the
> category get resolved? Wont the compiler complain about not being able to
> resolve it?
Nope.
> Sorry if the answer to this is obvious :)
Groovy newbieness applied ;-)
But don't worry, it's not a bad disease to have, LOL :-)
Guillaume
--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes Gaelyk.
Pour envoyer un message à ce groupe, adressez un e-mail à gae...@googlegroups.com.
Pour vous désabonner de ce groupe, envoyez un e-mail à l'adresse gaelyk+un...@googlegroups.com.
Pour plus d'options, consultez la page de ce groupe : http://groups.google.com/group/gaelyk?hl=fr
I'll have to play with them some day for the fun, as they sound interesting.
Thanks :-)
> This bring me to a slight critique of the plugin documentation. I've asked
> another developer to look at it and they too were confused by it. We both
> agreed that the docs make it appear that a plugin is provided via a war and
Via a zip, I would say, for distribution purpose, if people want to
share their plugins.
But it's not necessarily mandatory :-)
You can indeed just put the right files in the right places too! (as
you did and figured out)
> that to develop it it requires a project structure as per the diagram. I
> think it would be worth mentioning in the docs that this is not the case,
> that a plugin is just a bunch of files as is accurately described in the
> docs and these files go in certain places in your application's folders in
> order to be used as is also accurately described in the docs.
Exactly.
So the doc can be improved to make things clearer.
> Other than that, I love the simplicity of the plugin system. It's as simple
> as just dropping the right file into the right directory. And I think if the
> docs made it that clear it would help alleviate some of the confusion that I
> and future developers might encounter.
You know, I highly welcome even documentation contributions ;-)))
> KISS to me is almost a mantra :)
On first read, I read "KISS me is almost a mantra", and I was a bit
confused that I really had to kiss you, LOL ;-D
Guillaume
--
Don't worry, I knew what KISS meant, but I'm so used to "speed
reading" (my tons of daily emails) that sometimes you get some bad
reads :-)
> I will go through the doc for plugin and get back to you with a suggestion
> or 2.
Thank you!
Guillaume