public class EvalSelectStreamWUndRecastMapFactory {
public static SelectExprProcessor make(EventType[] eventTypes, SelectExprContext selectExprContext, int streamNumber, EventType targetType, ExprNode[] exprNodes, EngineImportService engineImportService)
throws ExprValidationException
{
MapEventType mapResultType = (MapEventType) targetType;
MapEventType mapStreamType = (MapEventType) eventTypes[streamNumber];
// (A) fully assignment-compatible: same number, name and type of fields, no additional expressions: Straight repackage
String typeSameMssage = BaseNestableEventType.isDeepEqualsProperties(mapResultType.getName(), mapResultType.getTypes(), mapStreamType.getTypes());
if (typeSameMssage == null && selectExprContext.getExpressionNodes().length == 0) {
return new MapInsertProcessorSimpleRepackage(selectExprContext, streamNumber, targetType);
}
// (B) not completely assignable: find matching properties
Set<WriteablePropertyDescriptor> writables = selectExprContext.getEventAdapterService().getWriteableProperties(mapResultType, true);
List<Item> items = new ArrayList<Item>();
List<WriteablePropertyDescriptor> written = new ArrayList<WriteablePropertyDescriptor>();
// find the properties coming from the providing source stream
int count = 0;
for (WriteablePropertyDescriptor writeable : writables) {
String propertyName = writeable.getPropertyName();
if (mapStreamType.getTypes().containsKey(propertyName)) {
Object setOneType = mapStreamType.getTypes().get(propertyName);
Object setTwoType = mapResultType.getTypes().get(propertyName);
boolean setTwoTypeFound = mapResultType.getTypes().containsKey(propertyName);
String message = BaseNestableEventUtil.comparePropType(propertyName, setOneType, setTwoType, setTwoTypeFound, mapResultType.getName());
if (message != null) {
throw new ExprValidationException(message);