Introduction

The struts-it architecture subproject provides a ready-to-go architecture for small and medium sized projects which are using a servlet container as runtime environment. This architecture provides a technology stack, a product stack, an overall architecture for all software layers, design guidelines as well as program guidelines. There also exists much source code stuff, where interests may track the architecture by studying examples. Please visit http://struts-it.org or for Germans http://struts-it.de. To avoid implementation some frameworks are fixed in this architecture:

  • Struts: A presentation framework for offering a MVC paradigm as well as a validation framework, a layout manager (Tiles) and a workflow component.
  • Velocity: A template engine to build dynamic html-pages.
  • HiveMinde An inversion-of-control framework to build low coupled service components.
  • Hibernate An O/R mapping tool.

Beside these components every architecture has to offer solutions for many other things e.g. logging, exception handling or testing. The most of these activities can be solved by using frameworks like AOP, log4j, junit and so on. The four named frameworks are the fundament of the struts-it architecture. The main constructs of the architecture are:

  • There is a thread-safe context with the whole lifecycle from request to response.
  • This context maybe shared in the same session between many requests that belongs to the same use case.
  • Services, which hold the business logic, will be called by name. For the programmer it is transparent if the service is pooled, a singleton or whatever.
  • Services may be generic (only a execute() Method) or pronounced with methods of the business logic.
  • Standard return codes of action such like "hasSucceeded" or "hasFailure" will be supported directly.

So this little example just shows where the journey ends: Easy solutions for tasks which are recurring. As an example here a typical program approach: A struts-action in struts-it manner:

   
    public boolean execute(StrutsitContext context) throws Exception {

        // Cast the context to the proper type
        HibernateContext hibContext = (HibernateContext) context;

        // Gets a service out of the HiveMind Registry
        Service service = getService("applicationservice.Login");
        
        // Puts an activity into the context
        hibContext.setAction(Constants.LOGIN_COMPARE_PASSWD);

        // Executes the service
        service.execute(hibContext);

        // evaluate the result of the service
        if (hibContext.getResult() == false) {
            // Deal with struts error messages
            ActionMessages messages = new ActionMessages();
            messages.add("", new ActionMessage("error.nameOrPassword"));
            saveMessages(hibContext.getRequest(), messages);
            // return to input page
            setInput(context);
        } else {
            // return and go to next workflow step
            setSucceeded(context);
        }

        // clears the ressources
        hibContext.resetForm();
        hibContext.release();

        return true;
    }
  
  

Struts-it layer architecture

A typical layer structure is like this:

  • Presentation Layer: MVC (model-view-control) is best practice designing a user interface nevertheless the user interface is swing-, swt- or browser based. A MVC-framework like struts is a "must have".

  • Service Layer: The service layer is the entry point to the business logic and the -workflow. Good designed technical services as email, caching etc. may be shared across several projects. But perhaps it is also possible to share other components like roles.

  • Persistence Layer: This layer is the entry point to the database. Often along an entry point (perhaps a specific persistence service) there is a framework to do the O/R mapping like hibernate.

Beside this components every architecture has to offer solutions for many other things e.g. logging, exception handling or testing. The most of these activities can be solved by using frameworks like log4j, junit and so on.

The architecture part of struts-it will offer several components for a ready to go component architecture. This architecture is not bundled to struts, it can be used with several frameworks. Because our favorite presentation framework is struts, the implementation all belongs to this framework.