public PluggableObjectEntry( PluggableObjectType type, object customConfigs) { PluggableType = type; CustomConfigs = customConfigs; }
/// <summary> /// Add a single object to the collection. /// </summary> /// <param name="namespace">is the object's namespace</param> /// <param name="name">is the object's name</param> /// <param name="clazz">is the class the object resolves to</param> /// <param name="type">is the object type</param> public void AddObject( string @namespace, string name, Type clazz, PluggableObjectType type) { AddObject(@namespace, name, clazz, type, null); }
/// <summary> /// Add a single object to the collection also adding additional configuration. /// </summary> /// <param name="namespace">is the object's namespace</param> /// <param name="name">is the object's name</param> /// <param name="clazz">is the class the object resolves to</param> /// <param name="type">is the object type</param> /// <param name="configuration">The configuration.</param> public void AddObject(String @namespace, String name, Type clazz, PluggableObjectType type, Object configuration) { var namespaceMap = Pluggables.Get(@namespace); if (namespaceMap == null) { namespaceMap = new Dictionary <String, Pair <Type, PluggableObjectEntry> >(); Pluggables.Put(@namespace, namespaceMap); } namespaceMap.Put(name, new Pair <Type, PluggableObjectEntry>(clazz, new PluggableObjectEntry(type, configuration))); }
/// <summary> /// Add a single object to the collection also adding additional configuration. /// </summary> /// <param name="namespace">is the object's namespace</param> /// <param name="name">is the object's name</param> /// <param name="clazz">is the class the object resolves to</param> /// <param name="type">is the object type</param> /// <param name="configuration">config</param> public void AddObject( string @namespace, string name, Type clazz, PluggableObjectType type, object configuration) { SerializableExtensions.EnsureSerializable(configuration); var namespaceMap = Pluggables.Get(@namespace); if (namespaceMap == null) { namespaceMap = new Dictionary<string, Pair<Type, PluggableObjectEntry>>(); Pluggables.Put(@namespace, namespaceMap); } namespaceMap.Put( name, new Pair<Type, PluggableObjectEntry>(clazz, new PluggableObjectEntry(type, configuration))); }
private void HandleAddPluggableObject( string factoryClassName, string @namespace, string name, PluggableObjectType type, object optionalCustomConfig, ImportServiceCompileTime importService) { SerializableExtensions.EnsureSerializable(optionalCustomConfig); if (factoryClassName == null) { throw new ConfigurationException("Factory class name has not been supplied for object '" + name + "'"); } if (@namespace == null) { throw new ConfigurationException("Namespace name has not been supplied for object '" + name + "'"); } if (name == null) { throw new ConfigurationException( "Name has not been supplied for object in namespace '" + @namespace + "'"); } Type clazz; try { clazz = importService.ClassForNameProvider.ClassForName(factoryClassName); } catch (TypeLoadException) { throw new ConfigurationException("View factory class " + factoryClassName + " could not be loaded"); } var namespaceMap = Pluggables.Get(@namespace); if (namespaceMap == null) { namespaceMap = new Dictionary<string, Pair<Type, PluggableObjectEntry>>(); Pluggables.Put(@namespace, namespaceMap); } namespaceMap.Put( name, new Pair<Type, PluggableObjectEntry>(clazz, new PluggableObjectEntry(type, optionalCustomConfig))); }
private void HandleAddPluggableObject( String factoryClassName, String @namespace, String name, PluggableObjectType type, Object optionalCustomConfig, EngineImportService engineImportService) { if (factoryClassName == null) { throw new ConfigurationException("Factory class name has not been supplied for object '" + name + "'"); } if (@namespace == null) { throw new ConfigurationException("Namespace name has not been supplied for object '" + name + "'"); } if (name == null) { throw new ConfigurationException("Name has not been supplied for object in namespace '" + @namespace + "'"); } try { var clazz = engineImportService.GetClassForNameProvider().ClassForName(factoryClassName); var namespaceMap = Pluggables.Get(@namespace); if (namespaceMap == null) { namespaceMap = new Dictionary <String, Pair <Type, PluggableObjectEntry> >(); Pluggables.Put(@namespace, namespaceMap); } namespaceMap.Put( name, new Pair <Type, PluggableObjectEntry>(clazz, new PluggableObjectEntry(type, optionalCustomConfig))); } catch (TypeLoadException e) { throw new ConfigurationException("View factory class " + factoryClassName + " could not be loaded", e); } }
private Object CreateFactory(ObjectSpec spec, PluggableObjectType type) { if (Log.IsDebugEnabled) { Log.Debug(".create Creating factory, spec=" + spec); } // Find the factory class for this pattern object Type factoryClass = null; IDictionary <String, Pair <Type, PluggableObjectEntry> > namespaceMap = _patternObjects.Pluggables.Get(spec.ObjectNamespace); if (namespaceMap != null) { Pair <Type, PluggableObjectEntry> pair = namespaceMap.Get(spec.ObjectName); if (pair != null) { if (pair.Second.PluggableType == type) { factoryClass = pair.First; } else { // invalid type: expecting observer, got guard if (type == PluggableObjectType.PATTERN_GUARD) { throw new PatternObjectException("Pattern observer function '" + spec.ObjectName + "' cannot be used as a pattern guard"); } else { throw new PatternObjectException("Pattern guard function '" + spec.ObjectName + "' cannot be used as a pattern observer"); } } } } if (factoryClass == null) { if (type == PluggableObjectType.PATTERN_GUARD) { String message = "Pattern guard name '" + spec.ObjectName + "' is not a known pattern object name"; throw new PatternObjectException(message); } else if (type == PluggableObjectType.PATTERN_OBSERVER) { String message = "Pattern observer name '" + spec.ObjectName + "' is not a known pattern object name"; throw new PatternObjectException(message); } else { throw new PatternObjectException("Pattern object type '" + type + "' not known"); } } Object result; try { result = Activator.CreateInstance(factoryClass); } catch (TypeInstantiationException ex) { String message = "Error invoking pattern object factory constructor for object '" + spec.ObjectName; message += "' using Activator.CreateInstance"; throw new PatternObjectException(message, ex); } catch (TargetInvocationException ex) { String message = "Error invoking pattern object factory constructor for object '" + spec.ObjectName; message += "' using Activator.CreateInstance"; throw new PatternObjectException(message, ex); } catch (MethodAccessException ex) { String message = "Error invoking pattern object factory constructor for object '" + spec.ObjectName; message += "', no invocation access for Activator.CreateInstance"; throw new PatternObjectException(message, ex); } catch (MemberAccessException ex) { String message = "Error invoking pattern object factory constructor for object '" + spec.ObjectName; message += "', no invocation access for Activator.CreateInstance"; throw new PatternObjectException(message, ex); } return(result); }
private void HandleAddPluggableObject(String factoryClassName, String @namespace, String name, PluggableObjectType type, Object optionalCustomConfig) { if (factoryClassName == null) { throw new ConfigurationException("Factory class name has not been supplied for object '" + name + "'"); } if (@namespace == null) { throw new ConfigurationException("Namespace name has not been supplied for object '" + name + "'"); } if (name == null) { throw new ConfigurationException("Name has not been supplied for object in namespace '" + @namespace + "'"); } var clazz = TypeHelper.ResolveType(factoryClassName, false); if (clazz == null) { throw new ConfigurationException("View factory class " + factoryClassName + " could not be loaded"); } var namespaceMap = Pluggables.Get(@namespace); if (namespaceMap == null) { namespaceMap = new Dictionary <String, Pair <Type, PluggableObjectEntry> >(); Pluggables.Put(@namespace, namespaceMap); } namespaceMap.Put(name, new Pair <Type, PluggableObjectEntry>(clazz, new PluggableObjectEntry(type, optionalCustomConfig))); }
private object CreateForge( ObjectSpec spec, PluggableObjectType type) { if (Log.IsDebugEnabled) { Log.Debug(".create Creating factory, spec=" + spec); } // Find the factory class for this pattern object Type forgeClass = null; var namespaceMap = patternObjects.Pluggables.Get(spec.ObjectNamespace); var pair = namespaceMap?.Get(spec.ObjectName); if (pair != null) { if (pair.Second.PluggableType == type) { forgeClass = pair.First; } else { // invalid type: expecting observer, got guard if (type == PluggableObjectType.PATTERN_GUARD) { throw new PatternObjectException( "Pattern observer function '" + spec.ObjectName + "' cannot be used as a pattern guard"); } throw new PatternObjectException( "Pattern guard function '" + spec.ObjectName + "' cannot be used as a pattern observer"); } } if (forgeClass == null) { if (type == PluggableObjectType.PATTERN_GUARD) { var message = "Pattern guard name '" + spec.ObjectName + "' is not a known pattern object name"; throw new PatternObjectException(message); } if (type == PluggableObjectType.PATTERN_OBSERVER) { var message = "Pattern observer name '" + spec.ObjectName + "' is not a known pattern object name"; throw new PatternObjectException(message); } throw new PatternObjectException("Pattern object type '" + type + "' not known"); } object result; try { if (forgeClass == typeof(string)) { result = string.Empty; } else { result = TypeHelper.Instantiate(forgeClass); } } catch (MemberAccessException e) { var message = "Error invoking pattern object factory constructor for object '" + spec.ObjectName; message += "', no invocation access for Class.newInstance"; throw new PatternObjectException(message, e); } return result; }