}
private static SelectExprProcessor initializeCtorInjection(EventType eventType, ExprEvaluator[] exprEvaluators, StreamTypeService typeService, Object[] expressionReturnTypes, EngineImportService engineImportService, EventAdapterService eventAdapterService)
throws ExprValidationException {
BeanEventType beanEventType = (BeanEventType) eventType;
Class[] ctorTypes = new Class[expressionReturnTypes.length];
ExprEvaluator[] evaluators = new ExprEvaluator[exprEvaluators.length];
for (int i = 0; i < expressionReturnTypes.length; i++) {
Object columnType = expressionReturnTypes[i];
if (columnType instanceof Class || columnType == null) {
ctorTypes[i] = (Class) expressionReturnTypes[i];
evaluators[i] = exprEvaluators[i];
continue;
}
if (columnType instanceof EventType) {
EventType columnEventType = (EventType) columnType;
final Class returnType = columnEventType.getUnderlyingType();
int streamNum = 0;
for (int j = 0; j < typeService.getEventTypes().length; j++)
{
if (typeService.getEventTypes()[j] == columnEventType)
{
streamNum = j;
break;
}
}
final int streamNumEval = streamNum;
evaluators[i] = new ExprEvaluator() {
public Object evaluate(EventBean[] eventsPerStream, boolean isNewData, ExprEvaluatorContext exprEvaluatorContext)
{
EventBean theEvent = eventsPerStream[streamNumEval];
if (theEvent != null)
{
return theEvent.getUnderlying();
}
return null;
}
public Class getType()
{
return returnType;
}
public Map<String, Object> getEventType() {
return null;
}
};
continue;
}
// handle case where the select-clause contains an fragment array
if (columnType instanceof EventType[])
{
EventType columnEventType = ((EventType[]) columnType)[0];
final Class componentReturnType = columnEventType.getUnderlyingType();
final ExprEvaluator inner = exprEvaluators[i];
evaluators[i] = new ExprEvaluator() {
public Object evaluate(EventBean[] eventsPerStream, boolean isNewData, ExprEvaluatorContext exprEvaluatorContext)
{
Object result = inner.evaluate(eventsPerStream, isNewData, exprEvaluatorContext);
if (!(result instanceof EventBean[])) {
return null;
}
EventBean[] events = (EventBean[]) result;
Object values = Array.newInstance(componentReturnType, events.length);
for (int i = 0; i < events.length; i++) {
Array.set(values, i, events[i].getUnderlying());
}
return values;
}
public Class getType()
{
return componentReturnType;
}
public Map<String, Object> getEventType() {
return null;
}
};
continue;
}
String message = "Invalid assignment of expression " + i + " returning type '" + columnType +
"', column and parameter types mismatch";
throw new ExprValidationException(message);
}
FastConstructor fctor;
try {
Constructor ctor = engineImportService.resolveCtor(beanEventType.getUnderlyingType(), ctorTypes);
FastClass fastClass = FastClass.create(beanEventType.getUnderlyingType());
fctor = fastClass.getConstructor(ctor);
}
catch (EngineImportException ex) {
throw new ExprValidationException("Failed to find a suitable constructor for bean-event type '" + eventType.getName() + "': " + ex.getMessage(), ex);
}