}
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();
final ExprEvaluator inner = exprEvaluators[i];
evaluators[i] = new ExprEvaluator() {
public Object evaluate(EventBean[] eventsPerStream, boolean isNewData, ExprEvaluatorContext exprEvaluatorContext)
{
EventBean theEvent = (EventBean) inner.evaluate(eventsPerStream, isNewData, exprEvaluatorContext);
if (theEvent != null)
{
return theEvent.getUnderlying();
}
return null;
}
public Class getType()
{
return returnType;
}
};
ctorTypes[i] = returnType;
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;
}
};
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(Thread.currentThread().getContextClassLoader(), 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);
}