Example #1
0
        public override ExprNode Validate(ExprValidationContext validationContext)
        {
            // rewrite expression into a table-access expression
            if (validationContext.StreamTypeService.HasTableTypes)
            {
                ExprTableIdentNode tableIdentNode = validationContext.TableService.GetTableIdentNode(validationContext.StreamTypeService, _unresolvedPropertyName, _streamOrPropertyName);
                if (tableIdentNode != null)
                {
                    return(tableIdentNode);
                }
            }

            string unescapedPropertyName = PropertyParser.UnescapeBacktick(_unresolvedPropertyName);
            Pair <PropertyResolutionDescriptor, string> propertyInfoPair = ExprIdentNodeUtil.GetTypeFromStream(validationContext.StreamTypeService, unescapedPropertyName, _streamOrPropertyName, false);

            _resolvedStreamName = propertyInfoPair.Second;
            int  streamNum    = propertyInfoPair.First.StreamNum;
            Type propertyType = propertyInfoPair.First.PropertyType;

            _resolvedPropertyName = propertyInfoPair.First.PropertyName;
            EventPropertyGetter propertyGetter;

            try {
                propertyGetter = propertyInfoPair.First.StreamEventType.GetGetter(_resolvedPropertyName);
            }
            catch (PropertyAccessException ex) {
                throw new ExprValidationException("Property '" + _unresolvedPropertyName + "' is not valid: " + ex.Message, ex);
            }

            if (propertyGetter == null)
            {
                throw new ExprValidationException("Property getter returned was invalid for property '" + _unresolvedPropertyName + "'");
            }

            var audit = AuditEnum.PROPERTY.GetAudit(validationContext.Annotations);

            if (audit != null)
            {
                _evaluator = new ExprIdentNodeEvaluatorLogging(streamNum, propertyGetter, propertyType, this, _resolvedPropertyName, validationContext.StatementName, validationContext.StreamTypeService.EngineURIQualifier);
            }
            else
            {
                _evaluator = new ExprIdentNodeEvaluatorImpl(streamNum, propertyGetter, propertyType, this);
            }

            // if running in a context, take the property value from context
            if (validationContext.ContextDescriptor != null && !validationContext.IsFilterExpression)
            {
                EventType fromType            = validationContext.StreamTypeService.EventTypes[streamNum];
                string    contextPropertyName = validationContext.ContextDescriptor.ContextPropertyRegistry.GetPartitionContextPropertyName(fromType, _resolvedPropertyName);
                if (contextPropertyName != null)
                {
                    EventType contextType = validationContext.ContextDescriptor.ContextPropertyRegistry.ContextEventType;
                    _evaluator = new ExprIdentNodeEvaluatorContext(streamNum, contextType.GetPropertyType(contextPropertyName), contextType.GetGetter(contextPropertyName));
                }
            }
            return(null);
        }
Example #2
0
 public static void ToPrecedenceFreeEPL(TextWriter writer, string streamOrPropertyName, string unresolvedPropertyName)
 {
     if (streamOrPropertyName != null)
     {
         writer.Write(ASTUtil.UnescapeDot(streamOrPropertyName));
         writer.Write('.');
     }
     writer.Write(ASTUtil.UnescapeDot(PropertyParser.UnescapeBacktick(unresolvedPropertyName)));
 }