Meta-properties with groovy?
In python ( specifically CherryPy ) I can do something like
class Root(Object):
开发者_如何学Cdef index():
#some sort of logic here
index.expose = True
is there something similar for Groovy?
Update
CherryPy use's plain objects for it's equivalent of controllers, where the developer decorates or marks each method that should be exposed to the URL routing system. In the above example ( with some additional configuration ), the .expose property tells the framework that index should be accessible viable the request routing system. Specifically for my problem, I'm trying to write a data dictionary that pushes abbreviated key, value pairs onto a simple class from a vCard file. So ideally something like
class Foo {
@Key("FN")
def fullName
}
where a vCard parser would create a new instance of foo then assign the FullName class property with the contents of "FN".
Doing some more research ( Google ), I ended up checking r/Groovy on reddit and was led to this very useful blog post
From my perspectives, Java annotations can be used to decorate or markup methods with extended logic. So something like
class Root {
@Expose
void index() {
#som sort of logic here
}
}
And then use Java annotations to detect the @Expose annotation.
精彩评论