Пример #1
0
        protected override EventPropertyGetter DoResolvePropertyGetter(String propertyExpression)
        {
            var getter = _propertyGetterCache.Get(propertyExpression);

            if (getter != null)
            {
                return(getter);
            }

            if (!ConfigurationEventTypeXMLDOM.IsXPathPropertyExpr)
            {
                var prop = PropertyParser.ParseAndWalkLaxToSimple(propertyExpression);
                getter = prop.GetGetterDOM();
                if (!prop.IsDynamic)
                {
                    getter = new DOMConvertingGetter(propertyExpression, (DOMPropertyGetter)getter, typeof(string));
                }
            }
            else
            {
                try
                {
                    var ast       = PropertyParser.Parse(propertyExpression);
                    var isDynamic = PropertyParser.IsPropertyDynamic(ast);
                    var xPathExpr = SimpleXMLPropertyParser.Walk(
                        ast,
                        propertyExpression,
                        RootElementName,
                        _defaultNamespacePrefix,
                        _isResolvePropertiesAbsolute);

                    if (Log.IsInfoEnabled)
                    {
                        Log.Info("Compiling XPath expression for property '" + propertyExpression + "' as '" + xPathExpr +
                                 "'");
                    }

                    var xPathExpression = XPathExpression.Compile(xPathExpr, NamespaceContext);
                    var xPathReturnType = isDynamic ? XPathResultType.Any : XPathResultType.String;
                    getter = new XPathPropertyGetter(
                        propertyExpression,
                        xPathExpr,
                        xPathExpression,
                        xPathReturnType,
                        null,
                        null);
                }
                catch (XPathException e)
                {
                    throw new EPException(
                              "Error constructing XPath expression from property name '" + propertyExpression + '\'', e);
                }
            }

            // no fragment factory, fragments not allowed
            _propertyGetterCache.Put(propertyExpression, getter);
            return(getter);
        }
Пример #2
0
        /// <summary>
        /// Set the preconfigured event properties resolved by XPath expression.
        /// </summary>
        /// <param name="explicitXPathProperties">are preconfigured event properties</param>
        /// <param name="additionalSchemaProperties">the explicit properties</param>
        protected void Initialize(ICollection <ConfigurationEventTypeXMLDOM.XPathPropertyDesc> explicitXPathProperties,
                                  IList <ExplicitPropertyDescriptor> additionalSchemaProperties)
        {
            // make sure we override those explicitly provided with those derived from a metadataz
            var namedProperties = new LinkedHashMap <String, ExplicitPropertyDescriptor>();

            foreach (ExplicitPropertyDescriptor desc in additionalSchemaProperties)
            {
                namedProperties[desc.Descriptor.PropertyName] = desc;
            }

            String xPathExpression = null;

            try
            {
                foreach (ConfigurationEventTypeXMLDOM.XPathPropertyDesc property in explicitXPathProperties)
                {
                    xPathExpression = property.XPath;
                    if (Log.IsInfoEnabled)
                    {
                        Log.Info("Compiling XPath expression for property '" + property.Name + "' as '" +
                                 xPathExpression + "'");
                    }

                    var expressionContext = NamespaceContext ?? GetExtendedContext();
                    var expression        = XPathExpression.Compile(xPathExpression, expressionContext);

                    FragmentFactoryXPathPredefinedGetter fragmentFactory = null;

                    var isFragment = false;
                    if (property.OptionalEventTypeName != null)
                    {
                        fragmentFactory = new FragmentFactoryXPathPredefinedGetter(
                            EventAdapterService,
                            property.OptionalEventTypeName,
                            property.Name);
                        isFragment = true;
                    }

                    var getter = new XPathPropertyGetter(
                        property.Name,
                        xPathExpression,
                        expression,
                        property.ResultType,
                        property.OptionalCastToType,
                        fragmentFactory);
                    var returnType = SchemaUtil.ToReturnType(
                        property.ResultType,
                        property.OptionalCastToType.GetBoxedType());
                    var indexType = returnType.GetIndexType();
                    var isIndexed = indexType != null;

                    if (property.ResultType == XPathResultType.NodeSet)
                    {
                        isIndexed = true;
                    }

                    var desc = new EventPropertyDescriptor(
                        property.Name, returnType, indexType, false, false,
                        isIndexed, false, isFragment);
                    var @explicit = new ExplicitPropertyDescriptor(
                        desc, getter, isIndexed,
                        property.OptionalEventTypeName);

                    namedProperties[desc.PropertyName] = @explicit;
                }
            }
            catch (XPathException ex)
            {
                throw new EPException(
                          "XPath expression could not be compiled for expression '" + xPathExpression + '\'', ex);
            }

            Initialize(namedProperties.Values);

            // evaluate start and end timestamp properties if any
            _startTimestampPropertyName = ConfigurationEventTypeXMLDOM.StartTimestampPropertyName;
            _endTimestampPropertyName   = ConfigurationEventTypeXMLDOM.EndTimestampPropertyName;
            EventTypeUtility.ValidateTimestampProperties(this, _startTimestampPropertyName, _endTimestampPropertyName);
        }