KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > checks > j2ee > ContainerManagedMethodChecker


1 ////////////////////////////////////////////////////////////////////////////////
2
// checkstyle: Checks Java source code for adherence to a set of rules.
3
// Copyright (C) 2001-2005 Oliver Burn
4
//
5
// This library is free software; you can redistribute it and/or
6
// modify it under the terms of the GNU Lesser General Public
7
// License as published by the Free Software Foundation; either
8
// version 2.1 of the License, or (at your option) any later version.
9
//
10
// This library is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
// Lesser General Public License for more details.
14
//
15
// You should have received a copy of the GNU Lesser General Public
16
// License along with this library; if not, write to the Free Software
17
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
////////////////////////////////////////////////////////////////////////////////
19
package com.puppycrawl.tools.checkstyle.checks.j2ee;
20
21 import com.puppycrawl.tools.checkstyle.api.DetailAST;
22 import com.puppycrawl.tools.checkstyle.api.TokenTypes;
23
24 /**
25  * Checks methods of entity beans with container-managed persistence.
26  * Reference: Enterprise JavaBeansTM Specification,Version 2.0, Chapter 10
27  * @author Rick Giles
28  */

29 public class ContainerManagedMethodChecker
30     extends EntityBeanMethodChecker
31 {
32     /**
33      * Constructs a ContainerManagedMethodChecker for a entity bean check.
34      * @param aCheck the entity bean check.
35      */

36     public ContainerManagedMethodChecker(EntityBeanCheck aCheck)
37     {
38         super(aCheck);
39     }
40
41     /**
42      * {@inheritDoc}
43      */

44     public void checkMethod(DetailAST aMethodAST)
45     {
46         super.checkMethod(aMethodAST);
47
48         final DetailAST nameAST = aMethodAST.findFirstToken(TokenTypes.IDENT);
49         final String JavaDoc name = nameAST.getText();
50
51         if (name.startsWith("ejbSelect")) {
52             checkSelectMethod(aMethodAST);
53         }
54     }
55
56     /**
57       * Checks whether an ejbSelect<METHOD>(...) method of an
58       * entity bean satisfies requirements.
59       * @param aMethodAST the AST for the method definition.
60       */

61     protected void checkSelectMethod(DetailAST aMethodAST)
62     {
63         // must be declared as public
64
if (!Utils.isPublic(aMethodAST)) {
65             log(aMethodAST, "nonpublic.bean", new Object JavaDoc[] {"Method"});
66         }
67         // The method must be declared as abstract.
68
if (!Utils.isAbstract(aMethodAST)) {
69             log(aMethodAST, "nonabstract.bean", new Object JavaDoc[] {"Method"});
70         }
71         // The throws clause must define the javax.ejb.FinderException.
72
checkThrows(aMethodAST, "javax.ejb.FinderException");
73     }
74
75      /**
76       * Checks whether an ejbCreate<METHOD>(...) method of an
77       * entity bean satisfies requirements.
78       * @param aMethodAST the AST for the method definition.
79       */

80     protected void checkCreateMethod(DetailAST aMethodAST)
81     {
82         super.checkCreateMethod(aMethodAST);
83
84         // The throws clause must define the javax.ejb.CreateException.
85
checkThrows(aMethodAST, "javax.ejb.CreateException");
86     }
87 }
88
Popular Tags