BeanUtils: First Firemoss open-source software!

Over the weekend, I pushed a library named "BeanUtils" out to RIAForge. I realized today that it represents the first full project released under an open-source license (ASL 2.0) that falls under Firemoss copyright.

It's not a framework: it's more of a tool for utility and framework writers who need to deal with discovering and manipulating properties of CFCs at runtime. It's something I've needed a few times, and I can see places for it within Model-Glue, ColdSpring, Validat, and other utilities that need to do this sort of manipulation.

Features

It provides the following utilities:

Property Inspection

Pass a CFC instance to inspect() and it'll tell you about all of its properties (as either a struct or XML), based <cfproperty /> and getter properties. Any extra attributes added to the relevant <cfproperty /> or <cffunction /> tags will also be included. You can choose to cache results of inspection (by CFC type name) or have it reinspect on each request (to handle things like mixins).

Property Extraction

Pass a CFC instance to extract(), and it'll crawl through the THIS scope and call getter functions as necessary to build a structure of the CFC's data. Safely handles recursive references, even within arrays and structs, building out recursive data structures as a result.

Property Injection

Pass a structure and a CFC to inject(), and it'll set the CFC's properties from like-named members of the structure. It'll populate single "has-a" relationships, but won't populate things like arrays of CFCs (how would it know what "child" CFC to create?). This might get enabled through an optional additional inspection strategy that recognized an attribute like "collectionOf" on array and structure properties (see below bits on "Have it Your Way").

Property Setting

If you don't know the name of a property to set until runtime, setProperty() accepts the name as a variable. It's smart enough to know if it should use the THIS scope or call a setter function.

Property Getting

Similar to setProperty(), getProperty() will get a property by a variable name, using the THIS scope or calling the appropriate getter function.

Have it Your Way

A lot of semantics go into determining what is a property, whether or not its extractable, how a query should be represented in an extraction (right now, it's just a query, but you may want an array of structs, etc.)

For this purpose, BeanUtils is really just a facade on two lower level components: an Inspector and a Convertor. Inspectors discover properties, and Convertors handle the injection / extraction of data.

As this is a fairly low-level tool, it's not likely to be widely used or documented. If you need it, you know it already. I've been very good about using the HINT attribute, so the API should be fairly straightforward.

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
© 2008 Firemoss, LLC
BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.