use of org.apache.openejb.BeanContext in project tomee by apache.
the class CdiPlugin method validateProduceMethods.
private static void validateProduceMethods(final CdiEjbBean<?> bean, final Set<ProducerMethodBean<?>> methods) {
final BeanContext beanContext = bean.getBeanContext();
if (beanContext.isLocalbean()) {
return;
}
for (final ProducerMethodBean<?> m : methods) {
final Method method = m.getCreatorMethod();
final Method viewMethod = doResolveViewMethod(bean, method);
if (viewMethod == null || beanContext.getBusinessRemoteInterfaces().contains(viewMethod.getDeclaringClass())) {
throw new WebBeansConfigurationException("@Produces " + method + " not in a local ejb view of ejb " + beanContext.getEjbName());
}
}
}
use of org.apache.openejb.BeanContext in project tomee by apache.
the class CdiPlugin method findBeanContext.
private static BeanContext findBeanContext(final WebBeansContext ctx, final Class<?> clazz) {
final Map<Class<?>, BeanContext> beans = pluginBeans(ctx);
final BeanContext b = beans.get(clazz);
if (b != null) {
return b;
}
for (final BeanContext bc : beans.values()) {
if (bc.isLocalbean()) {
// see isSessionBean() impl
continue;
}
final CdiEjbBean<?> cdiEjbBean = bc.get(CdiEjbBean.class);
if (cdiEjbBean == null) {
continue;
}
for (final Class<?> itf : cdiEjbBean.getBusinessLocalInterfaces()) {
if (itf.equals(clazz)) {
return bc;
}
}
}
final WebBeansContext parentCtx = superContext(ctx);
if (parentCtx != null) {
return findBeanContext(parentCtx, clazz);
}
return null;
}
use of org.apache.openejb.BeanContext in project tomee by apache.
the class CdiPlugin method doResolveViewMethod.
public static Method doResolveViewMethod(final Bean<?> component, final Method declaredMethod) {
if (!(component instanceof CdiEjbBean)) {
return declaredMethod;
}
final CdiEjbBean cdiEjbBean = (CdiEjbBean) component;
final BeanContext beanContext = cdiEjbBean.getBeanContext();
for (final Class intface : beanContext.getBusinessLocalInterfaces()) {
try {
return intface.getMethod(declaredMethod.getName(), declaredMethod.getParameterTypes());
} catch (final NoSuchMethodException ignore) {
// no-op
}
}
for (final Class intface : beanContext.getBusinessRemoteInterfaces()) {
try {
return intface.getMethod(declaredMethod.getName(), declaredMethod.getParameterTypes());
} catch (final NoSuchMethodException ignore) {
// no-op
}
}
return null;
}
use of org.apache.openejb.BeanContext in project tomee by apache.
the class CdiResourceInjectionService method setAppContext.
public void setAppContext(final AppContext appModule, final Collection<BeanContext> ejbs) {
compContexts.clear();
ear = false;
for (final BeanContext beanContext : appModule.getBeanContexts()) {
if (!ear) {
ear = beanContext.getEjbName().contains("ear-scoped-cdi-beans_");
}
if (beanContext.getBeanClass().equals(BeanContext.Comp.class) && (ejbs == null || ear || ejbs.contains(beanContext))) {
compContexts.add(beanContext);
}
}
this.appCtx = appModule;
}
use of org.apache.openejb.BeanContext in project tomee by apache.
the class CdiResourceInjectionService method getResourceReference.
@Override
public <X, T extends Annotation> X getResourceReference(final ResourceReference<X, T> resourceReference) {
final Class<X> type = resourceReference.getResourceType();
final String name = resourceReference.getJndiName();
try {
return type.cast(new InitialContext().lookup(name));
} catch (final NamingException e) {
// no-op: try next
}
final String noJavaPrefix = name.replace("java:", "");
for (final BeanContext beanContext : compContexts) {
try {
return type.cast(beanContext.getJndiContext().lookup(noJavaPrefix));
} catch (final NamingException e1) {
// fine for now
}
}
if (appCtx != null) {
// depending envrt bindings can be missing from InitialContext (embedded for instance)
for (final WebContext w : appCtx.getWebContexts()) {
final Object instance = w.getBindings().get(noJavaPrefix);
if (instance != null) {
if (Reference.class.isInstance(instance)) {
try {
return type.cast(Reference.class.cast(instance).getObject());
} catch (final NamingException e) {
// no-op: try next
}
}
if (type.isInstance(instance)) {
return type.cast(instance);
}
// else a javax.naming.Reference we don't handle yet surely
}
}
}
return null;
}
Aggregations