The org.jucas.JucasBean interface

Generally you won?t implement the JucasBean interface yourself but will rather extend from org.jucas.BaseJucasBean. This class fullfills the contract of the interface and provides reasonable default implementations of the methods.

However here the JucasBean interfaces must be explained, so that you know how to implement it yourself if you want so (it?s very easy) and that you know how and which methods you can override from BaseJucasBean.

givenBeanHelperJucasOnly()

The first time a JucasBean is loaded (created) by the BeanManager (or by the parent JucasBean), it has to be configured. Here the name of the Bean (the URI), the parent of the Bean and the BeanHelper are given to the JucasBean.

The whole configuration happens by giving the JucasBean an instance of org.jucas.BeanHelper. This happens through the method JucasBean.givenBeanHelperJucasOnly(). This method must only be called by the Jucas framework. The instance of JucasHelper overgiven at setup should be store by the Bean in a private field. (The JucasHelper instance should generally not be given out of the Bean, because it holds important internals). When the Bean is released the givenBeanHelperJucasOnly() method will be called with an argument of null. If this happens also the JucasBean should release it?s BeanHelper instance (setting to null), because it is not valid anymore from this moment. So the general implementation for the method JucasBean.givenBeanHelperJucasOnly():

      private BeanHelper beanHelper = null;
      
      final public void givenBeanHelperJucasOnly(BeanHelper bH)
      {
            this.beanHelper = bH;
      }

getBeanName()

Each IJucasBean has a name. This name must be provided to the public by the method getBeanName(). The name is assigned by the framework when the Bean is setup (loaded) through the BeanHelper. JucasServices.getBeanName() contains the assigned BeanName so the only way this method should be implemented is:

     final public URI getBeanName(){
        return (this.beanHelper == null) ? null : this.beanHelper.getBeanName();
     }

getJucasParent()

Like the name each JucasBean has a parent (Except of PageBeans). The parent can be retrieved through the method JucasBean.getJucasParent(). This is the JucasBean which created the Bean or null if the JucasBean is a PageBean (directly managaged by the BeanManager - the name-uri has no fragment). Like the BeanName URI also the parent is assigned by the framework through the BeanHelper. Again the only thing this method should do is give out the parent which the BeanHelper provides:

    final public JucasBean getJucasParent(){
        return (this.beanHelper == null) ? null : this.beanHelper.getJucasParent();
    }

initializeJucasOnly()

After the BeanHelper has been set on the JucasBean (the JucasBean has now a name) the Bean is set to be initialized. Right after this and before the Bean is returned by the BeanManager or given to its parent. The method initializeJucasOnly() is called to inform the Bean that it has been loaded. The Bean may do in this method all its setup for which it needs the BeanHelper (i.e. initilizing values in the Session or Request scope, create child IJucasBeans etc.). What can be done with the JucasServices is described later.

getAllowedPageBeanScope()

A JucasBean which is a PageBean is held by the BeanManager either in the Request or Session scope. In which scope the Bean is held is determined by the Bean itself. This happens through the method IJucasBean.getAllowedPageBeanScope(Scope requestedScope). The method is only used on PageBeans. The method should either return Scope.REQUEST or Scope.SESSION. The parameter is the scope in which the user of the Bean wants the Bean to be held in. The Bean does not have to follow the wish of the user. The value of the parameter is either Scope.REQUEST, Scope.SESSION or null if the user did not request a certain scope. How the JucasBean reactes to the users whish should be documented by the bean.

The method is always called once when the Bean is the first time loaded by the BeanManager (before the Bean has been setup). If the Bean is than held in request scope (the method returned Scope.REQUEST) and the user asks for the Bean to be held in Session scope, the method will be asked again if it allows the Bean to be upgraded to Session scope. If the Bean than returns Scope.SESSION, the Bean will be further held in Session scope (the Bean itself remains unchanged - no new initialization or similar happens). A change from session scope to the request scope is not possible anymore (for consitency reasons). The Bean will also not be informed of such wishes.

retrievedFromBeanManager()

Through the method JucasBean.retrievedFromBeanManager() the Bean is informed each time it is gotten from the BeanManager. Note: only PageBeans (Beans which are managed by the BeanManager directly) are informed. This method is generally left empty, but it could be used i.e. for security checking.

getStaticType()

The last method in JuasBean is getStaticType(). The String returned by this method represents the type of the JucasBean. It is used as a key for storing values in the HttpServletRequest and HttpSession, which should be accessible like static variables to all JucasBeans of the same type. If this method returns null the class-name of the JucasBean will be taken as a key. This is also the normal usage. Only in special cases when the Java-Class can represent different JucasBeans types (like in the case when the Bean is defined as XML) this method should be overwritten to return the type.