public void ReplaceXMLEventType(String xmlEventTypeName, ConfigurationEventTypeXMLDOM config)
        {
            SchemaModel schemaModel = null;

            if (config.SchemaResource != null || config.SchemaText != null)
            {
                try
                {
                    schemaModel = XSDSchemaMapper.LoadAndMap(config.SchemaResource, config.SchemaText);
                }
                catch (Exception ex)
                {
                    throw new ConfigurationException(ex.Message, ex);
                }
            }

            try
            {
                _eventAdapterService.ReplaceXMLEventType(xmlEventTypeName, config, schemaModel);
            }
            catch (EventAdapterException e)
            {
                throw new ConfigurationException("Error updating XML event type: " + e.Message, e);
            }
        }
        public void AddEventType(String eventTypeName, ConfigurationEventTypeXMLDOM xmlDOMEventTypeDesc)
        {
            SchemaModel schemaModel = null;

            CheckTableExists(eventTypeName);

            if ((xmlDOMEventTypeDesc.SchemaResource != null) || (xmlDOMEventTypeDesc.SchemaText != null))
            {
                try
                {
                    schemaModel = XSDSchemaMapper.LoadAndMap(xmlDOMEventTypeDesc.SchemaResource, xmlDOMEventTypeDesc.SchemaText);
                }
                catch (Exception ex)
                {
                    throw new ConfigurationException(ex.Message, ex);
                }
            }

            try
            {
                _eventAdapterService.AddXMLDOMType(eventTypeName, xmlDOMEventTypeDesc, schemaModel, false);
            }
            catch (EventAdapterException t)
            {
                throw new ConfigurationException(t.Message, t);
            }
        }
Пример #3
0
        public void RegisterXMLNewType(
            EventTypeMetadata metadata,
            ConfigurationCommonEventTypeXMLDOM config)
        {
            SchemaModel schemaModel = null;
            if ((config.SchemaResource != null) || (config.SchemaText != null)) {
                try {
                    schemaModel = XSDSchemaMapper.LoadAndMap(
                        config.SchemaResource,
                        config.SchemaText,
                        _container.ResourceManager());
                }
                catch (Exception ex) {
                    throw new EPException(ex.Message, ex);
                }
            }

            EventType eventType = _eventTypeFactory.CreateXMLType(
                metadata,
                config,
                schemaModel,
                null,
                metadata.Name,
                _beanEventTypeFactory,
                _xmlFragmentEventTypeFactory,
                _eventTypeNameResolver);
            HandleRegister(eventType);

            if (eventType is SchemaXMLEventType) {
                _xmlFragmentEventTypeFactory.AddRootType((SchemaXMLEventType) eventType);
            }
        }
        public static void BuildXMLTypes(
            EventTypeRepositoryImpl repo,
            IDictionary<string, ConfigurationCommonEventTypeXMLDOM> eventTypesXMLDOM,
            BeanEventTypeFactory beanEventTypeFactory,
            XMLFragmentEventTypeFactory xmlFragmentEventTypeFactory,
            IResourceManager resourceManager)
        {
            // Add from the configuration the XML DOM names and type def
            foreach (var entry in eventTypesXMLDOM) {
                if (repo.GetTypeByName(entry.Key) != null) {
                    continue;
                }
                
                SchemaModel schemaModel = null;
                if (entry.Value.SchemaResource != null || entry.Value.SchemaText != null) {
                    try {
                        schemaModel = XSDSchemaMapper.LoadAndMap(
                            entry.Value.SchemaResource,
                            entry.Value.SchemaText,
                            resourceManager);
                    }
                    catch (Exception ex) {
                        throw new ConfigurationException(ex.Message, ex);
                    }
                }

                try {
                    AddXMLDOMType(
                        repo,
                        entry.Key,
                        entry.Value,
                        schemaModel,
                        beanEventTypeFactory,
                        xmlFragmentEventTypeFactory);
                }
                catch (Exception ex) {
                    throw new ConfigurationException(ex.Message, ex);
                }
            }
        }
Пример #5
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);
            }
        }