Wednesday, December 08, 2004

Cornerstone: the API Simplifier

Cornerstone is certainly about the big things such as software mass customization. But its impact on a developer's everyday probably starts from the fact that it's an API simplifier. The reason why simplification is possible is that the common use case is indeed simple and can be kept that way.

JMX Simplifier

A developer needs to have zero knowledge of JMX to make his/her application JMX-enabled. All that needs to be done is the following 2 lines of code:
IJMXManager jmxManager = (IJMXManager)

Cornerstone.createInstance(IJMXManager.class);
jmxManager.manage(anyObject);
Now you can use any JMX user interface (such as the HTML adapter in the JMX Reference Implementation or MC4J) to view all the constructors, properties and operations (methods) of this object. It doesn't get simpler than that :).

Persistence Simplifier

Cornerstone provides a persistence API that is much simpler than the state of the art today. Even when you are using an excellent O-R mapping tool such as Hibernate, you have to be intimated involved with sessions and all that. When using Hibernate with Cornerstone, a developer doesn't directly use Hibernate's API. For example:
IComponentManager componentManager = (IComponentManager)

Cornerstone.createComponent(IComponentManager.class);
IPersistentObjectFactory userFactory = (IPersistentObjectFactory)
componentManager.createComponent(IFactory.class, "myUserFactory");
IUser user = (IUser) userFactory.createInstance(10002);
user.setFirstName("John");
userFactory.store(user);
Cornerstone is the meta-container (a container of other containers). componentManager is the component container. In a Cornerstone application, you actually don't see these interfaces because all of the dependencies are (can be and should be) injected. So the above code is more typically written this way:
IUser user = _userFactory.createInstance(10002);

user.setFirstName("John");
userFactory.store(user);
where _userFactory is an instance variable (data member, whose value is injected by Cornerstone at runtime according to configuration; or change it to getUserFactory() to make getter injection posible). Now you wonder where is the connection and also the transaction? Let's leave that to another post.