512 lines
18 KiB
HTML
512 lines
18 KiB
HTML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE html
|
|
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
|
"DTD/xhtml1-strict.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
<head>
|
|
<title>Checks for J2EE coding problems</title>
|
|
<link rel="stylesheet" type="text/css" href="mystyle.css"/>
|
|
</head>
|
|
|
|
<body>
|
|
<!-- The header -->
|
|
<table border="0" width="100%" summary="header layout">
|
|
<tr>
|
|
<td><h1>Checks for J2EE coding problems</h1></td>
|
|
<td align="right"><img src="logo.png" alt="Checkstyle Logo"/></td>
|
|
</tr>
|
|
</table>
|
|
<!-- content -->
|
|
<table border="0" width="100%" cellpadding="5" summary="body layout">
|
|
<tr>
|
|
<!--Left menu-->
|
|
<td class="menu" valign="top">
|
|
<ul>
|
|
<li>
|
|
<a href="#EntityBean">EntityBean</a>
|
|
</li>
|
|
<li>
|
|
<a href="#FinalStatic">FinalStatic</a>
|
|
</li>
|
|
<li>
|
|
<a href="#LocalHomeInterface">LocalHomeInterface</a>
|
|
</li>
|
|
<li>
|
|
<a href="#LocalInterface">LocalInterface</a>
|
|
</li>
|
|
<li>
|
|
<a href="#MessageBean">MessageBean</a>
|
|
</li>
|
|
<li>
|
|
<a href="#RemoteHomeInterface">RemoteHomeInterface</a>
|
|
</li>
|
|
<li>
|
|
<a href="#RemoteInterface">RemoteInterface</a>
|
|
</li>
|
|
<li>
|
|
<a href="#SessionBean">SessionBean</a>
|
|
</li>
|
|
<li>
|
|
<a href="#ThisParameter">ThisParameter</a>
|
|
</li>
|
|
<li>
|
|
<a href="#ThisReturn">ThisReturn</a>
|
|
</li>
|
|
</ul>
|
|
</td>
|
|
<!--Content-->
|
|
<td class="content" valign="top" align="left">
|
|
|
|
<!-- --><a name="EntityBean"></a> <h2>EntityBean</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Checks that a direct entity bean, i.e. a class that directly implements
|
|
<span class="code">javax.ejb.EntityBean</span>, satisfies these class requirements:
|
|
</p>
|
|
<ul>
|
|
<li class="body">
|
|
The class is defined as <span class="code">public</span>.
|
|
</li>
|
|
<li class="body">
|
|
The class cannot be defined as <span class="code">final</span>.
|
|
</li>
|
|
<li class="body">
|
|
It contains a <span class="code">public</span> constructor with no parameters.
|
|
</li>
|
|
<li class="body">
|
|
It must not define the <span class="code">finalize</span> method.
|
|
</li>
|
|
</ul>
|
|
<p class="body">
|
|
Checks that methods of a direct entity bean satisfy these requirements:
|
|
</p>
|
|
<ul>
|
|
<li class="body">
|
|
All <span class="code">ejbCreate<METHOD>(...)</span> methods are
|
|
<span class="code">public</span>, not <span class="code">final</span>, and not
|
|
<span class="code">static</span>.
|
|
</li>
|
|
<li class="body">
|
|
The return type of all <span class="code">ejbCreate<METHOD>(...)</span>
|
|
methods is not <span class="code">void</span>, because the return type must be
|
|
the entity bean's primary key type.
|
|
</li>
|
|
<li class="body">
|
|
All <span class="code">ejbPostCreate<METHOD>(...)</span> methods are
|
|
<span class="code">public</span>, not <span class="code">final</span>, and not
|
|
<span class="code">static</span>.
|
|
</li>
|
|
<li class="body">
|
|
The return type of all <span class="code">ejbPostCreate<METHOD>(...)</span>
|
|
methods is <span class="code">void</span>.
|
|
</li>
|
|
<li class="body">
|
|
For each <span class="code">ejbCreate<METHOD>(...)</span> method there is
|
|
a matching <span class="code">ejbPostCreate<METHOD>(...)</span> method.
|
|
</li>
|
|
</li>
|
|
<li class="body">
|
|
All <span class="code">ejbHome<METHOD>(...)</span> methods are
|
|
<span class="code">public</span>, and not <span class="code">static</span>.
|
|
</li>
|
|
<li class="body">
|
|
The throws clause of all <span class="code">ejbHome<METHOD>(...)</span>
|
|
methods does not define the <span class="code">java.rmi.RemoteException</span>.
|
|
</li>
|
|
</ul>
|
|
|
|
<p class="body">
|
|
When the check is configured to check direct entity beans as having bean-managed
|
|
persistence, checks that methods satisfy these additional requirements:
|
|
</p>
|
|
<ul>
|
|
<li class="body">
|
|
All <span class="code">ejbFind<METHOD>(...)</span> methods are
|
|
<span class="code">public</span>, not <span class="code">final</span>, and not
|
|
<span class="code">static</span>.
|
|
</li>
|
|
<li class="body">
|
|
The return type of all <span class="code">ejbFind<METHOD>(...)</span>
|
|
methods is not <span class="code">void</span>, because the return type must be
|
|
the entity bean's primary key type, or a collection of primary keys.
|
|
</li>
|
|
<li class="body">
|
|
There is a <span class="code">ejbFindByPrimaryKey</span> method with one parameter.
|
|
</li>
|
|
</ul>
|
|
<p class="body">
|
|
When the check is configured to check direct entity beans as having container-managed
|
|
persistence, checks that methods satisfy these additional requirements:
|
|
</p>
|
|
<ul>
|
|
<li class="body">
|
|
The throws clause of all <span class="code">ejbCreate<METHOD>(...)</span>
|
|
methods defines the <span class="code">javax.ejb.CreateException</span>.
|
|
</li>
|
|
<li class="body">
|
|
All <span class="code">ejbSelect<METHOD>(...)</span> methods are
|
|
<span class="code">public</span> and <span class="code">abstract</span>.
|
|
</li>
|
|
<li class="body">
|
|
The throws clause of all <span class="code">ejbSelect<METHOD>(...)</span>
|
|
methods defines the <span class="code">javax.ejb.FinderException</span>.
|
|
</li>
|
|
</ul>
|
|
|
|
|
|
<h4>Properties</h4>
|
|
<table width="100%" border="1" cellpadding="5" class="body">
|
|
<tr class="header">
|
|
<th>name</th>
|
|
<th>description</th>
|
|
<th>type</th>
|
|
<th>default value</th>
|
|
</tr>
|
|
<tr>
|
|
<td>persistence</td>
|
|
<td>type of persistence management</td>
|
|
<td><a href="property_types.html#persistence">persistence policy</a></td>
|
|
<td><span class="default">mixed</span></td>
|
|
</tr>
|
|
</table>
|
|
<p class="body">
|
|
Reference: Enterprise JavaBeans™ Specification,Version 2.0, sections
|
|
10.6 and 12.2.
|
|
</p>
|
|
<h4>Example</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="j2ee.EntityBean"/>
|
|
</pre>
|
|
<p class="body">
|
|
To configure the check to apply the <span class="code">container</span> policy to direct entity beans:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="j2ee.EntityBean">
|
|
<property name="persistence" value="container"/>
|
|
</module>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.j2ee
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --><a name="FinalStatic"></a> <h2>FinalStatic</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Checks that all static fields are declared final.
|
|
</p>
|
|
<p class="body">
|
|
Rational: This check ensures consistent runtime semantics so that EJB containers have
|
|
the flexibility to distribute instances across multiple JVMs.
|
|
</p>
|
|
<p class="body">
|
|
Reference: <a href="http://www.javaworld.com/javaworld/jw-08-2000/jw-0825-ejbrestrict.html">Programming restrictions on EJB</a>.
|
|
</p>
|
|
<h4>Example</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="j2ee.FinalStatic"/>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.j2ee
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --><a name="LocalHomeInterface"></a> <h2>LocalHomeInterface</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Checks that a direct local home interface, i.e. an interface that directly extends
|
|
<span class="code">javax.ejb.EJBLocalHome</span>, satisfies these requirements:
|
|
</p>
|
|
<ul>
|
|
<li class="body">
|
|
The return type of all <span class="code">create<METHOD>(...)</span>
|
|
methods is not <span class="code">void</span>, because the return type must be
|
|
the bean's local interface.
|
|
</li>
|
|
<li class="body">
|
|
The throws clause of all <span class="code">create<METHOD>(...)</span>
|
|
methods defines the <span class="code">javax.ejb.CreateException</span>.
|
|
</li>
|
|
<li class="body">The throws clause of all methods does not define the <span class="code">java.rmi.RemoteException</span>.</li>
|
|
</ul>
|
|
<p class="body">
|
|
Reference: Enterprise JavaBeansTM Specification,Version 2.0, sections 6.4 and 9.6.
|
|
</p>
|
|
<h4>Example</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="j2ee.LocalHomeInterface"/>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.j2ee
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --><a name="LocalInterface"></a> <h2>LocalInterface</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Checks that a direct local interface, i.e. an interface that directly extends
|
|
<span class="code">javax.ejb.EJBLocalObject</span>, satisfies these requirements:
|
|
</p>
|
|
<ul>
|
|
<li class="body">The throws clause of all methods does not define the <span class="code">java.rmi.RemoteException</span>.</li>
|
|
</ul>
|
|
<p class="body">
|
|
Reference: Enterprise JavaBeansTM Specification,Version 2.0, section 9.10.
|
|
</p>
|
|
<h4>Example</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="j2ee.LocalInterface"/>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.j2ee
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --><a name="MessageBean"></a> <h2>MessageBean</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Checks that a direct message bean, i.e. a class that directly implements
|
|
<span class="code">javax.ejb.MessageDrivenBean</span> and
|
|
<span class="code">javax.jms.MessageListener</span>, satisfies these class requirements:
|
|
</p>
|
|
<ul>
|
|
<li class="body">
|
|
The class is defined as <span class="code">public</span>.
|
|
</li>
|
|
<li class="body">
|
|
The class cannot be defined as <span class="code">final</span>.
|
|
</li>
|
|
<li class="body">
|
|
The class cannot be defined as <span class="code">abstract</span>.
|
|
</li>
|
|
<li class="body">
|
|
It contains a <span class="code">public</span> constructor with no parameters.
|
|
</li>
|
|
<li class="body">
|
|
It must not define the <span class="code">finalize</span> method.
|
|
</li>
|
|
<li class="body">
|
|
It defines an <span class="code">ejbCreate()</span> method this is
|
|
<span class="code">public</span>, not <span class="code">final</span>,
|
|
not <span class="code">static</span>, has no parameters, and has
|
|
return type <span class="code">void</span>.
|
|
</li>
|
|
</ul>
|
|
|
|
<p class="body">
|
|
Reference: Enterprise JavaBeans™ Specification,Version 2.0, section 15.7.
|
|
</p>
|
|
<h4>Example</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="j2ee.MessageBean"/>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.j2ee
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --><a name="RemoteHomeInterface"></a> <h2>RemoteHomeInterface</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Checks that a direct remote home interface, i.e. an interface that directly extends
|
|
<span class="code">javax.ejb.EJBHome</span>, satisfies these requirements:
|
|
</p>
|
|
<ul>
|
|
<li class="body">
|
|
The return type of all <span class="code">create<METHOD>(...)</span>
|
|
methods is not <span class="code">void</span>, because the return type must be
|
|
the bean's remote interface.
|
|
</li>
|
|
<li class="body">
|
|
The throws clause of all <span class="code">create<METHOD>(...)</span>
|
|
methods defines the <span class="code">javax.ejb.CreateException</span>.
|
|
</li>
|
|
<li class="body">The throws clause of all methods defines the <span class="code">java.rmi.RemoteException</span>.</li>
|
|
</ul>
|
|
<p class="body">
|
|
Reference: Enterprise JavaBeansTM Specification,Version 2.0, sections 6.3 and 9.5.
|
|
</p>
|
|
<h4>Example</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="j2ee.RemoteHomeInterface"/>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.j2ee
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --><a name="RemoteInterface"></a> <h2>RemoteInterface</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Checks that a direct remote interface, i.e. an interface that directly extends
|
|
<span class="code">javax.ejb.EJBObject</span>, satisfies these requirements:
|
|
</p>
|
|
<ul>
|
|
<li class="body">The throws clause of all methods defines the <span class="code">java.rmi.RemoteException</span>.</li>
|
|
</ul>
|
|
<p class="body">
|
|
Reference: Enterprise JavaBeansTM Specification,Version 2.0, section 9.9.
|
|
</p>
|
|
<h4>Example</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="j2ee.RemoteInterface"/>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.j2ee
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
<!-- --><a name="SessionBean"></a> <h2>SessionBean</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Checks that a direct session bean, i.e. a class that directly implements
|
|
<span class="code">javax.ejb.SessionBean</span>, satisfies these class requirements:
|
|
</p>
|
|
<ul>
|
|
<li class="body">
|
|
The class is defined as <span class="code">public</span>.
|
|
</li>
|
|
<li class="body">
|
|
The class cannot be defined as <span class="code">final</span>.
|
|
</li>
|
|
<li class="body">
|
|
The class cannot be defined as <span class="code">abstract</span>.
|
|
</li>
|
|
<li class="body">
|
|
It contains a <span class="code">public</span> constructor with no parameters.
|
|
</li>
|
|
<li class="body">
|
|
It must not define the <span class="code">finalize</span> method.
|
|
</li>
|
|
<li class="body">
|
|
It defines an <span class="code">ejbCreate<METHOD>()</span> method this is
|
|
<span class="code">public</span>, not <span class="code">final</span>,
|
|
not <span class="code">static</span>, and has
|
|
return type <span class="code">void</span>.
|
|
</li>
|
|
</ul>
|
|
|
|
<p class="body">
|
|
Reference: Enterprise JavaBeans™ Specification,Version 2.0, section 7.10.
|
|
</p>
|
|
<h4>Example</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="j2ee.SessionBean"/>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.j2ee
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
|
|
<!-- --><a name="ThisParameter"></a> <h2>ThisParameter</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Checks that <span class="code">this</span> is not a parameter of any method calls or constructors for a bean.
|
|
Instead, you must use the result of the <span class="code">getEJBObject()</span> available in
|
|
<span class="code">SessionContext</span> or <span class="code">EntityContext</span>.
|
|
</p>
|
|
<p class="body">
|
|
Reference: <a href="http://www.javaworld.com/javaworld/jw-08-2000/jw-0825-ejbrestrict.html">Programming restrictions on EJB</a>.
|
|
</p>
|
|
<h4>Example</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="j2ee.ThisParameter"/>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.j2ee
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
|
|
<!-- --><a name="ThisReturn"></a> <h2>ThisReturn</h2> <h4>Description</h4>
|
|
<p class="body">
|
|
Checks that <span class="code">this</span> is not returned by a bean method.
|
|
Instead, you must use the result of the <span class="code">getEJBObject()</span> available in
|
|
<span class="code">SessionContext</span> or <span class="code">EntityContext</span>.
|
|
</p>
|
|
<p class="body">
|
|
Reference: <a href="http://www.javaworld.com/javaworld/jw-08-2000/jw-0825-ejbrestrict.html">Programming restrictions on EJB</a>.
|
|
</p>
|
|
<h4>Example</h4>
|
|
<p class="body">
|
|
To configure the check:
|
|
</p>
|
|
<pre class="body">
|
|
<module name="j2ee.ThisReturn"/>
|
|
</pre>
|
|
<h4>Package</h4>
|
|
<p class="body">
|
|
com.puppycrawl.tools.checkstyle.checks.j2ee
|
|
</p>
|
|
<h4>Parent Module</h4>
|
|
<p class="body">
|
|
<a href="config.html#treewalker">TreeWalker</a>
|
|
</p>
|
|
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<hr />
|
|
<div><a href="index.html">Back to the Checkstyle Home Page</a></div>
|
|
<p class="copyright">
|
|
Copyright © 2002-2004 Oliver Burn. All rights Reserved.
|
|
</p>
|
|
|
|
</body>
|
|
</html>
|