现在的位置: 首页 > 综合 > 正文

PMD规则之J2EE Rules

2013年10月02日 ⁄ 综合 ⁄ 共 2544字 ⁄ 字号 评论关闭

·  UseProperClassLoader: In J2EE getClassLoader() might not work as expected. Use Thread.currentThread().getContextClassLoader() instead.

翻译  使用合适的类加载器:在J2EEgetClassLoader()方法可能不会按照期望工作。使用Thread.currentThread().getContextClassLoader()来代替。

·  MDBAndSessionBeanNamingConvention: The EJB Specification state that any MessageDrivenBean or SessionBean should be suffixed by Bean.

翻译  消息驱动bean和会话bean命名规则:EJB规范表示任何消息驱动bean和会话bean的命名应该以’Bean’结尾。

代码示例:

/* Proper name */

            public class SomeBean implements SessionBean{}

 

/* Bad name */

            public class MissingTheProperSuffix implements SessionBean {}

·  RemoteSessionInterfaceNamingConvention: Remote Home interface of a Session EJB should be suffixed by 'Home'.

翻译  远程会话接口命名规则:会话EJBremote home接口命名应该以‘Home’结尾。

代码示例:

/* Proper name */

            public interface MyBeautifulHome extends javax.ejb.EJBHome {}

 

/* Bad name */

            public interface MissingProperSuffix extends javax.ejb.EJBHome {}

·  LocalInterfaceSessionNamingConvention: The Local Interface of a Session EJB should be suffixed by 'Local'.

翻译  本地接口会话命名规则:会话EJB的本地接口应该以‘Local’结尾。

代码示例:

/* Proper name */

            public interface MyLocal extends javax.ejb.EJBLocalObject {}

 

/* Bad name */

            public interface MissingProperSuffix extends javax.ejb.EJBLocalObject {}

·  LocalHomeNamingConvention: The Local Home interface of a Session EJB should be suffixed by 'LocalHome'.

翻译  本地Home命名规则:会话EJB的本地home接口应该以’LocalHome’结尾

代码示例:

/* Proper name */

            public interface MyBeautifulLocalHome extends javax.ejb.EJBLocalHome {}

 

/* Bad name */

            public interface MissingProperSuffix extends javax.ejb.EJBLocalHome {}

·  RemoteInterfaceNamingConvention: Remote Interface of a Session EJB should NOT be suffixed.

翻译  远程接口命名规则:会话EJB的远程接口应该没有后缀。

代码示例:

/* Bad Session suffix */

            public interface BadSuffixSession extends javax.ejb.EJBObject {}

 

/* Bad EJB suffix */

            public interface BadSuffixEJB extends javax.ejb.EJBObject {}

 

/* Bad Bean suffix */

            public interface BadSuffixBean extends javax.ejb.EJBObject {}

·  DoNotCallSystemExit: Web applications should not call System.exit(), since only the web container or the application server should stop the JVM.

翻译  不要调用System.exit:web应用不该调用System.exit(),因为只有web容器或应用服务器才能停止JVM.

·  StaticEJBFieldShouldBeFinal: According to the J2EE specification (p.494), an EJB should not have any static fields with write access. However, static read only fields are allowed. This ensures proper behavior especially when instances are distributed by the container on several JREs.

翻译  静态EJB域应该是final的:根据J2EE规范(p.494),EJB不应该有任何具有写入访问权的静态域,然而,只读静态域是允许的。这样能够保证合适的行为,尤其当实例分布存在于多个JRE的容器中

·  DoNotUseThreads: The J2EE specification explicitly forbid use of threads.

翻译  不用使用线程:J2EE规范明确禁止使用线程。

备注:意思是已经由J2EE规范和成熟类库帮你封装了线程处理,自己尽量不要用线程。

抱歉!评论已关闭.