BeanProxy

From Tupelo Wiki

Table of contents

Bean Proxies

What is it?

A bean proxy is simply a type of java.util.HashMap that keys property values to their names. It is a stand-in for a bean . For example:

  • If it is impossible to instantiate a given bean (such as not having the class available) or
  • Where instantiation would be too costly (e.g. a bean that automatically creates a connection to a database).
  • To resolve bootstrapping issues. E.g., a system needs configuration before it is initialized. A bean proxy can be used to retrieve all configuration information
  • To keep from deserializing a large, complex network

A bean proxy is intended to be a very simple class and has only a couple of its own properties: Its RDF subject and the bean class mapping that gave rise to the proxy.

It will also only deserialize as much of a network as needed. In the case of a bean, since we cannot impose other structure on the beans, retrieving a bean that references a network of beans will cause the entire network to be deserialized. Sometimes this is too much. For instance, retrieving a bean just to read its title as part of constructing a user interface might cause a huge number of referenced beans to be constructed. A bean proxy can be used in this case.

Bean proxy operations

Mapping bean classes

Every bean proxy must have a bean class mapping associated with it. You may create one (by hand, since there is no class to introspect for you) or retrieve one from a context if it exists. Note that it is not required to have the class for the mapping available. This may be retrieved from the bean proxy by issuing

beanProxy.getBeanClassRdfMapping();


Registration and deregistration

Should you have a bean class mapping that you would like to add to the system, the usual calls will work as well:

beanSession.mapAndRegister(beanProxy);

Again, this will take the bean class mapping and add it to the current context. This is a useful call if you have different bean sessions and need to add a class mapping to another context. Of course, this supposes that you have the bean class mapping in the first place, if you need to create one, look here.

Saving and rolling back

Saving a bean proxy is simple. Just issue the global save (no arguments) to save all proxies and beans or invoke with the subject. The previous comments for rolling back changes during a session also hold.

Fetching bean proxies

There is a specific call for fetching a bean proxy:

BeanProxy beanProxy = beanSession.fetchBeanProxy(subject);

In other words, you must tell the bean session explicitly if you wish it to try and instantiate a bean or use a proxy.