1 22 package org.jboss.verifier; 23 24 45 46 47 import java.util.Iterator ; 49 import java.net.URL ; 50 51 import org.jboss.verifier.strategy.EJBVerifier21; 53 import org.jboss.verifier.strategy.VerificationContext; 54 import org.jboss.verifier.strategy.VerificationStrategy; 55 import org.jboss.verifier.strategy.EJBVerifier11; 56 import org.jboss.verifier.strategy.EJBVerifier20; 57 58 import org.jboss.verifier.event.VerificationEvent; 59 import org.jboss.verifier.event.VerificationListener; 60 import org.jboss.verifier.event.VerificationEventGeneratorSupport; 61 62 import org.jboss.metadata.ApplicationMetaData; 63 import org.jboss.metadata.BeanMetaData; 64 import org.jboss.metadata.EntityMetaData; 65 import org.jboss.metadata.SessionMetaData; 66 import org.jboss.metadata.MessageDrivenMetaData; 67 68 import org.jboss.logging.Logger; 69 70 82 public class BeanVerifier 83 implements VerificationContext 84 { 85 private ApplicationMetaData ejbMetaData = null; 86 private URL ejbURL = null; 87 private ClassLoader ejbClassLoader = null; 88 89 private VerificationStrategy verifier = null; 90 91 private boolean success = true; 92 93 private static Logger log = Logger.getLogger( BeanVerifier.class ); 94 95 98 private VerificationEventGeneratorSupport events = 99 new VerificationEventGeneratorSupport(); 100 101 104 public BeanVerifier() 105 {} 106 107 115 public void verify(URL url, ApplicationMetaData metaData) 116 { 117 verify(url, metaData, null); 118 } 119 120 129 public void verify(URL url, ApplicationMetaData metaData, ClassLoader cl) 130 { 131 ejbURL = url; 132 ejbMetaData = metaData; 133 ejbClassLoader = cl; 134 135 if(metaData.isEJB1x()) 136 { 137 setVerifier(VERSION_1_1); 138 } 139 else if(metaData.isEJB21()) 140 { 141 setVerifier(VERSION_2_1); 142 } 143 else 144 { 145 setVerifier(VERSION_2_0); 146 } 147 148 Iterator beans = ejbMetaData.getEnterpriseBeans(); 149 150 while (beans.hasNext()) 151 { 152 BeanMetaData bean = (BeanMetaData)beans.next(); 153 154 if( bean.isEntity() ) 155 { 156 EntityMetaData entityBean = (EntityMetaData)bean; 157 if( metaData.isEJB2x() && entityBean.isCMP1x() ) 158 { 159 boolean storedSuccess = success; 163 164 verifier.checkEntity( entityBean ); 165 166 if( success != storedSuccess ) 167 { 168 log.warn( "The CMP 1.x EJB '" + entityBean.getEjbName() + 169 "' generated some verification warnings. The Deployer " + 170 "will ignore these warnings but you should check " + 171 "your EJB to be on the safe side of things." ); 172 } 173 174 success = storedSuccess; 175 } 176 else 177 { 178 verifier.checkEntity( entityBean ); 179 } 180 } 181 else if( bean.isSession() ) 182 { 183 verifier.checkSession( (SessionMetaData)bean ); 184 } 185 else 186 { 187 verifier.checkMessageBean( (MessageDrivenMetaData)bean ); 188 } 189 } 190 } 191 192 198 public boolean getSuccess() 199 { 200 return success; 201 } 202 203 210 public void addVerificationListener(VerificationListener listener) 211 { 212 events.addVerificationListener(listener); 213 } 214 215 public void removeVerificationListener(VerificationListener listener) 216 { 217 events.removeVerificationListener(listener); 218 } 219 220 public void fireBeanChecked(VerificationEvent event) 221 { 222 events.fireBeanChecked(event); 223 } 224 225 public void fireSpecViolation( VerificationEvent event ) 226 { 227 success = false; 229 events.fireSpecViolation(event); 230 } 231 232 239 public ApplicationMetaData getApplicationMetaData() 240 { 241 return ejbMetaData; 242 } 243 244 public URL getJarLocation() 245 { 246 return ejbURL; 247 } 248 249 public ClassLoader getClassLoader() 250 { 251 return ejbClassLoader; 252 } 253 254 public String getEJBVersion() 255 { 256 return VERSION_1_1; 257 258 } 260 261 266 protected void setVerifier( String version ) 267 { 268 if( VERSION_1_1.equals(version) ) 269 { 270 verifier = new EJBVerifier11(this); 271 } 272 else if( VERSION_2_0.equals(version) ) 273 { 274 verifier = new EJBVerifier20(this); 275 } 276 else if (VERSION_2_1.equals(version)) 277 { 278 verifier=new EJBVerifier21(this); 279 } 280 else 281 { 282 throw new IllegalArgumentException ( UNRECOGNIZED_VERSION + 283 ": " + version); 284 } 285 } 286 287 290 protected VerificationStrategy getVerifier() 291 { 292 return verifier; 293 } 294 295 298 private final static String UNRECOGNIZED_VERSION = 299 "Unknown version string"; 300 } 301 304 | Popular Tags |