예제 #1
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);
            }
        }
 public void AddEventTypeAutoName(String @namespace)
 {
     _eventAdapterService.AddAutoNamePackage(@namespace);
 }
예제 #3
0
 public void AddEventTypeAutoName(string javaPackageName)
 {
     _eventAdapterService.AddAutoNamePackage(javaPackageName);
 }