1 package com.puppycrawl.tools.checkstyle.checks.j2ee; 20 21 import org.apache.commons.beanutils.ConversionException; 22 23 import com.puppycrawl.tools.checkstyle.api.DetailAST; 24 25 36 public class EntityBeanCheck 37 extends AbstractBeanCheck 38 { 39 40 private PersistenceOption mPersistenceOption; 41 42 43 private String mVersion = "2.0"; 44 45 48 public EntityBeanCheck() 49 { 50 mPersistenceOption = PersistenceOption.MIXED; 51 setMethodChecker(new EntityBeanMethodChecker(this)); 52 } 53 54 59 public void setPersistence(String aOption) 60 throws ConversionException 61 { 62 mPersistenceOption = 63 (PersistenceOption) mPersistenceOption.decode(aOption); 64 if (mPersistenceOption == null) { 65 throw new ConversionException("unable to parse " + aOption); 66 } 67 else if (mPersistenceOption == PersistenceOption.BEAN) { 68 setMethodChecker(new BeanManagedMethodChecker(this)); 69 } 70 else if (mPersistenceOption == PersistenceOption.CONTAINER) { 71 setMethodChecker(new ContainerManagedMethodChecker(this)); 72 } 73 else { 74 setMethodChecker(new EntityBeanMethodChecker(this)); 75 } 76 } 77 78 82 public PersistenceOption getPersistenceOption() 83 { 84 return mPersistenceOption; 85 } 86 87 91 public void setVersion(String aVersion) 92 { 93 mVersion = aVersion; 94 } 95 96 100 public String getVersion() 101 { 102 return mVersion; 103 } 104 105 108 public void visitToken(DetailAST aAST) 109 { 110 if (Utils.hasImplements(aAST, "javax.ejb.EntityBean")) { 111 checkBean(aAST, "Entity bean", true); 112 checkAbstract(aAST); 113 getMethodChecker().checkMethods(aAST); 114 } 115 } 116 117 122 private void checkAbstract(DetailAST aAST) 123 { 124 if ((getPersistenceOption() == PersistenceOption.BEAN) 126 && Utils.isAbstract(aAST)) 127 { 128 logName(aAST, "abstract.bean", new Object [] {}); 129 } 130 if ((getPersistenceOption() == PersistenceOption.CONTAINER) 132 && !Utils.isAbstract(aAST)) 133 { 134 logName(aAST, "nonabstract.bean", new Object [] {}); 135 } 136 } 137 } 138 | Popular Tags |