Implement the transitions

It is time to consolidate the command specification and the parameter specification into an implementation of commands and data objects.

A command must implement the se.kmr.scam.client.http.Command interface. This API defines how the command is initialized and invoked. The configuration file provides initialization data to a command, see Example 10.15. This is handled by the init method which is invoked before the execute method is invoked.

Example 10.1. Command object, handling initialization parameters

              public void init(Map args) {
                  _defaultDepth = URLUtil.parseInt( (String) args.get("depth"), 0);
                  _maxDepth = URLUtil.parseInt( (String) args.get("maxDepth"), 1);
                  String include = (String) args.get("includeAnnotations");
                  _includeAnnotations = (include != null && include.equals("true"));
              } 
              
            

A Command-object is stateless and should not rely on information provided from earlier requests. Command objects communicates through objects (normally JavaBeans) in request-, session- or application-scope.

This example shows how an instance of a data object, ModelBean, is associated in request scope with the default name for a ModelBean.

Example 10.2. Command object, providing attributes

                
                ModelBean mBean = new ModelBean(model, roots);
                Context.setAttribute(ModelBean.NAME, mBean, request, Context.REQUEST);
                
                

This example shows how an instance of ModelBean, associated with the default name, is retrieved.

Example 10.3. Command object, retrieving attributes

                // Extract the model bean
                ModelBean mBean = ( ModelBean ) Context.getAttribute( ModelBean.NAME, request );
                if ( mBean == null ) {
                    throw new HttpException( HttpException.MISSING_PARAM, ModelBean.NAME );
                }
                

In this case he scope is not defined so the Context object will look for the object in this order:

  1. as an (attribute)object in request-scope
  2. as a (parameter)object in request-scope
  3. as an object in session-scope
  4. as an object in application-scope

Tip

An object that is made available with the Context object is also available in Java Standard Tag Library (JSTL) expression language.

In scam.properties a set of settings for factory services is available.

Example 10.4. scam.properties, factory service settings

                scam.client.factory.manifest=se.kmr.scam.client.repository.ejb.ManifestFactoryImpl
                scam.client.factory.search=se.kmr.scam.client.repository.ejb.SearchFactoryImpl
                scam.client.factory.content=se.kmr.scam.client.repository.ejb.ContentFactoryImpl
                scam.client.factory.administer=se.kmr.scam.client.repository.ejb.AdministerFactoryImpl
                scam.client.factory.import=se.kmr.scam.client.repository.ejb.ImportFactoryImpl
                

These settings define which repository implementation to use, currently only the EJB implementation is complete. Each factory service is represented by an object from which an "hook" to the repository can be retrieved.

Example 10.5. Command object, factory service usage

                try {
                  ManifestI server = ManifestFactory.getInstance().create(request);

                  _log.debug("Fetching component(s) from " + idBean.getID() +
                             ", depth=" + depth + ": " + uris);

                  // Fetch roots and verify that they exist
                  Model model = server.getModel(idBean.getID(), uris);
                

The ManifestFactory service object provides factory objects defined by the scam.client.factory.manifest setting.