blob: 5d019cbdc920f521034c39b91dcefc0f8596b777 [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="../../../../../webtools/wtp.xsl"?>
<html>
<head>
<meta
name="root"
content="../../../../.." />
<title>j2ee models</title>
</head>
<body>
<h1>jst j2ee component</h1>
<h2>Intoduction</h2>
<p>
The J2EE Component provides the core models and API for J2EE 1.2, 1.3 and
1.4 specification levels artifacts. The core models are for creating and
loading the J2EE artifacts (Enterprise Applications, Application Clients,
Web Applications, Web Services, Enterprise Java Bean and Connectors). All
the J2EE core models exist in the
<b>org.eclipse.jst.j2ee.core</b>
plugin of the j2ee sub component of the jst sub project. The details of
each of core j2ee models usage and api are discussed in the following
sections.
</p>
<h2>J2EE Components</h2>
<p>
In WTP, J2EE projects include a entry for ModuleCoreNature, that indicates metadata
is present for the modulecore model. This model represents the different j2ee component types,
and how they are structured.
<br />
The snippet of code below shows how a VirtualComponent is accessed from a project that contains the ModuleCoreNature.
<pre>
FlexibleProject flexProj = ComponentCore.createFlexibleProject(anIProject);
IVirtualComponent comp = flexProj.createComponent(compName);
</pre>
</p>
<h2>ArtifactEdit</h2>
<p>
ArtifactEdit classes are a mechanism to create and load emf resources from the emf
resource set in read or write mode. When opened in either mode they have
to be released after the work with the resource is done. The need for
releasing these edit models is needed because accessing the edit models
increments the resource count by 1 on the actual resource in the resource
set. This mechanism of incrementing the resource count is used for
resource synchronization. There are artifact edit classes defined for each j2ee
module type to handle creation,load and editiing scenarios of the their deployment
descriptor resources.
<br />
The snippet of code below shows how an EJBArtifactEdit is created from a component
and used get the list on all the enterprise bean in the EJB Jar module:
<pre>
public List getEnterpriseBeans(IVirtualComponent comp) {
EJBArtifactEdit ejbArtifactEdit = null;
try{
ejbArtifactEdit =
EJBArtifactEdit.getEJBArtifactEditForRead(comp);
List enterpriseBeans =
ejbArtifactEdit.getEJBJar().getEnterpriseBeans();
return enterpriseBeans;
}
finally {
if(ejbArtifactEdit != null) {
ejbArtifactEdit.dispose();
}
}
}
</pre>
</p>
<p>
Quick EMF model overview:
A resource set (@ResourceSet) manages a collection of resources (@link #getResource) A
resource contains api to view the (@link #getAllContents) collection of EMF Objects.
A resource can be created (@link #createResource) or demand loaded (@link
#getResource(URI, boolean)) into the resource set collection. A proxy can
be {@link #getEObject} can be resolved by the resource set, and may cause
the demand load of a resource.
</p>
<h2>Common J2EE Model</h2>
<p>
The common J2EE model represents the common schema elements that are
created and used across all the j2ee modules. The
<b>org.eclipse.jst.j2ee.common</b>
java package contains the api for creating and accessing the common
elements
<b>
(description, displayName, small-icon,large-icon,ejb-ref,
resource-ref,resource-env-ref,message-desintations-refs,service-refs,message-destinations,security-roles
etc.)
</b>
. The following diagram depicts all the elements of the common model that
is being shared across all j2ee module models.
<br />
<img
border="0"
src="../images/CommonRefs.jpg" />
<br />
</p>
<h2>Enterprise Application Model</h2>
<p>
The
<b>org.eclipse.jst.j2ee.application</b>
package contains all the api for creating an Application module and the
nested modules (Application Client, Web, EJB and Connector) in the
Application.
</p>
<p>
The snippet of code below shows how to create an Application:
ApplicationFactory.eINSTANCE.createApplication();
<br />
The ApplicationFactory interface has addtional api to create j2ee modules
as listed below
<br />
<pre>
WebModule createWebModule();
JavaClientModule createJavaClientModule();
EjbModule createEjbModule();
ConnectorModule createConnectorModule();
ApplicationPackage getApplicationPackage();
</pre>
<br />
The Application needs to have a minimum of one module as per J2EE
specification. The modules can be created as standalone modules or along
with an EAR with the module added to the EAR. The standalone module
creation api are mentioned in the corresponding module sections below.
The following diagram depicts all the elements in the Application that
constitutes the Enteprise Application resource (EARFile). The Application
needs to have a minimum of one module as per J2EE specification. The
modules can created as part of EAR creation or individually as standalone
modules. The UML model below depicts the elements of an Application and
that contitute the application.xml file.
<br />
<img
border="0"
src="../images/Application.jpg" />
<br />
The
<b>Application</b>
Interface class provides all the necessary api to elements on the
Application model. Here are the api avialable on the Application
Interface class
<pre>
/*Returns the first module matching the specified uri*/
public Module getFirstModule(String uri);
/**Returns the first module where the alt dd matches the specified uri*/
public Module getModuleHavingAltDD(String uri);
/*Returns the Securtiy Role in the Application matching the name*/
public SecurityRole getSecurityRoleNamed(String name);
</pre>
</p>
<h2>Application Client Model</h2>
<p>
The
<b>org.eclipse.jst.j2ee.client</b>
java package contains all the interfaces and api for creating and
accessing the elements
<b>(env-entry,callback-handler etc.)</b>
an Application Client module. The ApplicationClient interface class has
the all the api to get to the elemmts that constitutes the deployment
decriptor
<b>(application-client.xml)</b>
. The ClientFactory interface is used to create an instances of an
Applciation Client. The following diagram depitcs all the elements of an
Application Client module that constitutes the Application Client jar
(JavaClientFile).
<br />
<img
border="0"
src="../images/ApplicationClient.jpg" />
<br />
The snippet of code below shows how an AppClientArtifactEdit is accessed
from a passed component and used to get the list of EJB
references in the Application Client resource.
<pre>
public List getEJBReferences(IVirtualComponent appClientComponent) {
AppClientArtifactEdit appClientArtifactEdit = null;
try {
appClientArtifactEdit =
AppClientArtifactEdit.getAppClientArtifactEditForRead(appClientComponent);
return appClientArtifactEdit.getApplicationClient().getEjbReferences();
}
finally {
if(appClientArtifactEdit != null)
appClientArtifactEdit.dispose();
}
}
</pre>
</p>
<h2>Web Application Model</h2>
<p>
The
<b>org.eclipse.jst.j2ee.webapplication</b>
java package contains all the model api for creating and accessing the
elements
<b>
(context-param, servlet, servlet-mapping, session-config,
mime-mapping, welcome-file-list, error-page, taglib, resource-ref,
security-constraint, login-config, security-role, env-entry etc.)
</b>
of a Web App. The WebApp and WebResourceCollection are the interfaces
through which all the elements of WebApplication module can be accessed.
The
<b>org.eclipse.jst.j2ee.webapplication.impl</b>
package contains the concrete implemenation of the interface provided in
the
<b>org.eclipse.jst.j2ee.webapplication</b>
package. The following diagram depicts all the elements of a Web Module
module deployment descriptor that constitutes the Web Archive (WARFile)
<br />
<img
border="0"
src="../images/WebApp.jpg" />
<br />
The snippet of code below shows how a WebArtifactEdit is accessed from a Web component
to get the list of all the servlets in the web module.
<pre>
public List getServlets(IVirtualComponent webComponent) {
WebArtifactEdit webArtifactEdit = null;
try {
webArtifactEdit = WebArtifactEdit.getWebArtifactEditForRead(webComponent);
return webArtifactEdit.getWebApp().getServlets();
}
finally {
if(webArtifactEdit!= null)
webArtifactEdit.dispose();
}
}
</pre>
</p>
<h2>Enterprise Java Bean Model</h2>
<p>
The
<b>org.eclipse.jst.j2ee.ejb</b>
java package contains all the interfaces and api for creating and
accessing the elements
<b>
(enterprise-beans, relationships, assembly-descriptor,
ejb-client-jar)
</b>
of an Enterprise Java Bean module. The
<b>EJBJar</b>
interface contains all the api for accessing the elements of an
Enterprise Bean module. The
<b>EnterpriseBean</b>
interface provides the api for accessing the elements of an Enterprise
Java Bean. the The following diagram depicts all the elements of a EJB
resource that constitutes EJBJar (EJBJarFile).
<br />
<img
border="0"
src="../images/EJBJar.jpg" />
<br />
The snippet of code below shows how the EJBArtifactEdit is accessed for
write from an EJB component and a CMPAttribute is added to the
ContainerManagedEntity bean.
<pre>
public void addNewCMPAttributeToCMP(IVirtualComponent ejbComp, String cmpBeanName) {
EJBArtifactEdit ejbArtifactEdit = null;
try {
ejbArtifactEdit = EJBArtifactEdit.getEJBArtifactEditForWrite(ejbComp);
EJBJar ejbJar = ejbArtifactEdit.getEJBJar();
EnterpriseBean bean = ejbJar.getEnterpriseBeanNamed(cmpBeanName);
if(bean instanceof ContainerManagedEntity) {
ContainerManagedEntity cmpBean = (ContainerManagedEntity)bean;
CMPAttribute attr = EjbFactory.eINSTANCE.createCMPAttribute(); attr.setName("foo");
cmpBean.getCMPAttribute().add(attr);
}
ejbArtifactEdit.saveIfNecessary();
}
finally {
if(ejbArtifactEdit != null)
ejbArtifactEdit.dispose();
}
}
</pre>
</p>
<h2>Connector Model</h2>
<p>
The
<b>org.eclipse.jst.j2ee.jca</b>
java package contains all the interfaces and api for creating and
accessing the elemtns
<b>
(vendor-name, spec-version, eis-type, version, license,
resourceadapter,activation-spec)
</b>
of an Connector module. The
<b>Connector</b>
interface contains all the api for accessing the elements of an Connector
module. The
<b>ResourceAdapter</b>
interface provides all the api for accessing the elements of the
internals of an Connector modules. The following diagram depicts all the
elements of a Connector resource that constitutes Resource Archive
(RARFile).
<br />
<img
border="0"
src="../images/Connector.jpg" />
<br />
The snippet of code below shows how the ConnectorArtifactEdit is accessed
from a Connector component and to get the Config Properties in the
ResourceAdapter of the Connecter resource.
<pre>
public List getConnectorConfigProperties(IVirtualComponent comp) {
ConnectorArtifactEdit connectorArtifactEdit = null;
try {
connectorArtifactEdit = connectorRuntime.getConnectorArtifactEditForRead(comp);
return connectorArtifactEdit.getConnector().getResourceAdapter().getConfigProperties();
}
finally {
if(connectorArtifactEdit != null)
connectorArtifactEdit.dispose();
}
}
</pre>
</p>
<h2>Web Services Model</h2>
<p>
The
<b>org.eclipse.jst.j2ee.webservice.wsclient</b>
java package contains all the interfaces and api for creating and
accessing the elements
<b>(ports,handlers,serviceRefs, componentsScopedRefs etc.)</b>
of a Web Serices Client resource. The
<b>Webservice_clientFactory</b>
interface contains all the api for creating the elements of a Web Service
Client. The
<b>ComponentScopedRefs,Handler,PortComponentRef,ServiceRef</b>
interfaces contain the api for accessing the internal elements of a Web
Services client resource.The
<b>org.eclipse.jst.j2ee.webservice.wsdd</b>
package contains the api to access the elements of Web Services
Deployment Descriptor(WSDD). The
<b>WsddFactory</b>
interface contains the api for creating the elements of a WSDD resource.
The following diagram depicts all the elements of a WSDD and the
WebServicesClient resource.
<br />
<img
border="0"
src="../images/wsdd.jpg" />
<br />
<img
border="0"
src="../images/webserviceclient.jpg" />
<br />
</p>
</body>
</html>