Exemple #1
0
        /// <summary>
        /// Ctor.
        /// </summary>
        /// <param name="eventTypeMetadata">event type metadata</param>
        /// <param name="eventTypeId">The event type id.</param>
        /// <param name="config">configuration for type</param>
        /// <param name="schemaModel">the schema representation</param>
        /// <param name="eventAdapterService">type lookup and registration</param>
        public SchemaXMLEventType(EventTypeMetadata eventTypeMetadata, int eventTypeId, ConfigurationEventTypeXMLDOM config, SchemaModel schemaModel, EventAdapterService eventAdapterService)
            : base(eventTypeMetadata, eventTypeId, config, eventAdapterService)
        {
            _propertyGetterCache       = new Dictionary <String, EventPropertyGetter>();
            _schemaModel               = schemaModel;
            _rootElementNamespace      = config.RootElementNamespace;
            _schemaModelRoot           = SchemaUtil.FindRootElement(schemaModel, _rootElementNamespace, RootElementName);
            _isPropertyExpressionXPath = config.IsXPathPropertyExpr;

            // Set of namespace context for XPath expressions
            var ctx = new XPathNamespaceContext();

            if (config.DefaultNamespace != null)
            {
                ctx.SetDefaultNamespace(config.DefaultNamespace);
            }

            foreach (var entry in config.NamespacePrefixes)
            {
                ctx.AddNamespace(entry.Key, entry.Value);
            }

            NamespaceContext = ctx;

            // add properties for the root element
            var additionalSchemaProps = new List <ExplicitPropertyDescriptor>();

            // Add a property for each complex child element
            foreach (SchemaElementComplex complex in _schemaModelRoot.ComplexElements)
            {
                var  propertyName          = complex.Name;
                var  returnType            = typeof(XmlNode);
                Type propertyComponentType = null;

                if (complex.OptionalSimpleType != null)
                {
                    returnType = SchemaUtil.ToReturnType(complex);
                }
                if (complex.IsArray)
                {
                    // We use XmlNode[] for arrays and NodeList for XPath-Expressions returning Nodeset
                    returnType            = typeof(XmlNode[]);
                    propertyComponentType = typeof(XmlNode);
                }

                bool isFragment = false;
                if (ConfigurationEventTypeXMLDOM.IsAutoFragment && (!ConfigurationEventTypeXMLDOM.IsXPathPropertyExpr))
                {
                    isFragment = CanFragment(complex);
                }

                var indexType = returnType.GetIndexType();
                var isIndexed = indexType != null;
                var getter    = DoResolvePropertyGetter(propertyName, true);
                var desc      = new EventPropertyDescriptor(propertyName, returnType, indexType, false, false, isIndexed, false, isFragment);
                var @explicit = new ExplicitPropertyDescriptor(desc, getter, false, null);
                additionalSchemaProps.Add(@explicit);
            }

            // Add a property for each simple child element
            foreach (SchemaElementSimple simple in _schemaModelRoot.SimpleElements)
            {
                var propertyName = simple.Name;
                var returnType   = SchemaUtil.ToReturnType(simple);
                var getter       = DoResolvePropertyGetter(propertyName, true);
                var indexType    = returnType.GetIndexType();
                var isIndexed    = indexType != null;
                var desc         = new EventPropertyDescriptor(propertyName, returnType, indexType, false, false, isIndexed, false, false);
                var @explicit    = new ExplicitPropertyDescriptor(desc, getter, false, null);
                additionalSchemaProps.Add(@explicit);
            }

            // Add a property for each attribute
            foreach (SchemaItemAttribute attribute in _schemaModelRoot.Attributes)
            {
                var propertyName = attribute.Name;
                var returnType   = SchemaUtil.ToReturnType(attribute);
                var getter       = DoResolvePropertyGetter(propertyName, true);
                var indexType    = returnType.GetIndexType();
                var isIndexed    = indexType != null;
                var desc         = new EventPropertyDescriptor(propertyName, returnType, indexType, false, false, isIndexed, false, false);
                var @explicit    = new ExplicitPropertyDescriptor(desc, getter, false, null);
                additionalSchemaProps.Add(@explicit);
            }

            // Finally add XPath properties as that may depend on the rootElementNamespace
            Initialize(config.XPathProperties.Values, additionalSchemaProps);
        }
Exemple #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);
        }
Exemple #3
0
        public SchemaXMLEventType(
            EventTypeMetadata eventTypeMetadata,
            ConfigurationCommonEventTypeXMLDOM config,
            SchemaModel schemaModel,
            string representsFragmentOfProperty,
            string representsOriginalTypeName,
            EventBeanTypedEventFactory eventBeanTypedEventFactory,
            EventTypeNameResolver eventTypeResolver,
            XMLFragmentEventTypeFactory xmlEventTypeFactory)
            : base(
                eventTypeMetadata,
                config,
                eventBeanTypedEventFactory,
                eventTypeResolver,
                xmlEventTypeFactory)
        {
            propertyGetterCache = new Dictionary<string, EventPropertyGetterSPI>();
            SchemaModel = schemaModel;
            rootElementNamespace = config.RootElementNamespace;
            schemaModelRoot = SchemaUtil.FindRootElement(schemaModel, rootElementNamespace, RootElementName);
            isPropertyExpressionXPath = config.IsXPathPropertyExpr;
            RepresentsFragmentOfProperty = representsFragmentOfProperty;
            RepresentsOriginalTypeName = representsOriginalTypeName;

            // Set of namespace context for XPath expressions
            var ctx = new XPathNamespaceContext();
            if (config.DefaultNamespace != null) {
                ctx.SetDefaultNamespace(config.DefaultNamespace);
            }

            foreach (var entry in config.NamespacePrefixes) {
                ctx.AddNamespace(entry.Key, entry.Value);
            }

            NamespaceContext = ctx;

            // add properties for the root element
            IList<ExplicitPropertyDescriptor> additionalSchemaProps = new List<ExplicitPropertyDescriptor>();

            // Add a property for each complex child element
            foreach (SchemaElementComplex complex in schemaModelRoot.ComplexElements) {
                var propertyName = complex.Name;
                var returnType = typeof(XmlNode);
                Type propertyComponentType = null;

                if (complex.OptionalSimpleType != null) {
                    returnType = SchemaUtil.ToReturnType(complex);
                    if (returnType == typeof(string)) {
                        propertyComponentType = typeof(char);
                    }
                }

                if (complex.IsArray) {
                    returnType = typeof(XmlNode[]); // We use Node[] for arrays and NodeList for XPath-Expressions returning Nodeset
                    propertyComponentType = typeof(XmlNode);
                }

                var isFragment = false;
                if (ConfigurationEventTypeXMLDOM.IsAutoFragment && !ConfigurationEventTypeXMLDOM.IsXPathPropertyExpr) {
                    isFragment = CanFragment(complex);
                }

                var getter = DoResolvePropertyGetter(propertyName, true);
                var desc = new EventPropertyDescriptor(
                    propertyName,
                    returnType,
                    propertyComponentType,
                    false,
                    false,
                    complex.IsArray,
                    false,
                    isFragment);
                var @explicit = new ExplicitPropertyDescriptor(desc, getter, false, null);
                additionalSchemaProps.Add(@explicit);
            }

            // Add a property for each simple child element
            foreach (var simple in schemaModelRoot.SimpleElements) {
                var propertyName = simple.Name;
                var returnType = SchemaUtil.ToReturnType(simple);
                var componentType = GenericExtensions.GetComponentType(returnType);
                var isIndexed = simple.IsArray || componentType != null;
                var getter = DoResolvePropertyGetter(propertyName, true);
                var desc = new EventPropertyDescriptor(
                    propertyName,
                    returnType,
                    componentType,
                    false,
                    false,
                    isIndexed,
                    false,
                    false);
                var @explicit = new ExplicitPropertyDescriptor(desc, getter, false, null);
                additionalSchemaProps.Add(@explicit);
            }

            // Add a property for each attribute
            foreach (var attribute in schemaModelRoot.Attributes) {
                var propertyName = attribute.Name;
                var returnType = SchemaUtil.ToReturnType(attribute);
                var componentType = GenericExtensions.GetComponentType(returnType);
                var isIndexed = componentType != null;
                var getter = DoResolvePropertyGetter(propertyName, true);
                var desc = new EventPropertyDescriptor(
                    propertyName,
                    returnType,
                    componentType,
                    false,
                    false,
                    isIndexed,
                    false,
                    false);
                var @explicit = new ExplicitPropertyDescriptor(desc, getter, false, null);
                additionalSchemaProps.Add(@explicit);
            }

            // Finally add XPath properties as that may depend on the rootElementNamespace
            Initialize(config.XPathProperties.Values, additionalSchemaProps);
        }