By Peter Bell

Why doesn't getMetadata() inherit?

I was just having a quick play with the getMetadata() function, thinking I might want to use it to implement annotations, so I could use custom properties within cfproperty, cfcomponent and cffunction to annotate my metadata for ORM, AOP and the like. But the way it works is a bit of a PITA . . .

Let's say you have User extends BaseObject. BaseObject has a cfproperty for ID, User has a cfproperty for FirstName. BaseObject has a get() method, User has a getAddress() method. You might expect that if you looked at the metadata for the object it'd show that it has two properties and two methods . . .

In fact, it shows that you have a User object with one property and one method which extends a BaseObject object with one property and one method. I know it isn't that much work to write a custom method that walks the tree to get the right methods and properties (allowing parent to override children based on the name of a property, function, etc.) but it just seems a little bit funky. I'll probably do it as I'm guessing cfproperty is gonna becoming increasingly important as ORM and other metadata is required by beans, but does anyone know WHY the getMetadata() reports the data in such an unusual way?

Comments
I'm not really sure what is so unusual about this, though not convenient for your purpose hehe.

It is more accurate and descriptive overall the way that CF outputs now. From it, you can tell almost every detail of an object and where everything came from. Maybe what convenience methods would be appropriately added to the CF language here.

Just my thoughts.

Mike.
# Posted By Mike Kelp | 7/22/08 4:00 PM
Hi Peter. It's because one may not want a flattened version of the metadata, but rather needs to know things like what properties and methods exist in what inherited component. For example, my ColdSpring BeanInjector has to walk the tree because one can specify a class name at which to stop recursion and stop looking for methods to attempt to autowire. If the metadata were flattened, this wouldn't work. In other words, the metadata has to be explicit.

All that said, flattening the metdata is actually pretty easy and I'm sure you'll do it in just a few lines of code. ;-)
# Posted By Brian Kotek | 7/22/08 4:01 PM
OK, sold on there being a value in having the unflattened data. It would be nice to have the flattened data available as well, but as Brian points out, it isn't that much work to write - but isn't cf supposed to make stuff easy *wink*.

Oh well, I haven't written anything recursive since LightWire - guess it's time . . .
# Posted By Peter Bell | 7/22/08 4:15 PM
As mentioned, I do think it might be a good idea to include convenience methods in the next release. Maybe getProperties(component) and getMethod(component)?
# Posted By Mike Kelp | 7/22/08 4:38 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.005.