use of org.apache.openejb.InterfaceType in project tomee by apache.
the class EjbHomeProxyHandler method createProxy.
public Object createProxy(final Object primaryKey, final Class mainInterface) {
try {
final InterfaceType objectInterfaceType = this.interfaceType.getCounterpart();
final BeanType type = getBeanContext().getComponentType();
final EjbObjectProxyHandler handler = newEjbObjectHandler(getBeanContext(), primaryKey, objectInterfaceType, getInterfaces(), mainInterface);
// TODO Is it correct for ManagedBean injection via managed bean class?
if ((InterfaceType.LOCALBEAN.equals(objectInterfaceType) || getBeanContext().getComponentType().equals(BeanType.MANAGED)) && !getBeanContext().isDynamicallyImplemented()) {
return LocalBeanProxyFactory.constructProxy(handler.getBeanContext().get(BeanContext.ProxyClass.class).getProxy(), handler);
} else {
final List<Class> proxyInterfaces = new ArrayList<Class>(handler.getInterfaces().size() + 2);
proxyInterfaces.addAll(handler.getInterfaces());
proxyInterfaces.add(Serializable.class);
proxyInterfaces.add(IntraVmProxy.class);
if (BeanType.STATEFUL.equals(type) || BeanType.MANAGED.equals(type)) {
proxyInterfaces.add(BeanContext.Removable.class);
}
return ProxyManager.newProxyInstance(proxyInterfaces.toArray(new Class[proxyInterfaces.size()]), handler);
}
} catch (final IllegalAccessException iae) {
throw new OpenEJBRuntimeException("Could not create IVM proxy for " + getInterfaces().get(0), iae);
}
}
use of org.apache.openejb.InterfaceType in project tomee by apache.
the class BaseSessionContext method getInvokedBusinessInterface.
public Class getInvokedBusinessInterface() {
doCheck(Call.getInvokedBusinessInterface);
final ThreadContext threadContext = ThreadContext.getThreadContext();
final Class invokedInterface = threadContext.getInvokedInterface();
final InterfaceType type = threadContext.getBeanContext().getInterfaceType(invokedInterface);
if (!type.isBusiness()) {
throw new IllegalStateException("The EJB spec requires us to cripple the use of this method for anything but business interface proxy. But FYI, your invoked interface is: " + invokedInterface.getName());
}
if (invokedInterface == null) {
throw new IllegalStateException("Business interface not set into ThreadContext.");
}
return invokedInterface;
}
use of org.apache.openejb.InterfaceType in project tomee by apache.
the class CdiPlugin method getSessionBeanProxy.
@Override
public Object getSessionBeanProxy(final Bean<?> inBean, final Class<?> interfce, final CreationalContext<?> creationalContext) {
Object instance = cacheProxies.get(inBean);
if (instance != null) {
return instance;
}
synchronized (inBean) {
// singleton for the app so safe to sync on it
instance = cacheProxies.get(inBean);
if (instance != null) {
return instance;
}
final Class<? extends Annotation> scopeClass = inBean.getScope();
final CdiEjbBean<Object> cdiEjbBean = (CdiEjbBean<Object>) inBean;
final CreationalContext<Object> cc = (CreationalContext<Object>) creationalContext;
if (scopeClass == null || Dependent.class == scopeClass) {
// no need to add any layer, null = @New
return cdiEjbBean.createEjb(cc);
}
// only stateful normally
final InstanceBean<Object> bean = new InstanceBean<Object>(cdiEjbBean);
if (webBeansContext.getBeanManagerImpl().isNormalScope(scopeClass)) {
final BeanContext beanContext = cdiEjbBean.getBeanContext();
final Provider provider = webBeansContext.getNormalScopeProxyFactory().getInstanceProvider(beanContext.getClassLoader(), cdiEjbBean);
if (!beanContext.isLocalbean()) {
final List<Class> interfaces = new ArrayList<Class>();
final InterfaceType type = beanContext.getInterfaceType(interfce);
if (type != null) {
interfaces.addAll(beanContext.getInterfaces(type));
} else {
// can happen when looked up from impl instead of API in OWB -> default to business local
interfaces.addAll(beanContext.getInterfaces(InterfaceType.BUSINESS_LOCAL));
}
interfaces.add(Serializable.class);
interfaces.add(IntraVmProxy.class);
if (BeanType.STATEFUL.equals(beanContext.getComponentType()) || BeanType.MANAGED.equals(beanContext.getComponentType())) {
interfaces.add(BeanContext.Removable.class);
}
try {
instance = ProxyManager.newProxyInstance(interfaces.toArray(new Class<?>[interfaces.size()]), new InvocationHandler() {
@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
try {
return method.invoke(provider.get(), args);
} catch (final InvocationTargetException ite) {
throw ite.getCause();
}
}
});
} catch (final IllegalAccessException e) {
throw new OpenEJBRuntimeException(e);
}
} else {
final NormalScopeProxyFactory normalScopeProxyFactory = webBeansContext.getNormalScopeProxyFactory();
final Class<?> proxyClass = normalScopeProxyFactory.createProxyClass(beanContext.getClassLoader(), beanContext.getBeanClass());
instance = normalScopeProxyFactory.createProxyInstance(proxyClass, provider);
}
cacheProxies.put(inBean, instance);
} else {
final Context context = webBeansContext.getBeanManagerImpl().getContext(scopeClass);
instance = context.get(bean, cc);
}
bean.setOwbProxy(instance);
return instance;
}
}
use of org.apache.openejb.InterfaceType in project tomee by apache.
the class LazyEjbReference method getObject.
public Object getObject() throws NamingException {
if (reference != null) {
return reference.getObject();
}
final SystemInstance systemInstance = SystemInstance.get();
final EjbResolver resolver = systemInstance.getComponent(EjbResolver.class);
final String deploymentId = resolver.resolve(info, moduleUri);
if (deploymentId == null) {
String key = "lazyEjbRefNotResolved";
if (info.getHome() != null) {
key += ".home";
}
final String message = messages.format(key, info.getName(), info.getEjbLink(), info.getHome(), info.getInterface());
throw new NameNotFoundException(message);
}
final ContainerSystem containerSystem = systemInstance.getComponent(ContainerSystem.class);
final BeanContext beanContext = containerSystem.getBeanContext(deploymentId);
if (beanContext == null) {
final String message = messages.format("deploymentNotFound", info.getName(), deploymentId);
throw new NameNotFoundException(message);
}
InterfaceType type = null;
switch(info.getRefType()) {
case LOCAL:
type = InterfaceType.BUSINESS_LOCAL;
break;
case REMOTE:
type = InterfaceType.BUSINESS_REMOTE;
break;
}
final String jndiName = "openejb/Deployment/" + JndiBuilder.format(deploymentId, info.getInterface(), type);
if (useCrossClassLoaderRef && isRemote(beanContext)) {
reference = new CrossClassLoaderJndiReference(jndiName);
} else {
reference = new IntraVmJndiReference(jndiName);
}
return reference.getObject();
}
use of org.apache.openejb.InterfaceType in project tomee by apache.
the class EjbFactory method buildJndiName.
protected String buildJndiName(final Reference reference) throws NamingException {
// get and verify deploymentId
final String jndiName;
final String deploymentId = NamingUtil.getProperty(reference, NamingUtil.DEPLOYMENT_ID);
if (deploymentId == null) {
throw new NamingException("ejb-ref deploymentId is null");
}
// get and verify interface type
InterfaceType type = InterfaceType.BUSINESS_REMOTE;
String interfaceType = NamingUtil.getProperty(reference, NamingUtil.REMOTE);
if (interfaceType == null) {
type = InterfaceType.LOCALBEAN;
interfaceType = NamingUtil.getProperty(reference, NamingUtil.LOCALBEAN);
}
if (interfaceType == null) {
type = InterfaceType.BUSINESS_LOCAL;
interfaceType = NamingUtil.getProperty(reference, NamingUtil.LOCAL);
}
if (interfaceType == null) {
throw new NamingException("ejb-ref interface type is null");
}
// build jndi name using the deploymentId and interface type
jndiName = "java:openejb/Deployment/" + JndiBuilder.format(deploymentId, interfaceType, type);
return jndiName;
}
Aggregations