private String formatDeploymentId(EnterpriseBean bean, Map<String, String> contextData, StringTemplate template) { contextData.put("ejbType", bean.getClass().getSimpleName()); contextData.put("ejbClass", bean.getEjbClass()); // we don't have the ejb class object (only the string name) so we have // to extract the simple name from the FQN of the class int simpleNameIdx = bean.getEjbClass().lastIndexOf("."); contextData.put("ejbClass.simpleName", bean.getEjbClass().substring(simpleNameIdx + 1)); contextData.put("ejbName", bean.getEjbName()); return template.apply(contextData); } }
private org.apache.openejb.api.EjbDeployment getEjbDeploymentAnnotation(final EjbModule ejbModule, final EnterpriseBean bean) { try { final Class<?> beanClass = ejbModule.getClassLoader().loadClass(bean.getEjbClass()); return beanClass.getAnnotation(org.apache.openejb.api.EjbDeployment.class); } catch (final ClassNotFoundException e) { // this should never happen, the class has already been loaded a ton of times by this point // unfortunately we have some unit tests that prevent us from throwing an exception just in case // Those are OpenEjb2ConversionTest and SunCmpConversionTest return null; } }
private org.apache.openejb.api.EjbDeployment getEjbDeploymentAnnotation(EjbModule ejbModule, EnterpriseBean bean) { try { Class<?> beanClass = ejbModule.getClassLoader().loadClass(bean.getEjbClass()); return beanClass.getAnnotation(org.apache.openejb.api.EjbDeployment.class); } catch (ClassNotFoundException e) { // this should never happen, the class has already been loaded a ton of times by this point // unfortunately we have some unit tests that prevent us from throwing an exception just in case // Those are OpenEjb2ConversionTest and SunCmpConversionTest return null; } }
private String formatDeploymentId(final EnterpriseBean bean, final Map<String, String> contextData, final StringTemplate template) { contextData.put("ejbType", bean.getClass().getSimpleName()); contextData.put("ejbClass", bean.getEjbClass()); // we don't have the ejb class object (only the string name) so we have // to extract the simple name from the FQN of the class final int simpleNameIdx = bean.getEjbClass().lastIndexOf("."); contextData.put("ejbClass.simpleName", bean.getEjbClass().substring(simpleNameIdx + 1)); contextData.put("ejbName", bean.getEjbName()); final String name = template.apply(contextData); if (bean instanceof CompManagedBean) { // avoid conflict in ear between an ejbmodule and a war using the same name return name + System.identityHashCode(bean); } return name; } }
private org.apache.openejb.api.EjbDeployment getEjbDeploymentAnnotation(final EjbModule ejbModule, final EnterpriseBean bean) { try { final Class<?> beanClass = ejbModule.getClassLoader().loadClass(bean.getEjbClass()); return beanClass.getAnnotation(org.apache.openejb.api.EjbDeployment.class); } catch (final ClassNotFoundException e) { // this should never happen, the class has already been loaded a ton of times by this point // unfortunately we have some unit tests that prevent us from throwing an exception just in case // Those are OpenEjb2ConversionTest and SunCmpConversionTest return null; } }
public InterceptorBinding(final EnterpriseBean bean, final Interceptor... interceptors) { this(bean.getEjbName(), interceptors); this.className = bean.getEjbClass(); }
public InterceptorBinding(final EnterpriseBean bean, final Interceptor... interceptors) { this(bean.getEjbName(), interceptors); this.className = bean.getEjbClass(); }
private String formatDeploymentId(final EnterpriseBean bean, final Map<String, String> contextData, final StringTemplate template) { contextData.put("ejbType", bean.getClass().getSimpleName()); contextData.put("ejbClass", bean.getEjbClass()); // we don't have the ejb class object (only the string name) so we have // to extract the simple name from the FQN of the class final int simpleNameIdx = bean.getEjbClass().lastIndexOf("."); contextData.put("ejbClass.simpleName", bean.getEjbClass().substring(simpleNameIdx + 1)); contextData.put("ejbName", bean.getEjbName()); final String name = template.apply(contextData); if (bean instanceof CompManagedBean) { // avoid conflict in ear between an ejbmodule and a war using the same name return name + System.identityHashCode(bean); } return name; } }
public Class<?> check_hasEjbClass(EnterpriseBean b) { String ejbName = b.getEjbName(); Class<?> beanClass = lookForClass(b.getEjbClass(), "<ejb-class>", ejbName); if (beanClass.isInterface()){ fail(ejbName, "interfaceDeclaredAsBean", beanClass.getName()); } if (isCmp(b)) return beanClass; if (isAbstract(beanClass.getModifiers())){ fail(ejbName, "abstractDeclaredAsBean", beanClass.getName()); } return beanClass; }
private boolean isLocalBean(Class clazz) { DeploymentModule module = getModule(); if (module instanceof EjbModule) { Set<String> localbeans = new HashSet<String>(); EjbModule ejbModule = (EjbModule) module; for (EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) { if (bean instanceof SessionBean) { if (((SessionBean) bean).getLocalBean() != null) { localbeans.add(bean.getEjbClass()); } } } if (localbeans.contains(clazz.getName())) { return true; } } return false; }
@Override public AppModule deploy(final AppModule appModule) throws OpenEJBException { for (final EjbModule ejbModule : appModule.getEjbModules()) { final ClassLoader classLoader = ejbModule.getClassLoader(); for (final EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) { if (bean.getEjbClass() == null) { continue; } try { final Class<?> clazz = classLoader.loadClass(bean.getEjbClass()); process(clazz, bean); } catch (final ClassNotFoundException e) { // skip, we'll get this in validation } } } return appModule; }
@Override public AppModule deploy(final AppModule appModule) throws OpenEJBException { for (final EjbModule ejbModule : appModule.getEjbModules()) { final ClassLoader classLoader = ejbModule.getClassLoader(); for (final EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) { if (bean.getEjbClass() == null) { continue; } try { final Class<?> clazz = classLoader.loadClass(bean.getEjbClass()); process(clazz, bean); } catch (final ClassNotFoundException e) { // skip, we'll get this in validation } } } return appModule; }
public Class<?> check_hasEjbClass(final ClassLoader loader, final EnterpriseBean b) { final String ejbName = b.getEjbName(); final Class<?> beanClass = lookForClass(loader, b.getEjbClass(), "ejb-class", ejbName); final boolean isDynamicProxyImpl = DynamicProxyImplFactory.isKnownDynamicallyImplemented(beanClass); if (beanClass == null) { return null; } if (beanClass.isInterface() && !isDynamicProxyImpl) { fail(ejbName, "interfaceDeclaredAsBean", beanClass.getName()); } if (isCmp(b)) { return beanClass; } if (isAbstract(beanClass.getModifiers()) && !isAbstractAllowed(beanClass)) { fail(ejbName, "abstractDeclaredAsBean", beanClass.getName()); } return beanClass; }
private boolean isValidEjbInterface(String b, Class clazz, String refName) { if (!clazz.isInterface()) { DeploymentModule module = getModule(); if (module instanceof EjbModule) { Set<String> beanClasses = new HashSet<String>(); EjbModule ejbModule = (EjbModule) module; for (EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) { beanClasses.add(bean.getEjbClass()); } if (beanClasses.contains(clazz.getName())) { fail(b, "ann.ejb.beanClass", clazz.getName(), refName); } else { fail(b, "ann.ejb.notInterface", clazz.getName(), refName); } } else { fail(b, "ann.ejb.notInterface", clazz.getName(), refName); } return false; } else if (EJBObject.class.isAssignableFrom(clazz)) { fail(b, "ann.ejb.ejbObject", clazz.getName(), refName); return false; } else if (EJBLocalObject.class.isAssignableFrom(clazz)) { fail(b, "ann.ejb.ejbLocalObject", clazz.getName(), refName); return false; } return true; }
public Class<?> check_hasEjbClass(final EnterpriseBean b) { final String ejbName = b.getEjbName(); final Class<?> beanClass = lookForClass(b.getEjbClass(), "ejb-class", ejbName); final boolean isDynamicProxyImpl = DynamicProxyImplFactory.isKnownDynamicallyImplemented(beanClass); if (beanClass == null) { return null; } if (beanClass.isInterface() && !isDynamicProxyImpl) { fail(ejbName, "interfaceDeclaredAsBean", beanClass.getName()); } if (isCmp(b)) { return beanClass; } if (isAbstract(beanClass.getModifiers()) && !isAbstractAllowed(beanClass)) { fail(ejbName, "abstractDeclaredAsBean", beanClass.getName()); } return beanClass; }
public void validate(EjbModule ejbModule) { for (EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) { String beanType = getType(bean); if (beanType.equals("Stateful")) continue; // skip statefuls for (PersistenceContextRef ref : bean.getPersistenceContextRef()) { if (isExtented(ref)) { String refName = ref.getName(); String prefix = bean.getEjbClass() + "/"; if (refName.startsWith(prefix)) { refName = refName.substring(prefix.length()); } fail(bean, "persistenceContextExtented.nonStateful", refName, beanType); } } } }
public void addEjbTimeout(EnterpriseBean remoteBean, EjbModule ejbModule, Collection<Permission> permissions) throws DeploymentException { NamedMethod timeout = null; if (remoteBean instanceof SessionBean) { timeout = ((SessionBean) remoteBean).getTimeoutMethod(); } else if (remoteBean instanceof MessageDrivenBean) { timeout = ((MessageDrivenBean) remoteBean).getTimeoutMethod(); } if (timeout != null) { permissions.add(new EJBMethodPermission(remoteBean.getEjbName(), timeout.getMethodName(), null, new String[]{Timer.class.getName()})); } else { try { Class ejbClass = ejbModule.getClassLoader().loadClass(remoteBean.getEjbClass()); if (TimedObject.class.isAssignableFrom(ejbClass)) { permissions.add(new EJBMethodPermission(remoteBean.getEjbName(), "ejbTimeout", null, new String[]{Timer.class.getName()})); } } catch (ClassNotFoundException e) { throw new DeploymentException("Could not figure out timer method", e); } } }
public void validate(final EjbModule ejbModule) { for (final EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) { if (bean instanceof SessionBean) { final SessionBean sessionBean = (SessionBean) bean; if (sessionBean.getSessionType() == null) { continue; // skipping since we don't know here what is the type } } final String beanType = getType(bean); if (beanType.equals("Stateful")) { continue; // skip statefuls and Comp ManagedBean } for (final PersistenceContextRef ref : bean.getPersistenceContextRef()) { if (isExtented(ref)) { String refName = ref.getName(); final String prefix = bean.getEjbClass() + "/"; if (refName.startsWith(prefix)) { refName = refName.substring(prefix.length()); } fail(bean, "persistenceContextExtented.nonStateful", refName, beanType); } } } }
public void validate(final EjbModule ejbModule) { for (final EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) { if (bean instanceof SessionBean) { final SessionBean sessionBean = (SessionBean) bean; if (sessionBean.getSessionType() == null) { continue; // skipping since we don't know here what is the type } } final String beanType = getType(bean); if (beanType.equals("Stateful")) { continue; // skip statefuls and Comp ManagedBean } for (final PersistenceContextRef ref : bean.getPersistenceContextRef()) { if (isExtented(ref)) { String refName = ref.getName(); final String prefix = bean.getEjbClass() + "/"; if (refName.startsWith(prefix)) { refName = refName.substring(prefix.length()); } fail(bean, "persistenceContextExtented.nonStateful", refName, beanType); } } } }
public AppModule deploy(final AppModule appModule) throws OpenEJBException { for (final ClientModule module : appModule.getClientModules()) { final JndiConsumer consumer = module.getApplicationClient(); if (consumer == null) { continue; } add(consumer, module, appModule, false); } for (final WebModule module : appModule.getWebModules()) { final JndiConsumer consumer = module.getWebApp(); if (consumer == null) { continue; } add(consumer, module, appModule, addDefaults); } for (final EjbModule module : appModule.getEjbModules()) { final EjbJar ejbJar = module.getEjbJar(); if (ejbJar == null) { continue; } for (final EnterpriseBean consumer : ejbJar.getEnterpriseBeans()) { add(consumer, module, appModule, addDefaults && BeanContext.Comp.class.getName().equals(consumer.getEjbClass())); } } return appModule; }