Cocoon Framework in JAVA

What is the Cocoon Framework in JAVA?

As defined by its founding company, Apache INC, the “Cocoon framework in JAVA is built around the concepts of separation of concerns and component-based development”. This framework is extensively used to develop enterprise applications.

Why use the Cocoon Framework?

One of the main features of the cocoon framework is its ability to make pipelines that connect various parts of the program to form one single application. Cocoon divides a particular project into various parts where each part specializes in the function it has been built for. With the help of the pipeline, a Lego(TM) like approach is achieved and the various components are hooked together. While this helps modularize the code, it also does not require users to write any extra lines of code to connect one part to the other.

Features of the Cocoon Framework

  • Many developers describe the Cocoon as a web glue. Not only does it keep all the parts of a project together but also removes a lot of structural issues. This removes a lot of conflicts and chances of unexpected program breakdown. The Lego-like structure separates the conflicts from the main program thereby boosting the performance of the application.
  • Abstraction forms a major part of the framework’s view component. Clients are only shown the final response to a request that has been made. The complex implementations request processing cycle is abstracted thereby keeping a simple user interface. Continuation-based page flow technology is used to achieve this.
  • The Cocoon framework works hand in glove with the Spring framework. It also allows links to be made with other Java binding frameworks like the Castor and Betwixt.
  • The Cocoon form feature is a relatively new concept that was introduced with the latest update from the framework. As the name suggests, it assists in extracting and handling data from forms.

Advantages and Uses of the Cocoon framework

As the cocoon provides a significant amount of abstraction, it is used in a lot of cases where such a technique is required. Not only does it ease the work of developers during debugging but also keeps the interface easy to use for clients. The Cocoon Portal Framework is a readymade template that is widely used to create portals for web-based companies. With the help of the Spring framework, Cocoon provides good language support and also manages to deal with more than one client at a time. For the purposes of project documentation, the Forest Run Mode can be used effectively.

Cocoon Blocks – Architecture

As mentioned before, the Cocoon architecture follows the process of modularization by breaking the code into several blocks. There are three main blocks that are present in all cocoon-based applications: Spring Integration, Sitemap, and Pipeline implementation. The blocks deal with different concepts. The pipeline architecture thereafter glues the blocks together. The blocks contain groups of classes and several resources and can be stored as JAR (java archive) files.

Real-life example of Pipelining in Cocoon

/*This example will showcase various blocks of a cocoon framework application and their pipelined architecture. */

<?xml version = “1.0” encoding = “UTF - 8”?>
<beans xmlns = “http://www.cocoonframework.org/schema/beans”
xmlns:xsi = “http://www.w3.org/2001/XMLSchema-instance”
xmlns:servlet = http://cocoon.apache.org/schema/servlet
xsi:schemaLocation = “http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://cocoon.apache.org/schema/servlet http://cocoon.apache.org/schema/servlet/cocoon-servlet-1.0.xsd">
<bean id="com.myExample.myCocoonBlock1.service" class="org.apache.cocoon.sitemap.SitemapServlet">
<servlet:context mount-path="/myCocoonBlock1" context-path="blockcontext:/myCocoonBlock1/">
<servlet:connections>
<entry key="myCocoonBlock2" value-ref="com.myExample.myCocoonBlock2.service"/>
</servlet:connections>
</servlet:context>
</bean>
</beans>




//The following is a linker between the two blocks of the cocoon framework

<?xml version = “1.0” encoding = “UTF-8”?>
<project>
[..]
<dependencies>
[..]
<dependency>
<groupId>com.SampleCode</groupId>
<artifactId>myCocoonBlock2</artifactId>
<version>1.0-SNAPSHOT</version>
</dependecy>
</dependencies>
[…]
</project>




//Once the link has been created, we will set the pipeline on the first cocoon block

<?xml version = “1.0” encoding = “UTF-8”>

<map:sitemapxmlns:map = “http://apache.org/cocoon/sitemap/1.0”>
<map:pipelines>
[..]
<map:pipeline>
<map:match pattern = “callingBlock2”>
<map: generatesrc=”servlet:myCocoonBlock2:/spring-bean” type=”file”/>
<map:serialize type = “xml”/>
</map:match>
</map:pipeline>
[…]
</map:pipelines>
</map:sitemap>

 

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.