Services provided by BeanHelper to JucasBeans

There are three different services provided by org.jucas.BeanHelper:

  1. Service to store values encapsulated in Session or Request scope

  2. Service to create child IJucasBeans.

  3. Service to get the BeanManager, the current HttpServletRequest, Response and ServletContext

All three services are accessible through the org.jucas.BeanHelper instance which is given to the JucasBean when it is setup. So the first time the Bean can use the Services is in the JucasBean.initializeJucasOnly() method.

For a full description of the services consult the org.jucas.BeanHelper api-docs.

Storing encapsulated in Request or Session Scope

The BeanHelper class has a number of get and put methods. These can be used to store a value in Session or Request scope. Their general forms are the put() and get() methods, which take Objects.

With the method BeanHelper.put(?myValue?,Scopes.Session, value) the Object value is stored under the name myValue in the Session. The value can than be retrieved by using the corresponding get method.

The BeanName of the JucasBean is combined with the name provided to the put method to construct a unique key, which is used to store the value in the actual HttpSession. This way different instances of JucasBean (even of the same type) may use the same names to store in Session or Request without getting in conflict. The value in the Session can only be retrieved by the JucasBean which created it. Through this some sort of encapsulation (like used of Java classes in their private fields) is possible in the Request and Session scopes. (Of course someone could always scan directly the HttpSession, or Request, but this is no contractual usage).

Corresponding to the get and put methods there is also always a getStatic putStatic method. This methods do take instead of the JucasBean name the String gotten by JucasBean.getStaticType() (generally the class name of the IJucasBean) to construct the key for storing in HttpSession. This way all JucasBeans of the same type have access to the value. This is used to provide similar functionality as static fields in a Java class.

The last important method is BeanHelper.getStorageValue(). This method and the corresponding getStaticStorageValue() are used to get an instance of org.jucas.StorageValue. StorageValue is a helper which holds the name and the scope with which you want to access the Session or Request. The typically use is that a StorageValue is created when the JuasBean is initialized and than kept in a private field. The StorageValue can than be used to access the Request and Session, without the need to type in always the correct name

Creating child JucasBeans

A JucasBean may be composed of other JucasBeans. To allow this the child creation Services provided by BeanHelper are used. This service is needed to create child JucasBeans because also the child-beans have to be setup like any other JucasBean.

The method BeanHelper.setUpNewBean(IJucasBean child,String name) will take a newly constructed JucasBean and set it up. The name must be unique among all child beans of the same (parent) JucasBean and it must be a valid property name (as defined by org.apache.commons.beanutils). So the name must be a JavaName (starting with a-zA-Z followed by any number of a-zA-Z, 0-9 or _ ) at the end it may contain square braces with an index (i.e [1]) to indicated that the property is indexed or round braces with an arbitrary string (i.e (key)) to indicate that the property is mapped. The name must not contain a dot. Additional the (parent) JucasBean which sets up the child JucasBean must implement a JavaBeans property through which the child JucasBean can be accessed.

The BeanName of the child JucasBean will be the BeanName of the parent plus in the fragment part of the URI the name of the child separated by a dot. This way in the fragment a BeanUtils properies path is created.

The method BeanHelper.createChildJucasBean(String name,URI definingURI) creates a child-bean with the given name (the above said also applies to this name). Contrary to the above method you don?t have to instantiate the Bean first, rather the URI is taken to load a new Instance of the Bean. For loading the new instance the same applies as said about how the BeanManager loads new instances.

Getting the current HttpServletRequest, -Response, ServletContext and BeanManager

The current HttpServletRequest, -Response and ServletContext can be gotten by the methods, getHttpServletRequest(), getHttpServletResponse(), getServletContext(). Note: that a JucasBean may be used (not concurrently but in series) in different requests (because it might be held in Session). Therefore the JucasBean should never hold a reference to the HttpServletReques, -Response or ServletContext. Rather if it needs one of these in a method it should retrieve it, use it and release it again.

Finally the BeanManager can be gotten by the method getBeanManager().