public void AddPlugInEventType(string eventTypeName, IList <Uri> resolutionURIs, object initializer)
 {
     try
     {
         _eventAdapterService.AddPlugInEventType(eventTypeName, resolutionURIs, initializer);
     }
     catch (EventAdapterException e)
     {
         throw new ConfigurationException("Error adding plug-in event type: " + e.Message, e);
     }
 }
Пример #2
0
        public void AddPlugInEventType(string eventTypeName, Uri[] resolutionURIs, object initializer)
        {
            if (initializer == null)
            {
                throw new ArgumentNullException("initializer");
            }

            if (!initializer.GetType().IsSerializable)
            {
                throw new ArgumentException("initializer is not serializable", "initializer");
            }

            try {
                _eventAdapterService.AddPlugInEventType(eventTypeName, resolutionURIs, initializer);
            } catch (EventAdapterException e) {
                throw new ConfigurationException("Error adding plug-in event type: " + e.Message, e);
            }
        }
Пример #3
0
        /// <summary>Resolves a given event name to an event type. </summary>
        /// <param name="eventName">is the name to resolve</param>
        /// <param name="eventAdapterService">for resolving event types</param>
        /// <param name="engineURI">the provider URI</param>
        /// <param name="optionalResolutionURIs">is URIs for resolving the event name against plug-inn event representations, if any</param>
        /// <returns>event type</returns>
        /// <throws>ExprValidationException if the info cannot be resolved</throws>
        public static EventType ResolveType(String engineURI, String eventName, EventAdapterService eventAdapterService, IList <Uri> optionalResolutionURIs)
        {
            var eventType = eventAdapterService.GetEventTypeByName(eventName);

            // may already be known
            if (eventType != null)
            {
                return(eventType);
            }

            var engineURIQualifier = engineURI;

            if (engineURI == null || EPServiceProviderConstants.DEFAULT_ENGINE_URI.Equals(engineURI))
            {
                engineURIQualifier = EPServiceProviderConstants.DEFAULT_ENGINE_URI__QUALIFIER;
            }

            // The event name can be prefixed by the engine URI, i.e. "select * from default.MyEvent"
            if (eventName.StartsWith(engineURIQualifier))
            {
                var indexDot = eventName.IndexOf('.');
                if (indexDot > 0)
                {
                    var eventNameURI       = eventName.Substring(0, indexDot);
                    var eventNameRemainder = eventName.Substring(indexDot + 1);

                    if (engineURIQualifier.Equals(eventNameURI))
                    {
                        eventType = eventAdapterService.GetEventTypeByName(eventNameRemainder);
                    }
                }
            }

            // may now be known
            if (eventType != null)
            {
                return(eventType);
            }

            // The type is not known yet, attempt to add as an object type with the same name
            String message = null;

            try
            {
                eventType = eventAdapterService.AddBeanType(eventName, eventName, true, false, false, false);
            }
            catch (EventAdapterException ex)
            {
                Log.Debug(".resolveType Event type named '" + eventName + "' not resolved as Type event");
                message = "Failed to resolve event type: " + ex.Message;
            }

            // Attempt to use plug-in event types
            try
            {
                eventType = eventAdapterService.AddPlugInEventType(eventName, optionalResolutionURIs, null);
            }
            catch (EventAdapterException)
            {
                Log.Debug(".resolveType Event type named '" + eventName + "' not resolved by plug-in event representations");
                // remains unresolved
            }

            if (eventType == null)
            {
                throw new ExprValidationException(message);
            }
            return(eventType);
        }
Пример #4
0
        /// <summary>Initialize event adapter service for config snapshot. </summary>
        /// <param name="eventAdapterService">is events adapter</param>
        /// <param name="configSnapshot">is the config snapshot</param>
        internal static void Init(EventAdapterService eventAdapterService, ConfigurationInformation configSnapshot)
        {
            // Extract legacy event type definitions for each event type name, if supplied.
            //
            // We supply this information as setup information to the event adapter service
            // to allow discovery of superclasses and interfaces during event type construction for bean events,
            // such that superclasses and interfaces can use the legacy type definitions.
            IDictionary <String, ConfigurationEventTypeLegacy> classLegacyInfo = new Dictionary <String, ConfigurationEventTypeLegacy>();

            foreach (KeyValuePair <String, String> entry in configSnapshot.EventTypeNames)
            {
                String typeName  = entry.Key;
                String className = entry.Value;
                ConfigurationEventTypeLegacy legacyDef = configSnapshot.EventTypesLegacy.Get(typeName);
                if (legacyDef != null)
                {
                    classLegacyInfo.Put(className, legacyDef);
                }
            }
            eventAdapterService.TypeLegacyConfigs = classLegacyInfo;
            eventAdapterService.DefaultPropertyResolutionStyle = configSnapshot.EngineDefaults.EventMetaConfig.ClassPropertyResolutionStyle;
            eventAdapterService.DefaultAccessorStyle           = configSnapshot.EngineDefaults.EventMetaConfig.DefaultAccessorStyle;

            foreach (String typeNamespace in configSnapshot.EventTypeAutoNamePackages)
            {
                eventAdapterService.AddAutoNamePackage(typeNamespace);
            }

            // Add from the configuration the event class names
            IDictionary <String, String> typeNames = configSnapshot.EventTypeNames;

            foreach (KeyValuePair <String, String> entry in typeNames)
            {
                // Add class
                try
                {
                    String typeName = entry.Key;
                    eventAdapterService.AddBeanType(typeName, entry.Value, false, true, true, true);
                }
                catch (EventAdapterException ex)
                {
                    throw new ConfigurationException("Error configuring engine: " + ex.Message, ex);
                }
            }

            // Add from the configuration the XML DOM names and type def
            IDictionary <String, ConfigurationEventTypeXMLDOM> xmlDOMNames = configSnapshot.EventTypesXMLDOM;

            foreach (KeyValuePair <String, ConfigurationEventTypeXMLDOM> entry in xmlDOMNames)
            {
                SchemaModel schemaModel = null;
                if ((entry.Value.SchemaResource != null) || (entry.Value.SchemaText != null))
                {
                    try
                    {
                        schemaModel = XSDSchemaMapper.LoadAndMap(entry.Value.SchemaResource, entry.Value.SchemaText, 2);
                    }
                    catch (Exception ex)
                    {
                        throw new ConfigurationException(ex.Message, ex);
                    }
                }

                // Add XML DOM type
                try
                {
                    eventAdapterService.AddXMLDOMType(entry.Key, entry.Value, schemaModel, true);
                }
                catch (EventAdapterException ex)
                {
                    throw new ConfigurationException("Error configuring engine: " + ex.Message, ex);
                }
            }

            // Add maps in dependency order such that supertypes are added before subtypes
            ICollection <String> dependentMapOrder;

            try
            {
                var typesReferences = ToTypesReferences(configSnapshot.MapTypeConfigurations);
                dependentMapOrder = GraphUtil.GetTopDownOrder(typesReferences);
            }
            catch (GraphCircularDependencyException e)
            {
                throw new ConfigurationException("Error configuring engine, dependency graph between map type names is circular: " + e.Message, e);
            }

            IDictionary <String, Properties> mapNames = configSnapshot.EventTypesMapEvents;
            IDictionary <String, IDictionary <String, Object> > nestableMapNames = configSnapshot.EventTypesNestableMapEvents;

            dependentMapOrder.AddAll(mapNames.Keys);
            dependentMapOrder.AddAll(nestableMapNames.Keys);
            try
            {
                foreach (String mapName in dependentMapOrder)
                {
                    ConfigurationEventTypeMap mapConfig = configSnapshot.MapTypeConfigurations.Get(mapName);
                    Properties propertiesUnnested       = mapNames.Get(mapName);
                    if (propertiesUnnested != null)
                    {
                        IDictionary <String, Object> propertyTypes         = CreatePropertyTypes(propertiesUnnested);
                        IDictionary <String, Object> propertyTypesCompiled = EventTypeUtility.CompileMapTypeProperties(propertyTypes, eventAdapterService);
                        eventAdapterService.AddNestableMapType(mapName, propertyTypesCompiled, mapConfig, true, true, true, false, false);
                    }

                    IDictionary <String, Object> propertiesNestable = nestableMapNames.Get(mapName);
                    if (propertiesNestable != null)
                    {
                        IDictionary <String, Object> propertiesNestableCompiled = EventTypeUtility.CompileMapTypeProperties(propertiesNestable, eventAdapterService);
                        eventAdapterService.AddNestableMapType(mapName, propertiesNestableCompiled, mapConfig, true, true, true, false, false);
                    }
                }
            }
            catch (EventAdapterException ex)
            {
                throw new ConfigurationException("Error configuring engine: " + ex.Message, ex);
            }

            // Add object-array in dependency order such that supertypes are added before subtypes
            ICollection <string> dependentObjectArrayOrder;

            try
            {
                var typesReferences = ToTypesReferences(configSnapshot.ObjectArrayTypeConfigurations);
                dependentObjectArrayOrder = GraphUtil.GetTopDownOrder(typesReferences);
            }
            catch (GraphCircularDependencyException e)
            {
                throw new ConfigurationException(
                          "Error configuring engine, dependency graph between object array type names is circular: " + e.Message, e);
            }

            var nestableObjectArrayNames = configSnapshot.EventTypesNestableObjectArrayEvents;

            dependentObjectArrayOrder.AddAll(nestableObjectArrayNames.Keys);
            try
            {
                foreach (string objectArrayName in dependentObjectArrayOrder)
                {
                    var objectArrayConfig = configSnapshot.ObjectArrayTypeConfigurations.Get(objectArrayName);
                    var propertyTypes     = nestableObjectArrayNames.Get(objectArrayName);
                    propertyTypes = ResolveClassesForStringPropertyTypes(propertyTypes);
                    var propertyTypesCompiled = EventTypeUtility.CompileMapTypeProperties(propertyTypes, eventAdapterService);
                    eventAdapterService.AddNestableObjectArrayType(objectArrayName, propertyTypesCompiled, objectArrayConfig, true, true, true, false, false, false, null);
                }
            }
            catch (EventAdapterException ex)
            {
                throw new ConfigurationException("Error configuring engine: " + ex.Message, ex);
            }

            // Add plug-in event representations
            var plugInReps = configSnapshot.PlugInEventRepresentation;

            foreach (var entry in plugInReps)
            {
                String className = entry.Value.EventRepresentationTypeName;
                Type   eventRepClass;
                try
                {
                    eventRepClass = TypeHelper.ResolveType(className);
                }
                catch (TypeLoadException ex)
                {
                    throw new ConfigurationException("Failed to load plug-in event representation class '" + className + "'", ex);
                }

                Object pluginEventRepObj;
                try
                {
                    pluginEventRepObj = Activator.CreateInstance(eventRepClass);
                }
                catch (TypeInstantiationException ex)
                {
                    throw new ConfigurationException("Failed to instantiate plug-in event representation class '" + className + "' via default constructor", ex);
                }
                catch (TargetInvocationException ex)
                {
                    throw new ConfigurationException("Failed to instantiate plug-in event representation class '" + className + "' via default constructor", ex);
                }
                catch (MethodAccessException ex)
                {
                    throw new ConfigurationException("Illegal access to instantiate plug-in event representation class '" + className + "' via default constructor", ex);
                }
                catch (MemberAccessException ex)
                {
                    throw new ConfigurationException("Illegal access to instantiate plug-in event representation class '" + className + "' via default constructor", ex);
                }


                if (!(pluginEventRepObj is PlugInEventRepresentation))
                {
                    throw new ConfigurationException("Plug-in event representation class '" + className + "' does not implement the required interface " + typeof(PlugInEventRepresentation).FullName);
                }

                var eventRepURI    = entry.Key;
                var pluginEventRep = (PlugInEventRepresentation)pluginEventRepObj;
                var initializer    = entry.Value.Initializer;
                var context        = new PlugInEventRepresentationContext(eventAdapterService, eventRepURI, initializer);

                try
                {
                    pluginEventRep.Init(context);
                    eventAdapterService.AddEventRepresentation(eventRepURI, pluginEventRep);
                }
                catch (Exception e)
                {
                    throw new ConfigurationException("Plug-in event representation class '" + className + "' and URI '" + eventRepURI + "' did not initialize correctly : " + e.Message, e);
                }
            }

            // Add plug-in event type names
            IDictionary <String, ConfigurationPlugInEventType> plugInNames = configSnapshot.PlugInEventTypes;

            foreach (KeyValuePair <String, ConfigurationPlugInEventType> entry in plugInNames)
            {
                String name = entry.Key;
                ConfigurationPlugInEventType config = entry.Value;
                eventAdapterService.AddPlugInEventType(name, config.EventRepresentationResolutionURIs, config.Initializer);
            }
        }