<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns = "http://java.sun.com/xml/ns/javaee"
version = "3.0"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
<enterprise-beans>
<session>
<ejb-name>Table</ejb-name>
<business-local>javax.swing.table.TableModel</business-local>
<ejb-class>javax.swing.table.DefaultTableModel</ejb-class>
<session-type>Stateless</session-type>
</session>
</enterprise-beans>
</ejb-jar>
The ejb-jar archive is empty in this case - it only contains the deployment descriptor. However the declaration of this legacy POJO in xml allows it injection to an "usual", annotated session bean:
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.jws.WebService;
import javax.swing.table.TableModel;
@Stateless
@WebService
public class LegacyTestBean implements LegacyTest {
@EJB(beanName="Table")
private TableModel tableModel;
public String accessTable(){
return "Row count: " + tableModel.getRowCount();
}
}
The attribute "beanName" of the @EJB annotation refers to the name of the declared bean. As you can see, with just few lines of XML code it is possible to deploy almost every class as a session bean. The requirements are only:
EJB 3 are really interesting - even for very small and trivial projects. I checked in the whole project into p4j5. The projects name is "LegacyPojo" - it was tested with Glassfish V2 and Netbeans 6b1.
[See also page 37 in the "Real World Java EE Patterns - Rethinking Best Practices" book]