public Collection execute(Method finderMethod,
Object[] args,
EntityEnterpriseContext ctx) throws Exception {
// invoke implementation method on ejb instance
try {
// if expected return type is Collection, return as is
// if expected return type is not Collection, wrap result in Collection
if (finderMethod.getReturnType().equals(Collection.class)) {
return (Collection)finderImplMethod.invoke(ctx.getInstance(),args);
} else {
Collection coll = new ArrayList(1);
coll.add(finderImplMethod.invoke(ctx.getInstance(),args));
return coll;
}
} catch (IllegalAccessException e1) {
throw new FinderException("Unable to access finder implementation:"+finderImplMethod.getName());
} catch (IllegalArgumentException e2) {
throw new FinderException("Illegal arguments for finder implementation:"+finderImplMethod.getName());
} catch (ExceptionInInitializerError e5) {
throw new FinderException("Unable to initialize finder implementation:"+finderImplMethod.getName());
} catch (InvocationTargetException e) {
Throwable target = e.getTargetException();
if(target instanceof Exception) {
throw (Exception)target;
}
throw new FinderException("Unable to initialize finder implementation: " + finderImplMethod.getName());
}
}
|