private PatternValidatedDesc ValidatePatternContextConditionPattern( bool isStartCondition, int nestingLevel, ContextSpecConditionPattern pattern, ISet<string> eventTypesReferenced, MatchEventSpec priorMatches, ISet<string> priorAllTags, CreateContextValidationEnv validationEnv) { var raw = new PatternStreamSpecRaw( pattern.PatternRaw, ViewSpec.EMPTY_VIEWSPEC_ARRAY, null, StreamSpecOptions.DEFAULT, false, false); var compiledDesc = StreamSpecCompiler.CompilePatternWTags( raw, eventTypesReferenced, false, priorMatches, priorAllTags, false, true, false, 0, validationEnv.StatementRawInfo, validationEnv.Services); var compiled = (PatternStreamSpecCompiled) compiledDesc.StreamSpecCompiled; pattern.PatternCompiled = compiled; pattern.PatternContext = new PatternContext( 0, compiled.MatchedEventMapMeta, true, nestingLevel, isStartCondition); var forges = compiled.Root.CollectFactories(); foreach (var forge in forges) { forge.CollectSelfFilterAndSchedule( validationEnv.FilterSpecCompileds, validationEnv.ScheduleHandleCallbackProviders); } var spec = new MatchEventSpec(compiled.TaggedEventTypes, compiled.ArrayEventTypes); return new PatternValidatedDesc(spec, compiled.AllTags, compiledDesc.AdditionalForgeables); }
private ContextDetailMatchPair ValidateRewriteContextCondition( bool isStartCondition, int nestingLevel, ContextSpecCondition endpoint, ISet<string> eventTypesReferenced, MatchEventSpec priorMatches, ISet<string> priorAllTags, CreateContextValidationEnv validationEnv) { if (endpoint is ContextSpecConditionCrontab) { var crontab = (ContextSpecConditionCrontab) endpoint; var forgesPerCrontab = new ExprForge[crontab.Crontabs.Count][]; for (int i = 0; i < crontab.Crontabs.Count; i++) { var item = crontab.Crontabs[i]; var forges = ScheduleExpressionUtil.CrontabScheduleValidate( ExprNodeOrigin.CONTEXTCONDITION, item, false, validationEnv.StatementRawInfo, validationEnv.Services); forgesPerCrontab[i] = forges; } crontab.ForgesPerCrontab = forgesPerCrontab; validationEnv.ScheduleHandleCallbackProviders.Add(crontab); return new ContextDetailMatchPair( crontab, new MatchEventSpec(), new LinkedHashSet<string>(), EmptyList<StmtClassForgeableFactory>.Instance); } if (endpoint is ContextSpecConditionTimePeriod) { var timePeriod = (ContextSpecConditionTimePeriod) endpoint; var validationContext = new ExprValidationContextBuilder( new StreamTypeServiceImpl(false), validationEnv.StatementRawInfo, validationEnv.Services).Build(); ExprNodeUtilityValidate.GetValidatedSubtree( ExprNodeOrigin.CONTEXTCONDITION, timePeriod.TimePeriod, validationContext); if (timePeriod.TimePeriod.IsConstantResult) { if (timePeriod.TimePeriod.EvaluateAsSeconds(null, true, null) < 0) { throw new ExprValidationException( "Invalid negative time period expression '" + ExprNodeUtilityPrint.ToExpressionStringMinPrecedenceSafe(timePeriod.TimePeriod) + "'"); } } validationEnv.ScheduleHandleCallbackProviders.Add(timePeriod); return new ContextDetailMatchPair( timePeriod, new MatchEventSpec(), new LinkedHashSet<string>(), EmptyList<StmtClassForgeableFactory>.Instance); } if (endpoint is ContextSpecConditionPattern) { var pattern = (ContextSpecConditionPattern) endpoint; var matches = ValidatePatternContextConditionPattern( isStartCondition, nestingLevel, pattern, eventTypesReferenced, priorMatches, priorAllTags, validationEnv); var validatedDesc = ValidatePatternContextConditionPattern( isStartCondition, nestingLevel, pattern, eventTypesReferenced, priorMatches, priorAllTags, validationEnv); return new ContextDetailMatchPair( pattern, validatedDesc.MatchEventSpec, validatedDesc.AllTags, validatedDesc.AdditionalForgeables); } if (endpoint is ContextSpecConditionFilter) { var filter = (ContextSpecConditionFilter) endpoint; ValidateNotTable(filter.FilterSpecRaw.EventTypeName, validationEnv.Services); // compile as filter if there are no prior match to consider if (priorMatches == null || priorMatches.ArrayEventTypes.IsEmpty() && priorMatches.TaggedEventTypes.IsEmpty()) { var rawExpr = new FilterStreamSpecRaw( filter.FilterSpecRaw, ViewSpec.EMPTY_VIEWSPEC_ARRAY, null, StreamSpecOptions.DEFAULT); var compiledDesc = StreamSpecCompiler.Compile( rawExpr, eventTypesReferenced, false, false, true, false, filter.OptionalFilterAsName, 0, validationEnv.StatementRawInfo, validationEnv.Services); var compiled = (FilterStreamSpecCompiled) compiledDesc.StreamSpecCompiled; filter.FilterSpecCompiled = compiled.FilterSpecCompiled; var matchEventSpec = new MatchEventSpec(); var filterForType = compiled.FilterSpecCompiled.FilterForEventType; var allTags = new LinkedHashSet<string>(); if (filter.OptionalFilterAsName != null) { matchEventSpec.TaggedEventTypes.Put( filter.OptionalFilterAsName, new Pair<EventType, string>(filterForType, rawExpr.RawFilterSpec.EventTypeName)); allTags.Add(filter.OptionalFilterAsName); } validationEnv.FilterSpecCompileds.Add(compiled.FilterSpecCompiled); var serdeForgeables = SerdeEventTypeUtility.Plan( filter.FilterSpecCompiled.FilterForEventType, validationEnv.StatementRawInfo, validationEnv.Services.SerdeEventTypeRegistry, validationEnv.Services.SerdeResolver); var allForgeables = compiledDesc.AdditionalForgeables .Concat(serdeForgeables) .ToList(); return new ContextDetailMatchPair(filter, matchEventSpec, allTags, allForgeables); } // compile as pattern if there are prior matches to consider, since this is a type of followed-by relationship EvalForgeNode forgeNode = new EvalFilterForgeNode(validationEnv.Services.IsAttachPatternText, filter.FilterSpecRaw, filter.OptionalFilterAsName, 0); var pattern = new ContextSpecConditionPattern(forgeNode, true, false); var validated = ValidatePatternContextConditionPattern( isStartCondition, nestingLevel, pattern, eventTypesReferenced, priorMatches, priorAllTags, validationEnv); return new ContextDetailMatchPair(pattern, validated.MatchEventSpec, validated.AllTags, validated.AdditionalForgeables); } if (endpoint is ContextSpecConditionImmediate || endpoint is ContextSpecConditionNever) { return new ContextDetailMatchPair( endpoint, new MatchEventSpec(), new LinkedHashSet<String>(), EmptyList<StmtClassForgeableFactory>.Instance); } throw new IllegalStateException("Unrecognized endpoint type " + endpoint); }