sabarish
Jan 15th, 2006, 01:36 PM
I could not find a NamingStrategy that supports generation of a type key property. Would it make sense to add a NamingStrategy for this, especially for applications that register many application beans (for ex all the facade beans) as MBeans?
A NamingStrategy based on a Decorator pattern that would decorate an existing NamingStrategy by adding a type key property to the ObjectName would be a nice to have. If a naming strategy impl to be decorated is not provided, it could fall back onto the logic in the default naming strategy, but then add a type key property.
Usually application classes implement some interface that can denote what kind of class it is. For ex, all facade classes would implement a MyServiceIntf. Similarly all DAOs might implement a Persister interface. So a InterfaceBasedTypeNamingStrategyDecorator that accepts a map (of interface names mapped to type values) would provide an easy way to supply the type property for such beans.
The strategy impl could check if the passed in managedObject implements one of the interfaces in the map fed to the strategy. And if so, it appends a type key property to the ObjectName, the value for which would be the type value from the map for that interface. But if the managedObject is not an instance of any interfaces in the map (or if no map was provided), then the type gets generated from the name of the super interface implemented by the managedObject.
This way using 4 or 5 (or 0) entries in the map, we can generate the type property for all the managed beans in the application. I don't think this would be of use to many apps out there, but still some would benefit :)
A NamingStrategy based on a Decorator pattern that would decorate an existing NamingStrategy by adding a type key property to the ObjectName would be a nice to have. If a naming strategy impl to be decorated is not provided, it could fall back onto the logic in the default naming strategy, but then add a type key property.
Usually application classes implement some interface that can denote what kind of class it is. For ex, all facade classes would implement a MyServiceIntf. Similarly all DAOs might implement a Persister interface. So a InterfaceBasedTypeNamingStrategyDecorator that accepts a map (of interface names mapped to type values) would provide an easy way to supply the type property for such beans.
The strategy impl could check if the passed in managedObject implements one of the interfaces in the map fed to the strategy. And if so, it appends a type key property to the ObjectName, the value for which would be the type value from the map for that interface. But if the managedObject is not an instance of any interfaces in the map (or if no map was provided), then the type gets generated from the name of the super interface implemented by the managedObject.
This way using 4 or 5 (or 0) entries in the map, we can generate the type property for all the managed beans in the application. I don't think this would be of use to many apps out there, but still some would benefit :)