ScheduleBucket scheduleBucket,
ExprEvaluatorContext exprEvaluatorContext)
throws ExprValidationException
{
// Try to resolve the method
FastMethod staticMethod;
Class declaringClass;
try
{
Method method = methodResolutionService.resolveMethod(methodStreamSpec.getClassName(), methodStreamSpec.getMethodName());
declaringClass = method.getDeclaringClass();
FastClass declaringFastClass = FastClass.create(Thread.currentThread().getContextClassLoader(), method.getDeclaringClass());
staticMethod = declaringFastClass.getMethod(method);
}
catch(Exception e)
{
throw new ExprValidationException(e.getMessage());
}
// Determine object type returned by method
Class beanClass = staticMethod.getReturnType();
if ((beanClass == void.class) || (beanClass == Void.class) || (JavaClassHelper.isJavaBuiltinDataType(beanClass)))
{
throw new ExprValidationException("Invalid return type for static method '" + staticMethod.getName() + "' of class '" + methodStreamSpec.getClassName() + "', expecting a Java class");
}
if (staticMethod.getReturnType().isArray())
{
beanClass = staticMethod.getReturnType().getComponentType();
}
// If the method returns a Map, look up the map type
Map<String, Object> mapType = null;
String mapTypeName = null;
if ( (JavaClassHelper.isImplementsInterface(staticMethod.getReturnType(), Map.class)) ||
(staticMethod.getReturnType().isArray() && JavaClassHelper.isImplementsInterface(staticMethod.getReturnType().getComponentType(), Map.class)) )
{
MethodMetadataDesc metadata = getCheckMetadata(methodStreamSpec.getMethodName(), methodStreamSpec.getClassName(), methodResolutionService, Map.class);
mapTypeName = metadata.getTypeName();
mapType = (Map<String, Object>) metadata.getTypeMetadata();
}
// If the method returns an Object[] or Object[][], look up the type information
LinkedHashMap<String, Object> oaType = null;
String oaTypeName = null;
if (staticMethod.getReturnType() == Object[].class || staticMethod.getReturnType() == Object[][].class)
{
MethodMetadataDesc metadata = getCheckMetadata(methodStreamSpec.getMethodName(), methodStreamSpec.getClassName(), methodResolutionService, LinkedHashMap.class);
oaTypeName = metadata.getTypeName();
oaType = (LinkedHashMap<String, Object>) metadata.getTypeMetadata();
}
// Determine event type from class and method name
EventType eventType;
if (mapType != null) {
eventType = eventAdapterService.addNestableMapType(mapTypeName, mapType, null, false, true, true, false, false);
}
else if (oaType != null) {
eventType = eventAdapterService.addNestableObjectArrayType(oaTypeName, oaType, null, false, true, true, false, false);
}
else {
eventType = eventAdapterService.addBeanType(beanClass.getName(), beanClass, false, true, true);
}
// Construct polling strategy as a method invocation
ConfigurationMethodRef configCache = engineImportService.getConfigurationMethodRef(declaringClass.getName());
if (configCache == null)
{
configCache = engineImportService.getConfigurationMethodRef(declaringClass.getSimpleName());
}
ConfigurationDataCache dataCacheDesc = (configCache != null) ? configCache.getDataCacheDesc() : null;
DataCache dataCache = DataCacheFactory.getDataCache(dataCacheDesc, epStatementAgentInstanceHandle, schedulingService, scheduleBucket);
PollExecStrategy methodPollStrategy;
if (mapType != null) {
if (staticMethod.getReturnType().isArray()) {
methodPollStrategy = new MethodPollingExecStrategyMapArray(eventAdapterService, staticMethod, eventType);
}
else {
methodPollStrategy = new MethodPollingExecStrategyMapPlain(eventAdapterService, staticMethod, eventType);
}
}
else if (oaType != null) {
if (staticMethod.getReturnType() == Object[][].class) {
methodPollStrategy = new MethodPollingExecStrategyOAArray(eventAdapterService, staticMethod, eventType);
}
else {
methodPollStrategy = new MethodPollingExecStrategyOAPlain(eventAdapterService, staticMethod, eventType);
}
}
else {
if (staticMethod.getReturnType().isArray()) {
methodPollStrategy = new MethodPollingExecStrategyPOJOArray(eventAdapterService, staticMethod, eventType);
}
else {
methodPollStrategy = new MethodPollingExecStrategyPOJOPlain(eventAdapterService, staticMethod, eventType);
}