* @return the remote interfaces of the container or an empty array
*/
public static Class<?>[] getRemoteAndBusinessRemoteInterfaces(Container container)
{
// Initialize
Remote remoteAnnotation = ((EJBContainer) container).getAnnotation(Remote.class);
RemoteHome remoteHomeAnnotation = ((EJBContainer) container).getAnnotation(RemoteHome.class);
Set<Class<?>> remoteAndRemoteBusinessInterfaces = new HashSet<Class<?>>();
Class<?> beanClass = container.getBeanClass();
boolean isStateless = (container instanceof StatelessContainer) ? true : false;
// Obtain business interfaces
Class<?>[] businessInterfaces = ProxyFactoryHelper.getBusinessInterfaces(beanClass).toArray(new Class[]
{});
// EJBTHREE-1127
// Determine remote interface from return value of "create" in Remote Home
if (remoteHomeAnnotation != null)
{
remoteAndRemoteBusinessInterfaces.addAll(ProxyFactoryHelper.getReturnTypesFromCreateMethods(
remoteHomeAnnotation.value(), isStateless));
}
// If @Remote is not defined
if (remoteAnnotation == null)
{
// For each of the business interfaces
for (Class<?> clazz : businessInterfaces)
{
// If @Remote is on the business interface
if (clazz.isAnnotationPresent(Remote.class))
{
// Add to the list of remotes
remoteAndRemoteBusinessInterfaces.add(clazz);
}
}
}
// @Remote was defined
else
{
// @Remote declares interfaces, add these
if (remoteAnnotation.value().length > 0)
{
for (Class<?> clazz : remoteAnnotation.value())
{
remoteAndRemoteBusinessInterfaces.add(clazz);
}
}
// @Remote is empty
else
{
// No business interfaces were defined on the bean
if (businessInterfaces.length == 0)
{
throw new RuntimeException("Use of empty @Remote on bean " + container.getEjbName()
+ " and there are no valid business interfaces");
}
// More than one default interface, cannot be marked as @Remote
else if (businessInterfaces.length > 1)
{
throw new RuntimeException("Use of empty @Remote on bean " + container.getEjbName()
+ " with more than one default interface " + businessInterfaces);
}
// Only one default interface, mark as @Remote and return
else
{
Class<?>[] rtn =
{(Class<?>) businessInterfaces[0]};
remoteAnnotation = new RemoteImpl(rtn);
((EJBContainer) container).getAnnotations().addClassAnnotation(javax.ejb.Remote.class, remoteAnnotation);
return rtn;
}
}
}
// If remotes were found
if (remoteAndRemoteBusinessInterfaces.size() > 0)
{
// Set interfaces and return
Class<?>[] remotesArray = remoteAndRemoteBusinessInterfaces
.toArray(new Class[remoteAndRemoteBusinessInterfaces.size()]);
remoteAnnotation = new RemoteImpl(remotesArray);
((EJBContainer) container).getAnnotations().addClassAnnotation(Remote.class, remoteAnnotation);
return remoteAnnotation.value();
}
// No remotes were found
else
{
return new Class<?>[]