Click here to Skip to main content
11,925,851 members (62,744 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


7 bookmarked

Introduction to the Green-forest Framework

, 31 Jan 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
An introduction to the Green-forest Framework for creating a web application example.

Green-forest Logo


Green-forest Framework is a simple IoC Container with Action-Handler architecture. It's not a competitor for Spring Framework or JEE but it's a powerful addition for these frameworks. You can use Green-forest for a single class implementation or for complex business logic.

The Action-Handler architecture can be presented by this scheme:

As you see on the scheme we divide our logic into some classes:

  1. Action

  2. The Action class presents an "atomic business method" and contains input and output data:

    //Action with String input and Integer output data
    public class SomeAction extends Action<String, Integer>{
        public SomeAction(String input) {
  3. Handler

  4. The Handler class presents an implementation of business logic:

    public class SomeHandler extends Handler<SomeAction>{
        SomeService service;
        public void invoke(SomeAction action) throws Exception {
            String input = action.getInput();
            Integer result = service.doSomeWork(input);
  5. Framework

  6. The Framework's Engine ensures functioning of handlers:

    //create Engine instance
    Engine engine = new Engine();
    //register the handler
    //invoke the action
    Integer result = engine.invoke(new SomeAction("some data"));


What is the motivation for using the Green-forest framework? The main task is to simplify code: transfer of one big class (some service implementation) to a set of small classes (handlers).

See this example: "Classic" implementation presents one big class in 1000 lines of code:

//"classic" impl of API
public class SomeBigServiceImpl implements SomeService {
    public Doc createDoc(...){...}
    public Doc createDocWithAttach(...){...}
    public Doc getDocById(...){...}
    public List getDocsList(...){...}
    //and many many other methods on 1000 lines of a code

Action-Handler implementation presents a set of small classes:

//Action-Handler API
public class CreateDocHandler extends Handler<CreateDoc>{
  //10-20 lines of code

public class CreateDocWithAttachHandler extends Handler<CreateDocWithAttach>{
  //10-20 lines of code

public class GetDocByIdHandler extends Handler<GetDoc>{
  //10-20 lines of code

public class GetDocListHandler extends Handler<GetDocList>{
  //10-20 lines of code

Example application


Let's review a simple example application with Green-forest framework. It presents a web interface for users and uses a database for storage. With this application we can create, read, update, and delete simple objects.

Here is a view of the application's web interface:

You can download binaries and sources for this example from the article's download section. After downloading the "web-app-example.war" file, deploy it into your Web Server. This application was tested on a Tomcat 7.0.28 web server.

Explanation of example

First we present the model class for CRUD operations - Doc:

package example.common.model;

public class Doc {
    public long id;
    public String name;

After that we create the set of actions - our business API:


Every class of this set is an action class:

package example.common.action;

public class RenameDoc extends Action<Doc, Void> {
    public RenameDoc(int id, String newName){
        this(new Doc(id, newName));

So we can use these actions in our web layer:

package example.web;

public class AppServlet extends HttpServlet {

    public void doPost(HttpServletRequest req, HttpServletResponse resp) {
        //get data for update
        int id = Util.tryParse(req.getParameter("id"), -1);
        String newName = req.getParameter("name");
        //invoke update action
        application.invoke(new RenameDoc(id, newName));


And for every action we create its own handler:


public class RenameDocHandler extends Handler<RenameDoc>{
    Connection c;

    public void invoke(RenameDoc action) throws Exception {
        Doc input = action.input();
        PreparedStatement ps = c.prepareStatement("UPDATE doc SET name=? WHERE id=?");

That's it! We receive a set of compact simple classes for API (Actions) and for implementation (Handlers).


Green-forest Framework presents a new perspective on the development of Java applications. It's a free open-source tool which can simplify the code of your application. This library requires minimum time to learn and is suitable for a wide range of tasks. Happy coding with it!


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer (Senior)
Russian Federation Russian Federation
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralMy vote of 5 Pin
Fred Flams1-Feb-13 2:54
memberFred Flams1-Feb-13 2:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.151126.1 | Last Updated 31 Jan 2013
Article Copyright 2013 by evgeny.dolganov
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid