{
// Initialize
Set<Class<?>> localAndBusinessLocalInterfaces = new HashSet<Class<?>>();
// Obtain @Local
Local localAnnotation = beanClass.getAnnotation(Local.class);
// Obtain @LocalHome
LocalHome localHomeAnnotation = beanClass.getAnnotation(LocalHome.class);
// Obtain @Remote
Remote remoteAnnotation = beanClass.getAnnotation(Remote.class);
// Obtain Remote and Business Remote interfaces
//Class<?>[] remoteAndBusinessRemoteInterfaces = ProxyFactoryHelper.getRemoteAndBusinessRemoteInterfaces(container);
// Obtain all business interfaces from the bean class
Set<Class<?>> businessInterfacesImplementedByBeanClass = getBusinessInterfaces(beanClass);
// Obtain all business interfaces directly implemented by the bean class (not including supers)
Set<Class<?>> businessInterfacesDirectlyImplementedByBeanClass = getBusinessInterfaces(
beanClass, false);
// For each of the business interfaces implemented by the bean class
for (Class<?> clazz : businessInterfacesImplementedByBeanClass)
{
// If @Local is on the interface
if (clazz.isAnnotationPresent(Local.class))
{
// Add to the list of locals
localAndBusinessLocalInterfaces.add(clazz);
}
}
// EJBTHREE-1062
// EJB 3 Core Specification 4.6.6
// If bean class implements a single interface, that interface is assumed to be the
// business interface of the bean. This business interface will be a local interface unless the
// interface is designated as a remote business interface by use of the Remote
// annotation on the bean class or interface or by means of the deployment descriptor.
if (businessInterfacesDirectlyImplementedByBeanClass.size() == 1 && localAndBusinessLocalInterfaces.size() == 0)
{
// Obtain the implemented interface
Class<?> singleInterface = businessInterfacesDirectlyImplementedByBeanClass.iterator().next();
// If not explicitly marked as @Remote, and is a valid business interface
if (remoteAnnotation == null && singleInterface.getAnnotation(Remote.class) == null)
{
// Return the implemented interface, adding to the container
Class<?>[] returnValue = new Class[]
{singleInterface};
return returnValue;
}
}
// @Local was defined
if (localAnnotation != null)
{
// If @Local has no value or empty value
if (localAnnotation.value() == null || localAnnotation.value().length == 0)
{
// If @Local is defined with no value and there are no business interfaces
if (businessInterfacesImplementedByBeanClass.size() == 0)
{
return new Class<?>[]
{};
}
// If more than one business interface is directly implemented by the bean class
else if (businessInterfacesImplementedByBeanClass.size() > 1)
{
return new Class<?>[]
{};
}
// JIRA EJBTHREE-1062
// EJB 3 4.6.6
// If the bean class implements only one business interface, that
//interface is exposed as local business if not denoted as @Remote
else
{
// If not explicitly marked as @Remote
if (remoteAnnotation == null)
{
// Return the implemented interface and add to container
Class<?>[] returnValue = businessInterfacesImplementedByBeanClass.toArray(new Class<?>[]
{});
return returnValue;
}
}
}
// @Local has value
else
{
// For each of the interfaces in @Local.value
for (Class<?> clazz : localAnnotation.value())
{
// Add to the list of locals
localAndBusinessLocalInterfaces.add(clazz);
}