রবিবার, ১২ ফেব্রুয়ারী, ২০১২

ABCD on seam

Seam Framework is one of the most successful integration frameworks that joins together multiple software components.

Integration is one of the hardest problems in enterprise application development. A
multitier application is typically made up of many components, such as transactional services, security, data persistence, asynchronous messaging, UI rendering, etc. Those components are developed in different frameworks and libraries; they often have different programming models and scalability characteristics. The need to make those components work with each other has given rise to integration frameworks.Seam integrates a number of other leading open source frameworks, such as jBPM, JBoss Rules (a.k.a. Drools), iText, and Spring.


The core framework of JEE 5.0 are:
1. EJB 3.0
2. JSF 1.2

(EJB 3.0 converts POJO into business service object and database persistence object)
(JSF is MVC component framework)
In JEE uses both EJB for business logic and JSF for front end.
Complementary to each others and designed as separate framework, each with its own philosophy.they are not aware of each other at the framework level.To make EJB3 and JSF work together, you need artificial facade objects.Gluing
those technologies together is part of Seam’s responsibilities.
Seam collapses the artificial layer between EJB3 and JSF and provides a consistent,
annotation-based approach to integrate .It provides a consistent,annotation-based approach to integrate EJB3 and JSF.

JSF is that it relies too much on HTTP POST and hard to bookmark a JSF web page and then get it via HTTP GET but Seam is solve the problem.


With Seam, there are no more DTOs to write, lazy loading just works, and
ORM performance can be greatly improved because the extended persistence context acts as a natural cache to reduce database roundtrips.


Seam was designed for stateful web applications.


Furthermore, database caches and transactions can be automatically tied with the appli-cation state in Seam. Seam automatically holds database updates in memory and commits to the database only at the end of a conversation.

Seam is fully optimized for Web 2.0 applications.

Seam wires POJO components together using a popular design pattern known as depen-dency injection (DI)
.

Writing a Seam web application is conceptually very simple. You only need to code
the following components:

• Entity objects that represent the data model. These entity objects could be entity
beans in the Java Persistence API (JPA, a.k.a. EJB3 persistence) or Hibernate POJOs.
They are automatically mapped to relational database tables.

• JSF web pages that display the user interface. These pages capture user input via
forms and display the data. The data fields on the page are mapped to the backend
data model via the JSF Expression Language (EL).

• EJB3 session beans or annotated Seam POJOs that act as UI event handlers for the
JSF web pages. They update the data model based on the user input.


Seam manages all these components and automatically injects them into the right pages or objects at runtime. For instance, when the user clicks a button to submit a JSF form, Seam automatically parses the form fields and constructs an entity bean. Then Seam passes the entity bean into the event handler session bean, which Seam also creates, for processing. You do not need to manage component lifecycles and relationships between components in your code. There is no boilerplate code and no XML file for dependency management.

Dependency bijection:

Seam wires POJO components together using a popular design pattern known as depen-dency injection (DI). Under this pattern, the Seam framework manages the lifecycle of all the components. When a component needs to use another, it declares this dependency to Seam using annotations. Seam determines where to get this dependent component based on the application’s current state and “injects” it into the asking component.

Expanding on the dependency injection concept, a Seam component A can also create another component B and “outject” the created component B back to Seam for other components, such as C, to use later.
In Seam terms, we call this dependency bijection.

Convention over Configuration

The idea is to have a set of common-sense default behaviors for the components (i.e., the convention). The developer needs to configure the component explicitly only when the desired behavior is not the default.
Overall, the configuration metadata in Seam is much simpler than in competing Java frameworks.




Seam designers recognize that XML is well suited to specifying web application pageflows or defining business process workflows. The XML file enables us to centrally manage the workflow for the entire application, as opposed to scattering the information around in Java source files.




@Entity
@Name("person")
public class Person implements Serializable {

private long id;
private String name;

@Id @GeneratedValue
public long getId() { return id;}

public void setId(long id) { this.id = id; }

public String getName() { return name; }

public void setName(String name) {
this.name = name;
}

}


The @Entity annotation tells the container to map this class to a relational
database table, with each property a column in the table.
The most important annotation in the Person class is the @Name annotation. It specifies the string name the Person bean should be registered by under Seam. In other Seam components (e.g., JSF web pages and session beans), you can reference the managed Person bean using the person name.


In the JSF page, we use the Person bean to back the form’s input text field. The
#{person.name} symbol refers to the name property on the Seam component named
person, which is an instance of the Person entity bean as we just discussed. The #{...} notation to reference Java objects is called JSF Expression Language (EL). It is widely used in Seam.


<h:form>
Please enter your name:<br/>
<h:inputText value="#{person.name}" size="15"/><br/>
<h:commandButton type="submit" value="Say Hello"
action="#{manager.sayHello}"/>
</h:form>






The manager component in Seam is the ManagerAction session bean, identified by the @Name annotation on the class. Notice that we use the @Stateful annotation here as Seam works best with stateful session beans (for details, refer to the end of this section). The ManagerAction class has a person field with the @In annotation.


@Stateful
@Name("manager")
public class ManagerAction implements Manager {
@In
private Person person;










//////////////////////////

Statefull framework

The real jewel of Seam is its support for sophisticated application state management that is not available in any other web application framework today.
The state management facilities in Seam are independent of JSF or EJB.

lazy loading:
When the framework loads an object from the relational database, it does not necessarily load all its associated objects.

If the web presentation layer attempts to lazy-
load associated objects after Spring returns, an exception will be thrown




To avoid the nasty lazy loading exceptions, developers have to work around the
framework using hacks such as Data Transfer Objects (DTOs) or messing with
the database queries or schema.a Seam component keeps the persistence context valid from the time
when an HTTP request is submitted to the time when the response page is fully renderedWe can pass
entity objects (i.e., EJB3 entity beans) directly across the business layer and the presen-
tation layer without the need to wrap them in DTO



Here is a list of stateful contexts in Seam:
stateless Components in this context are completely stateless and do not hold any
state data of their own.
event This is the narrowest stateful context in Seam. Components in this context
maintain their state throughout the processing of a single JSF request.
page Components in this context are tied to a specific page. You can have access to
these components from all events emitted from that page.
conversation In Seam, a conversation is a series of web requests to accomplish a
certain task (e.g., to check out the shopping cart). Components tied to a conversation
context maintain their state throughout the conversation. The conversation context
is the most important context in Seam; it is discussed in more detail in Chapter 8.
session Components in the session context are managed in an HTTP session object.
They maintain their state until the session expires. You can have multiple
conversations in a session.
business process This context holds stateful components associated with a long-
running business process managed in the JBoss jBPM (Business Process Manager)
engine. While all the previously discussed contexts manage stateful components
for a single web user, the business process components can span across several
users. We will explore this in more detail in Chapter 24.
application This is a global context that holds static information. There is no concept of web users in this context.