public override bool IsDependentOn(IObjectDefinition theOtherObject) { if (theOtherObject == this) { return(true); } if (mSourceImage != null && mSourceImage.IsDependentOn(theOtherObject)) { return(true); } if (mWidth != null && mWidth.IsDependentOn(theOtherObject)) { return(true); } if (mLeftEdge != null && mLeftEdge.IsDependentOn(theOtherObject)) { return(true); } if (mTopEdge != null && mTopEdge.IsDependentOn(theOtherObject)) { return(true); } if (mHeight != null && mHeight.IsDependentOn(theOtherObject)) { return(true); } return(base.IsDependentOn(theOtherObject)); }
public void Add(string key, IObjectDefinition value) { lock(SyncRoot) { base[key] = value; } }
public override bool IsDependentOn(IObjectDefinition theOtherObject) { if (theOtherObject == this) { return(true); } if (mSourceImage != null && mSourceImage.IsDependentOn(theOtherObject)) { return(true); } if (mSearchArea != null && mSearchArea.IsDependentOn(theOtherObject)) { return(true); } if (mSurfaceNoiseThreshold_Min != null && mSurfaceNoiseThreshold_Min.IsDependentOn(theOtherObject)) { return(true); } if (mSurfaceNoiseThreshold_Max != null && mSurfaceNoiseThreshold_Max.IsDependentOn(theOtherObject)) { return(true); } if (mSurfaceNoiseThreshold_PercentOfSharpestEdge != null && mSurfaceNoiseThreshold_PercentOfSharpestEdge.IsDependentOn(theOtherObject)) { return(true); } if (mMinSurfaceSize != null && mMinSurfaceSize.IsDependentOn(theOtherObject)) { return(true); } return(base.IsDependentOn(theOtherObject)); }
public override bool IsDependentOn(IObjectDefinition theOtherObject) { if (theOtherObject == this) { return(true); } if (mSourceImage != null && mSourceImage.IsDependentOn(theOtherObject)) { return(true); } if (mImageToMark != null && mImageToMark.IsDependentOn(theOtherObject)) { return(true); } if (mCenterX != null && mCenterX.IsDependentOn(theOtherObject)) { return(true); } if (mCenterY != null && mCenterY.IsDependentOn(theOtherObject)) { return(true); } if (mOuterSearchRadius != null && mOuterSearchRadius.IsDependentOn(theOtherObject)) { return(true); } if (mInnerSearchRadius != null && mInnerSearchRadius.IsDependentOn(theOtherObject)) { return(true); } return(base.IsDependentOn(theOtherObject)); }
public override bool IsDependentOn(IObjectDefinition theOtherObject) { return((theOtherObject == this) || (mReferencePoint_X != null && mReferencePoint_X.IsDependentOn(theOtherObject)) || (mReferencePoint_Y != null && mReferencePoint_Y.IsDependentOn(theOtherObject)) || base.IsDependentOn(theOtherObject)); }
/// <summary> /// Checks the class to see if it is a candidate to be a <see cref="ConfigurationAttribute"/> source. /// </summary> /// <param name="objectDefinition">The object definition.</param> /// <returns></returns> public static bool CheckConfigurationClassCandidate(IObjectDefinition objectDefinition) { Type objectType = null; if (objectDefinition is AbstractObjectDefinition) { AbstractObjectDefinition definition = (AbstractObjectDefinition)objectDefinition; if (definition.HasObjectType) { objectType = definition.ObjectType; } else { if (definition.ObjectTypeName != null) { objectType = TypeResolutionUtils.ResolveType(definition.ObjectTypeName); } } if (objectType != null) { if (Attribute.GetCustomAttribute(objectType, typeof(ConfigurationAttribute)) != null) { return true; } if (Attribute.GetCustomAttribute(objectType, typeof(ComponentAttribute)) != null || HasAttributeOnMethods(objectType, typeof(DefinitionAttribute))) { return true; } } } return false; }
/// <summary> /// Creates a new instance of the /// <see cref="ObjectDefinitionHolder"/> class. /// </summary> /// <param name="definition"> /// The object definition to be held by this instance. /// </param> /// <param name="name">The name of the object.</param> /// <param name="aliases"> /// Any aliases for the supplied <paramref name="definition"/> /// </param> public ObjectDefinitionHolder( IObjectDefinition definition, string name, IList <string> aliases) { this.objectDefinition = definition; this.objectName = name; this.aliases = aliases ?? new List <string>(0); }
/// <summary> /// Configures the <see paramref="app"/> instance and its modules. /// </summary> /// <remarks> /// When called, configures <see paramref="app"/> using the <see cref="IApplicationContext"/> instance /// provided in <paramref name="appContext"/> and the templates available in /// <see cref="ApplicationTemplate"/> and <see cref="ModuleTemplates"/>. /// </remarks> /// <param name="appContext">the application context instance to be used for resolving object references.</param> /// <param name="app">the <see cref="HttpApplication"/> instance to be configured.</param> public static void Configure(IConfigurableApplicationContext appContext, HttpApplication app) { IObjectDefinition applicationDefinition = s_applicationDefinition; if (s_applicationDefinition != null) { appContext.ObjectFactory.ConfigureObject(app, "ApplicationTemplate", applicationDefinition); } lock (s_moduleDefinitions.SyncRoot) { HttpModuleCollection modules = app.Modules; foreach (DictionaryEntry moduleEntry in s_moduleDefinitions) { string moduleName = (string)moduleEntry.Key; IObjectDefinition od = s_moduleDefinitions[moduleName]; IHttpModule module = modules[moduleName]; if (module != null) { appContext.ObjectFactory.ConfigureObject(module, moduleName, od); } else { throw ConfigurationUtils.CreateConfigurationException(string.Format("failed applying module template '{0}' - no matching module found", moduleName)); } } } }
/// <summary> /// /// </summary> /// <param name="objectDefinition"></param> public static void Register(IObjectDefinition objectDefinition) { if (!ObjectDefinitions.Contains(objectDefinition)) { ObjectDefinitions.Add(objectDefinition); } }
private void EnhanceConfigurationClasses(IConfigurableListableObjectFactory objectFactory) { ConfigurationClassEnhancer enhancer = new ConfigurationClassEnhancer(objectFactory); IList <string> objectNames = objectFactory.GetObjectDefinitionNames(); foreach (string name in objectNames) { IObjectDefinition objDef = objectFactory.GetObjectDefinition(name); if (((AbstractObjectDefinition)objDef).HasObjectType) { if (Attribute.GetCustomAttribute(objDef.ObjectType, typeof(ConfigurationAttribute)) != null) { //TODO check type of object isn't infrastructure type. Type configClass = objDef.ObjectType; Type enhancedClass = enhancer.Enhance(configClass); Logger.Debug(m => m("Replacing object definition '{0}' existing class '{1}' with enhanced class", name, configClass.FullName)); ((IConfigurableObjectDefinition)objDef).ObjectType = enhancedClass; } } } }
public void Add(string key, IObjectDefinition value) { lock (SyncRoot) { base[key] = value; } }
public override void Scaffold(IObjectDefinition objectDefinition, string outputDirectory, string subdirectory = "") { var codeBuilder = default(ICodeBuilder); var selection = objectDefinition.DbObject == null?this.GlobalSelection() : this.GetSelection(objectDefinition.DbObject); if (objectDefinition is CSharpClassDefinition) { codeBuilder = new CSharpClassBuilder { OutputDirectory = outputDirectory, ForceOverwrite = selection.Settings.ForceOverwrite, ObjectDefinition = objectDefinition }; } else if (objectDefinition is CSharpInterfaceDefinition) { codeBuilder = new CSharpInterfaceBuilder { OutputDirectory = outputDirectory, ForceOverwrite = selection.Settings.ForceOverwrite, ObjectDefinition = objectDefinition }; } OnScaffoldingDefinition(new ScaffoldingDefinitionEventArgs(Logger, codeBuilder)); codeBuilder.CreateFile(subdirectory: subdirectory); OnScaffoldedDefinition(new ScaffoldedDefinitionEventArgs(Logger, codeBuilder)); }
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is string) { NetworkCamera namedCamera; try { string cameraName = (string)value; if (context.Instance is IObjectDefinition) { IObjectDefinition objectBeingEditted = (IObjectDefinition)context.Instance; namedCamera = objectBeingEditted.Project().FindCamera(cameraName); } else if (context.Instance is FavoriteSettings) { namedCamera = ((FavoriteSettings)context.Instance).mTestSequence.project().FindCamera(cameraName); } else { throw new ArgumentException("alksdjaqwhkajlkaj"); } } catch { throw new ArgumentException("Can not convert '" + (string)value + "' to a camera"); } return(namedCamera); } return(base.ConvertFrom(context, culture, value)); }
/// <summary> /// Apply the given properties to the supplied /// <see cref="Spring.Objects.Factory.Config.IConfigurableListableObjectFactory"/>. /// </summary> /// <param name="factory"> /// The <see cref="Spring.Objects.Factory.Config.IConfigurableListableObjectFactory"/> /// used by the application context. /// </param> /// <param name="props">The properties to apply.</param> /// <exception cref="Spring.Objects.ObjectsException"> /// If an error occured. /// </exception> protected override void ProcessProperties(IConfigurableListableObjectFactory factory, NameValueCollection props) { PlaceholderResolveHandlerAdapter resolveAdapter = new PlaceholderResolveHandlerAdapter(this, props); ObjectDefinitionVisitor visitor = new ObjectDefinitionVisitor(resolveAdapter.ParseAndResolveVariables); IList <string> objectDefinitionNames = factory.GetObjectDefinitionNames(includeAncestors); for (int i = 0; i < objectDefinitionNames.Count; ++i) { string name = objectDefinitionNames[i]; IObjectDefinition definition = factory.GetObjectDefinition(name, includeAncestors); if (definition == null) { logger.ErrorFormat("'{0}' can't be found in factorys' '{1}' object definition (includeAncestor {2})", name, factory, includeAncestors); continue; } try { visitor.VisitObjectDefinition(definition); } catch (ObjectDefinitionStoreException ex) { throw new ObjectDefinitionStoreException( definition.ResourceDescription, name, ex.Message); } } factory.AddEmbeddedValueResolver(resolveAdapter); }
/// <summary> /// Apply the property replacement using the specified <see cref="IVariableSource"/>s for all /// object in the supplied /// <see cref="Spring.Objects.Factory.Config.IConfigurableListableObjectFactory"/>. /// </summary> /// <param name="factory"> /// The <see cref="Spring.Objects.Factory.Config.IConfigurableListableObjectFactory"/> /// used by the application context. /// </param> /// <exception cref="Spring.Objects.ObjectsException"> /// If an error occured. /// </exception> protected virtual void ProcessProperties(IConfigurableListableObjectFactory factory) { CompositeVariableSource compositeVariableSource = new CompositeVariableSource(variableSourceList); TextProcessor tp = new TextProcessor(this, compositeVariableSource); ObjectDefinitionVisitor visitor = new ObjectDefinitionVisitor(new ObjectDefinitionVisitor.ResolveHandler(tp.ParseAndResolveVariables)); var objectDefinitionNames = factory.GetObjectDefinitionNames(includeAncestors); for (int i = 0; i < objectDefinitionNames.Count; ++i) { string name = objectDefinitionNames[i]; IObjectDefinition definition = factory.GetObjectDefinition(name, includeAncestors); if (definition == null) { continue; } try { visitor.VisitObjectDefinition(definition); } catch (ObjectDefinitionStoreException ex) { throw new ObjectDefinitionStoreException( definition.ResourceDescription, name, ex.Message); } } }
/// <summary> /// Return the registered /// <see cref="Spring.Objects.Factory.Config.IObjectDefinition"/> for the /// given object, allowing access to its property values and constructor /// argument values. /// </summary> /// <param name="name">The name of the object.</param> /// <param name="includeAncestors">Whether to search parent object factories.</param> /// <returns> /// The registered <see cref="Spring.Objects.Factory.Config.IObjectDefinition"/>, /// or <c>null</c>, if specified object definitions does not exist. /// </returns> /// <exception cref="System.ArgumentException"> /// If <paramref name="name"/> is <c>null</c> or empty string. /// </exception> /// <seealso cref="IConfigurableListableObjectFactory.GetObjectDefinition(string)"/> public override IObjectDefinition GetObjectDefinition(string name, bool includeAncestors) { if (StringUtils.IsNullOrEmpty(name)) { throw new ArgumentException( "Cannot get an object definition with a null or zero length object name string."); } name = TransformedObjectName(name); IObjectDefinition definition = (IObjectDefinition)objectDefinitionMap[name]; if (definition == null) { if (!includeAncestors || ParentObjectFactory == null) { return(null); } else if (ParentObjectFactory is AbstractObjectFactory) { definition = ((AbstractObjectFactory)ParentObjectFactory).GetObjectDefinition(name, includeAncestors); } } return(definition); }
/// <summary> /// Uses reflection to generate Metadata from the in-memory entities. /// </summary> /// <param name="entityType">The entity type from which to create metadata.</param> /// <param name="shouldGetFields">Whether or not this method should get the entity's fields.</param> /// <returns>A single IObjectDefinition that represents the entity</returns> private IObjectDefinition GetObjectDefinition(Type entityType, bool shouldGetFields) { IObjectDefinition objectDefinition = null; objectDefinition = new ObjectDefinition { Name = entityType.Name, FullName = entityType.Name, Description = string.Empty, Hidden = false, RelationshipDefinitions = new List <IRelationshipDefinition>(), PropertyDefinitions = new List <IPropertyDefinition>(), SupportedActionFullNames = new List <string>() }; objectDefinition.SupportedActionFullNames.Add("Query"); if (entityType.Name == "Registrant") { /* If we're building the 'Registrant' metadata * add the 'Create' action to it. * Other entities do not support create. */ objectDefinition.SupportedActionFullNames.Add("Create"); } if (shouldGetFields) { objectDefinition.PropertyDefinitions = GetFieldDefinitions(entityType); } return(objectDefinition); }
/// <summary> /// Retrieves a single ObjectDefinition, by name. /// </summary> /// <param name="objectName"></param> /// <param name="shouldGetProperties"></param> /// <param name="shouldGetRelations"></param> /// <returns></returns> public IObjectDefinition RetrieveObjectDefinition(string objectName, bool shouldGetProperties = false, bool shouldGetRelations = false) { //GoToWebinar doesn't have any entities with parent/child relationships. //As such, we're not using the 'shouldGetRelations' parameter IObjectDefinition objectDefinition = null; using (LogMethodExecution logger = new LogMethodExecution("Rest CDK Example", "RetrieveObjectDefinition")) { //extract the one type that Scribe Online is asking for: if (EntityCollection.Count > 0) { foreach (var keyValuePair in EntityCollection) { if (keyValuePair.Key == objectName) { Type entityType = keyValuePair.Value; if (entityType != null) { //hand the type down to our reflection method and create an IObjectDefiniton for Scribe Online objectDefinition = GetObjectDefinition(entityType, shouldGetProperties); } } } } } return(objectDefinition); }
public T Get <T>(string entityName, string id) where T : class { if (!AppCore.AppSingleton.ObjectDefinitions.ContainsKey(entityName)) { Debug.Assert(false, "Unimplemented entity [" + entityName + "]"); } IObjectDefinition od = AppCore.AppSingleton.ObjectDefinitions[entityName]; string tableName = string.Format("[{0}]", od.TableName); string fileds = string.Join(",", od.Attributes.Values.Select(a => string.Format("[{0}]", a.Column)).ToArray()); string criterion = string.Format("[{0}] = @{0}", od.PrimaryKey.Column); string sqlContext = string.Format("select {0} from {1} where {2}", fileds, tableName, criterion); _cmd.CommandText = sqlContext; _cmd.Parameters.Clear(); _cmd.Parameters.Add("@" + od.PrimaryKey.Column, OleDbType.VarWChar, od.PrimaryKey.Length.GetValueOrDefault(50)).Value = id; T rel = null; using (OleDbDataReader reader = _cmd.ExecuteReader()) { if (reader != null) { if (reader.HasRows) { reader.Read(); rel = EntityReader.Read <T>(reader, entityName); reader.Close(); } } } return(rel); }
public T Delete <T>(string entityName, T instance) where T : class { if (instance == null) { throw new ArgumentNullException("instance"); } if (!AppCore.AppSingleton.ObjectDefinitions.ContainsKey(entityName)) { Debug.Assert(false, "Unimplemented entity [" + entityName + "]"); } IObjectDefinition od = AppCore.AppSingleton.ObjectDefinitions[entityName]; string table = od.TableName; string criterion = string.Format("[{0}]=@{0}", od.PrimaryKey.Column); string sqlContext = string.Format("delete from [{0}] where {1}", table, criterion); _cmd.CommandText = sqlContext; _cmd.Parameters.Clear(); _cmd.Parameters.Add("@" + od.PrimaryKey.Column, od.PrimaryKey.DataType, od.PrimaryKey.Length.GetValueOrDefault(50)). Value = (instance as IBaseObject).ID; int affectrRows = _cmd.ExecuteNonQuery(); if (affectrRows != 1) { throw new Exception("fails to update instance of entity " + entityName); } return(instance); }
public override bool IsDependentOn(IObjectDefinition theOtherObject) { if (theOtherObject == this) { return(true); } if (mSourceImage != null && mSourceImage.IsDependentOn(theOtherObject)) { return(true); } if (mROI != null && mROI.IsDependentOn(theOtherObject)) { return(true); } if (mVariationThreshhold != null && mVariationThreshhold.IsDependentOn(theOtherObject)) { return(true); } if (mSloppiness != null && mSloppiness.IsDependentOn(theOtherObject)) { return(true); } if (mBrightPixelFactor != null && mBrightPixelFactor.IsDependentOn(theOtherObject)) { return(true); } if (mDarkPixelFactor != null && mDarkPixelFactor.IsDependentOn(theOtherObject)) { return(true); } return(base.IsDependentOn(theOtherObject)); }
/// <summary>The parse inner object definition.</summary> /// <param name="element">The element.</param> /// <param name="parserContext">The parser context.</param> /// <returns>The Spring.Objects.Factory.Config.IObjectDefinition.</returns> public static IObjectDefinition ParseInnerObjectDefinition(XmlElement element, ParserContext parserContext) { // parses out inner object definition for concrete implementation if defined var childElements = element.GetElementsByTagName("object"); IObjectDefinition innerComponentDefinition = null; IConfigurableObjectDefinition inDef = null; if (childElements != null && childElements.Count == 1) { var objectElement = childElements[0] as XmlElement; // var odDelegate = parserContext.GetDelegate(); var odHolder = parserContext.ParserHelper.ParseObjectDefinitionElement(objectElement); // odHolder = odDelegate.DecorateObjectDefinitionIfRequired(objectElement, odHolder); inDef = odHolder.ObjectDefinition as IConfigurableObjectDefinition; var objectName = ObjectDefinitionReaderUtils.GenerateObjectName(inDef, parserContext.Registry); // innerComponentDefinition = new ObjectComponentDefinition(inDef, objectName); parserContext.Registry.RegisterObjectDefinition(objectName, inDef); } var aRef = element.GetAttribute(REF_ATTRIBUTE); AssertUtils.IsTrue( !(!string.IsNullOrWhiteSpace(aRef) && inDef != null), "Ambiguous definition. Inner object " + (inDef == null ? string.Empty : inDef.ObjectTypeName) + " declaration and \"ref\" " + aRef + " are not allowed together." ); return(inDef); }
void Init() { if (initialized) { return; } lock (componentProperties) { foreach (var t in componentProperties.Keys) { var builder = ObjectDefinitionBuilder.RootObjectDefinition(factory, t) .SetAutowireMode(AutoWiringMode.AutoDetect) .SetSingleton(typeHandleLookup[t] == DependencyLifecycle.SingleInstance); componentProperties[t].Configure(builder); IObjectDefinition def = builder.ObjectDefinition; context.RegisterObjectDefinition(t.FullName, def); } } initialized = true; context.Refresh(); }
/// <summary> /// Loads the object definitions from fluent configurations, build the object definition and load it into the spring object registry. /// </summary> /// <param name="listableObjectFactory">The listable object factory.</param> public void LoadObjectDefinitions(IConfigurableListableObjectFactory listableObjectFactory) { var definitionService = new ObjectDefinitionService(_objectDefinitionFactory, listableObjectFactory); foreach (IRegistrableObject registrableObject in _springObjectConfigurations .OfType <IRegistrableObject>() .Select(configurationContainer => (configurationContainer))) { InitialiseConventions(registrableObject); IObjectDefinition objectDefinition = registrableObject.GetObjectDefinition(definitionService); listableObjectFactory.RegisterObjectDefinition(registrableObject.Identifier, objectDefinition); if (FluentStaticConfiguration.RegisterImplementedInterfaces) { foreach (Type @interface in objectDefinition.ObjectType.GetInterfaces()) { if (!listableObjectFactory.ContainsObjectDefinition(@interface.FullName)) { listableObjectFactory.RegisterObjectDefinition(@interface.FullName, objectDefinition); } } } } }
/// <summary> /// Creates a new instance of the /// <see cref="ObjectDefinitionHolder"/> class. /// </summary> /// <param name="definition"> /// The object definition to be held by this instance. /// </param> /// <param name="name">The name of the object.</param> /// <param name="aliases"> /// Any aliases for the supplied <paramref name="definition"/> /// </param> public ObjectDefinitionHolder( IObjectDefinition definition, string name, string[] aliases) { this.objectDefinition = definition; this.objectName = name; this.aliases = aliases == null ? StringUtils.EmptyStrings : aliases; }
/// <summary> /// Resolve a reference to another object in the factory. /// </summary> /// <param name="name"> /// The name of the object that is having the value of one of its properties resolved. /// </param> /// <param name="definition"> /// The definition of the named object. /// </param> /// <param name="argumentName"> /// The name of the property the value of which is being resolved. /// </param> /// <param name="reference"> /// The runtime reference containing the value of the property. /// </param> /// <returns>A reference to another object in the factory.</returns> protected virtual object ResolveReference(IObjectDefinition definition, string name, string argumentName, RuntimeObjectReference reference) { #region Instrumentation if (log.IsDebugEnabled) { log.Debug( string.Format(CultureInfo.InvariantCulture, "Resolving reference from property '{0}' in object '{1}' to object '{2}'.", argumentName, name, reference.ObjectName)); } #endregion try { if (reference.IsToParent) { if (null == objectFactory.ParentObjectFactory) { throw new ObjectCreationException(definition.ResourceDescription, name, string.Format( "Can't resolve reference to '{0}' in parent factory: " + "no parent factory available.", reference.ObjectName)); } return(objectFactory.ParentObjectFactory.GetObject(reference.ObjectName)); } return(objectFactory.GetObject(reference.ObjectName)); } catch (ObjectsException ex) { throw ObjectCreationException.GetObjectCreationException(ex, name, argumentName, definition.ResourceDescription, reference.ObjectName); } }
/// <summary> /// TODO: we may want a static implementation of this in case there are IObjectDefinition classes that don't inherit from ObjectDefinition. This may apply to all methods here. /// TODO: what about properties that aren't of type IObjectDefinition? (e.g. Color, Direction, int, etc) /// </summary> /// <param name="propertyOwner"></param> /// <param name="newPropertyValue"></param> public void HandlePropertyChange(IObjectDefinition propertyOwner, string propertyName, IObjectDefinition originalValue, IObjectDefinition newPropertyValue) { if (originalValue != newPropertyValue) { if (newPropertyValue != null && newPropertyValue.IsDependentOn(propertyOwner)) { throw new ArgumentException("That would create a circular dependency."); } if (TestSequence().FullyInitialized) { NotifyPropertyChanged(propertyName); /* * bool changeIsSignificantToSequenceDefinition = true; * if (this is DataValueDefinition) * { * DataValueDefinition valueDef = (DataValueDefinition)this; * if (valueDef.Category == DataCategory.UnnamedConstant || valueDef.Category == DataCategory.CalculatedValue) * { * changeIsSignificantToSequenceDefinition = false; * } * }*/ if (IncludeObjectInConfigFile()) { TestSequence().Log("Changed " + propertyOwner.Name + "." + propertyName + " from '" + (originalValue == null ? "" : originalValue.Name) + "' to '" + (newPropertyValue == null ? "" : newPropertyValue.Name) + "'"); TestSequence().SetUnsavedChanges(); } TestSequence().SetUnusedChanges(); } } }
/// <summary> /// Given a property value, return a value, resolving any references to other /// objects in the factory if necessary. /// </summary> /// <remarks> /// <p> /// The value could be : /// <list type="bullet"> /// <item> /// <p> /// An <see cref="Spring.Objects.Factory.Config.IObjectDefinition"/>, /// which leads to the creation of a corresponding new object instance. /// Singleton flags and names of such "inner objects" are always ignored: inner objects /// are anonymous prototypes. /// </p> /// </item> /// <item> /// <p> /// A <see cref="Spring.Objects.Factory.Config.RuntimeObjectReference"/>, which must /// be resolved. /// </p> /// </item> /// <item> /// <p> /// An <see cref="Spring.Objects.Factory.Config.IManagedCollection"/>. This is a /// special placeholder collection that may contain /// <see cref="Spring.Objects.Factory.Config.RuntimeObjectReference"/>s or /// collections that will need to be resolved. /// </p> /// </item> /// <item> /// <p> /// An ordinary object or <see langword="null"/>, in which case it's left alone. /// </p> /// </item> /// </list> /// </p> /// </remarks> /// <param name="name"> /// The name of the object that is having the value of one of its properties resolved. /// </param> /// <param name="definition"> /// The definition of the named object. /// </param> /// <param name="argumentName"> /// The name of the property the value of which is being resolved. /// </param> /// <param name="argumentValue"> /// The value of the property that is being resolved. /// </param> public virtual object ResolveValueIfNecessary(string name, IObjectDefinition definition, string argumentName, object argumentValue) { object resolvedValue = null; resolvedValue = ResolvePropertyValue(name, definition, argumentName, argumentValue); return(resolvedValue); }
/// <summary> /// Checks the class to see if it is a candidate to be a <see cref="ConfigurationAttribute"/> source. /// </summary> /// <param name="objectDefinition">The object definition.</param> /// <returns></returns> public static bool CheckConfigurationClassCandidate(IObjectDefinition objectDefinition) { Type objectType = null; if (objectDefinition is AbstractObjectDefinition) { AbstractObjectDefinition definition = (AbstractObjectDefinition)objectDefinition; if (definition.HasObjectType) { objectType = definition.ObjectType; } else { if (definition.ObjectTypeName != null && !definition.IsAbstract) { objectType = TypeResolutionUtils.ResolveType(definition.ObjectTypeName); } } if (objectType != null) { if (Attribute.GetCustomAttribute(objectType, typeof(ConfigurationAttribute)) != null) { return(true); } if (Attribute.GetCustomAttribute(objectType, typeof(ComponentAttribute)) != null || HasAttributeOnMethods(objectType, typeof(ObjectDefAttribute))) { return(true); } } } return(false); }
public override bool IsDependentOn(IObjectDefinition theOtherObject) { if (theOtherObject == this) { return(true); } if (mSourceImage != null && mSourceImage.IsDependentOn(theOtherObject)) { return(true); } if (mSearchPath != null && mSearchPath.IsDependentOn(theOtherObject)) { return(true); } if (mSearchSpeed != null && mSearchSpeed.IsDependentOn(theOtherObject)) { return(true); } if (mRequiredConsecutiveColorMatches != null && mRequiredConsecutiveColorMatches.IsDependentOn(theOtherObject)) { return(true); } if (mSearchBackgroundColorDefinition != null && mSearchBackgroundColorDefinition.IsDependentOn(theOtherObject)) { return(true); } if (mObjectColorDefinition != null && mObjectColorDefinition.IsDependentOn(theOtherObject)) { return(true); } return(base.IsDependentOn(theOtherObject)); }
/// <summary> /// Registers the name of the with generated. /// </summary> /// <param name="objectDefinition">The object definition.</param> /// <returns>the generated object name</returns> public string RegisterWithGeneratedName(IObjectDefinition objectDefinition) { string generatedName = GenerateObjectName(objectDefinition); Registry.RegisterObjectDefinition(generatedName, objectDefinition); return(generatedName); }
public T Update <T>(string entityName, T instance) where T : class { if (instance == null) { throw new ArgumentNullException("instance"); } IDictionary <IAttributeDefinition, object> changes = EntityChecker.Check(entityName, instance as IBaseObject); if (changes.Count == 0) { return(instance); } if (!AppCore.AppSingleton.ObjectDefinitions.ContainsKey(entityName)) { Debug.Assert(false, "Unimplemented entity [" + entityName + "]"); } IObjectDefinition od = AppCore.AppSingleton.ObjectDefinitions[entityName]; string table = od.TableName; string fields = string.Join(",", changes.Keys.Select(a => string.Format("[{0}]=@{0}", a.Column)).ToArray()); string criterion = string.Format("[{0}]=@orgID", od.PrimaryKey.Column); string sqlContext = string.Format("update [{0}] set {1} where {2}", table, fields, criterion); _cmd.CommandText = sqlContext; _cmd.Parameters.Clear(); foreach (IAttributeDefinition attr in changes.Keys) { var para = new OleDbParameter("@" + attr.Column, attr.DataType); if (attr.Length.HasValue) { para.Size = attr.Length.Value; } para.Value = changes[attr] ?? DBNull.Value; para.IsNullable = !attr.IsRequired; _cmd.Parameters.Add(para); } if (!(instance is IBaseObjectProxy)) { Debug.Assert(false, "The given instance is not proxy type."); } _cmd.Parameters.Add("@orgID", od.PrimaryKey.DataType, od.PrimaryKey.Length.GetValueOrDefault(50)). Value = (instance as IBaseObjectProxy).Original.ID; int affectrRows = _cmd.ExecuteNonQuery(); if (affectrRows != 1) { throw new Exception("fails to update instance of entity " + entityName); } return(EntityUpdater.Update(this, entityName, instance, changes)); }
private static string ParseChild(XmlElement element, ParserContext parserContext, IObjectDefinition parentDefinition) { IObjectDefinition def = parserContext.ParserHelper.ParseCustomElement(element, parentDefinition); if(def == null) { parserContext.ReaderContext.ReportException(element, element.Name, "child ObjectDefinition must not be null"); } return parserContext.ReaderContext.RegisterWithGeneratedName(def); }
protected static IDictionary<string, IAttributeDefinition> CreateCollectionAttributes(IObjectDefinition od) { IDictionary<string, IAttributeDefinition> attrs = new Dictionary<string,IAttributeDefinition>(); attrs.Add("ID",new AttributeDefinition(od, "ID", "业务单号", "busnum", OleDbType.VarWChar, 20, 0, true)); attrs.Add("CustomerName",new AttributeDefinition(od, "CustomerName", "客户姓名", "clientname", OleDbType.VarWChar, 10, 1, false, true)); attrs.Add("Value",new AttributeDefinition(od, "Value", "收款金额", "moneys", OleDbType.VarWChar, 10, 2)); attrs.Add("Offset",new AttributeDefinition(od, "Offset", "退补金额", "moneyt", OleDbType.VarWChar, 10, 3)); return attrs; }
/// <summary> /// Creates a new <see cref="GenericObjectDefinition"/> as deep copy of the given /// object definition. /// </summary> /// <param name="original">the original object definition to copy from</param> public GenericObjectDefinition(IObjectDefinition original) : base(original) { GenericObjectDefinition god = original as GenericObjectDefinition; if (god != null) { this.parentName = god.parentName; } }
/// <summary> /// Generates an object name for the given object definition. /// </summary> /// <param name="definition">The object definition to generate a name for.</param> /// <param name="registry">The object definitions registry that the given definition is /// supposed to be registerd with</param> /// <returns> /// the generated object name /// </returns> public string GenerateObjectName(IObjectDefinition definition, IObjectDefinitionRegistry registry) { if (definition is ScannedGenericObjectDefinition) { string objectName = ((ScannedGenericObjectDefinition) definition).ComponentName; if (!string.IsNullOrEmpty(objectName)) return objectName; } return BuildDefaultObjectName(definition); }
protected static IDictionary<string, IAttributeDefinition> CreateCustomerAttributes(IObjectDefinition od) { IDictionary<string, IAttributeDefinition> attrs = new Dictionary<string,IAttributeDefinition>(); attrs.Add("ID", new AttributeDefinition(od,"ID", "客户身份证号", "clientnum",OleDbType.VarWChar, 20, 0,true)); attrs.Add("Name", new AttributeDefinition(od, "Name", "客户姓名", "clientname", OleDbType.VarWChar, 10, 1,true)); attrs.Add("Sex", new AttributeDefinition(od, "Sex", "客户性别", "clientsex", OleDbType.VarWChar, 10, 2)); attrs.Add("Phone", new AttributeDefinition(od, "Phone", "联系电话", "clientphone", OleDbType.VarWChar, 20, 3)); attrs.Add("Address", new AttributeDefinition(od, "Address", "收件地址", "clientaddress", OleDbType.VarWChar, 225, 4)); return attrs; }
protected override object ResolveDependency(string objectName, IObjectDefinition objectDefinition, IObjectWrapper objectWrapper, PropertyInfo propertyInfo) { if (!propertyInfo.PropertyType.IsInterface) { return null; } Type mockType = typeof(Mock).MakeGenericType(propertyInfo.PropertyType); Mock mock = (Mock)Activator.CreateInstance(mockType, defaultMockBehavior); return mock.Object; }
public string GenerateObjectName(IObjectDefinition definition, IObjectDefinitionRegistry registry) { var objectDefinition = definition as ScannedGenericObjectDefinition; if (objectDefinition != null) { string componentName = objectDefinition.ComponentName; if (!string.IsNullOrEmpty(componentName)) return componentName; } return BuildDefaultObjectName(definition); }
/// <summary> /// Generates an object name for the given object definition. /// </summary> /// <param name="definition">The object definition to generate a name for.</param> /// <param name="registry">The object definitions registry that the given definition is /// supposed to be registerd with</param> /// <returns>the generated object name</returns> public string GenerateObjectName(IObjectDefinition definition, IObjectDefinitionRegistry registry) { IConfigurableObjectDefinition objectDef = definition as IConfigurableObjectDefinition; if (objectDef == null) { throw new ArgumentException( "DefaultObjectNameGenerator is only able to handle IConfigurableObjectDefinition subclasses: " + definition); } return ObjectDefinitionReaderUtils.GenerateObjectName(objectDef, registry); }
protected static IDictionary<string, IAttributeDefinition> CreateCaseAttributes(IObjectDefinition od) { IDictionary<string, IAttributeDefinition> attrs = new Dictionary<string,IAttributeDefinition>(); attrs.Add("ID", new AttributeDefinition(od, "ID", "业务单号", "busnum", OleDbType.VarWChar, 20, 0, true)); attrs.Add("AppType", new AttributeDefinition(od, "AppType", "业务类别", "busstyle", OleDbType.VarWChar, 10, 1, false, true)); attrs.Add("CustomerName", new AttributeDefinition(od, "CustomerName", "客户姓名", "clientname", OleDbType.VarWChar, 10, 2, false, true)); attrs.Add("CustomerID", new AttributeDefinition(od, "CustomerID", "客户身份证号", "clientnum", OleDbType.VarWChar, 20, 3, false, true)); attrs.Add("Region", new AttributeDefinition(od, "Region", "申请国家", "applycountry", OleDbType.VarWChar, 10, 4, false, true)); attrs.Add("Type", new AttributeDefinition(od, "Type", "问题案类型", "prostyle", OleDbType.VarWChar, 10, 5)); attrs.Add("Text", new AttributeDefinition(od, "Text", "问题案信息", "protext", OleDbType.VarWChar, 255, 6)); return attrs; }
/// <summary> /// Traverse the given ObjectDefinition object and the MutablePropertyValues /// and ConstructorArgumentValues contained in them. /// </summary> /// <param name="definition">The object definition to traverse.</param> public virtual void VisitObjectDefinition(IObjectDefinition definition) { VisitObjectTypeName(definition); VisitPropertyValues(definition); ConstructorArgumentValues cas = definition.ConstructorArgumentValues; if (cas != null) { VisitIndexedArgumentValues(cas.IndexedArgumentValues); VisitNamedArgumentValues(cas.NamedArgumentValues); VisitGenericArgumentValues(cas.GenericArgumentValues); } }
public AttributeDefinition(IObjectDefinition od, string name, string label, string column, OleDbType type, int? length, int orderIndex, bool isRequired, bool isReadOnly) { Name = name; Label = label; Column = column; DataType = type; Length = length; OrderIndex = orderIndex; IsRequired = isRequired; ForObject = od; IsReadOnly = isReadOnly; ShowInList = true; }
protected static IDictionary<string, IAttributeDefinition> CreateApplicationAttributes(IObjectDefinition od) { IDictionary<string, IAttributeDefinition> attrs = new Dictionary<string,IAttributeDefinition>(); attrs.Add("ID", new AttributeDefinition(od, "ID", "业务单号", "busnum", OleDbType.VarWChar, 20, 0, true)); attrs.Add("Type", new AttributeDefinition(od, "Type", "业务类别", "busstyle", OleDbType.VarWChar, 10, 1,false,true)); attrs.Add("SubType", new AttributeDefinition(od, "SubType", "数量", "buscount", OleDbType.VarWChar, 10, 2, false, true)); attrs.Add("CustomerName", new AttributeDefinition(od, "CustomerName", "客户姓名", "clientname", OleDbType.VarWChar, 10, 3,false,true)); attrs.Add("CustomerSex", new AttributeDefinition(od, "CustomerSex", "客户性别", "clientsex", OleDbType.VarWChar, 10, 4,false,true)); attrs.Add("CustomerID", new AttributeDefinition(od, "CustomerID", "客户身份证号", "clientnum", OleDbType.VarWChar, 20, 5)); attrs.Add("Region", new AttributeDefinition(od, "Region", "申请国家", "applycountry", OleDbType.VarWChar, 10, 6)); attrs.Add("DateApplied", new AttributeDefinition(od, "DateApplied", "申请日期", "applydate", OleDbType.Date, 10, 7)); attrs.Add("DateTraved", new AttributeDefinition(od, "DateTraved", "启程日期", "traveldate", OleDbType.Date, 20, 8) { ShowInList = false }); attrs.Add("OffNoteNo", new AttributeDefinition(od, "OffNoteNo", "照会号", "offnotenum", OleDbType.VarWChar, 10, 9) { ShowInList = false }); attrs.Add("OffNoteDate", new AttributeDefinition(od, "OffNoteDate", "照会日期", "offnotedate", OleDbType.Date, 20, 10) { ShowInList = false }); attrs.Add("Remark", new AttributeDefinition(od, "Remark", "材料说明", "remark", OleDbType.VarWChar, 255, 11) { ShowInList = false }); return attrs; }
public static IDictionary<string, IAttributeDefinition> CreateAttributes(string entityName, IObjectDefinition od) { switch (entityName) { case "Application": return CreateApplicationAttributes(od); case "Customer": return CreateCustomerAttributes(od); case "Case": return CreateCaseAttributes(od); case "Collection": return CreateCollectionAttributes(od); case "Status": return CreateStatusAttributes(od); case "User": return CreateUserAttributes(od); default: Debug.Assert(false,"Encounter an unknown object type "+entityName); return new Dictionary<string,IAttributeDefinition>(); } }
// CLOVER:ON #endregion /// <summary> /// Gets those <see cref="System.Reflection.ConstructorInfo"/>s /// that are applicable for autowiring the supplied <paramref name="definition"/>. /// </summary> /// <param name="definition"> /// The <see cref="Spring.Objects.Factory.Config.IObjectDefinition"/> /// (definition) that is being autowired by constructor. /// </param> /// <param name="minimumArgumentCount"> /// The absolute minimum number of arguments that any returned constructor /// must have. If this parameter is equal to zero (0), then all constructors /// are valid (regardless of their argument count), including any default /// constructor. /// </param> /// <returns> /// Those <see cref="System.Reflection.ConstructorInfo"/>s /// that are applicable for autowiring the supplied <paramref name="definition"/>. /// </returns> public static ConstructorInfo[] GetConstructors( IObjectDefinition definition, int minimumArgumentCount) { const BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly; ConstructorInfo[] constructors = null; if (minimumArgumentCount > 0) { MemberInfo[] ctors = definition.ObjectType.FindMembers( MemberTypes.Constructor, flags, new MemberFilter(new CriteriaMemberFilter().FilterMemberByCriteria), new MinimumArgumentCountCriteria(minimumArgumentCount)); constructors = (ConstructorInfo[]) ArrayList.Adapter(ctors).ToArray(typeof (ConstructorInfo)); } else { constructors = definition.ObjectType.GetConstructors(flags); } AutowireUtils.SortConstructors(constructors); return constructors; }
protected override string PostProcessObjectNameAndAliases(string objectName, List<string> aliases, XmlElement element, IObjectDefinition containingDefinition) { string url = element.GetAttribute(ObjectDefinitionConstants.TypeAttribute); string strTypeName = url.ToLower(); if (strTypeName.EndsWith(".aspx")) { if (!StringUtils.HasText(objectName)) { objectName = webObjectNameGenerator.CreatePageDefinitionName(url); } // strip leading homepath symbol ('~') from aliases if necessary for (int ai = 0; ai < aliases.Count; ai++) { string alias = (string)aliases[ai]; if (alias != null && alias.Length > 0 && alias[0] == '~') { aliases[ai] = "/" + alias.Substring(1).TrimStart('/', '\\'); } } } else if (strTypeName.EndsWith(".ascx") || strTypeName.EndsWith(".master")) { string controlName = webObjectNameGenerator.CreateControlDefinitionName(url); if (!StringUtils.HasText(objectName)) { objectName = controlName; } else { aliases.Add(controlName); } } return objectName; }
protected abstract object ResolveDependency(string objectName, IObjectDefinition objectDefinition, IObjectWrapper objectWrapper, PropertyInfo propertyInfo);
/// <summary> /// Visits the property values of the ObjectDefinition, replacing string values /// using the specified IVariableSource. /// </summary> /// <param name="objectDefinition">The object definition.</param> protected virtual void VisitPropertyValues(IObjectDefinition objectDefinition) { MutablePropertyValues pvs = objectDefinition.PropertyValues; if (pvs != null) { for (int j = 0; j < pvs.PropertyValues.Length; j++) { PropertyValue pv = pvs.PropertyValues[j]; object newVal = ResolveValue(pv.Value); if (!ObjectUtils.NullSafeEquals(newVal, pv.Value)) { pvs.Add(pv.Name, newVal); } } } }
/// <summary> /// Visits the ObjectDefinition property ObjectTypeName, replacing string values using /// the specified IVariableSource. /// </summary> /// <param name="objectDefinition">The object definition.</param> protected virtual void VisitObjectTypeName(IObjectDefinition objectDefinition) { string objectTypeName = objectDefinition.ObjectTypeName; if (objectTypeName != null) { string resolvedName = ResolveStringValue(objectTypeName); if (!objectTypeName.Equals(resolvedName)) { objectDefinition.ObjectTypeName = resolvedName; } } }
/// <summary> /// Override settings in this object definition from the supplied /// <paramref name="other"/> object definition. /// </summary> /// <param name="other"> /// The object definition used to override the member fields of this instance. /// </param> public virtual void OverrideFrom(IObjectDefinition other) { AssertUtils.ArgumentNotNull(other, "other"); IsAbstract = other.IsAbstract; Scope = other.Scope; IsLazyInit = other.IsLazyInit; ConstructorArgumentValues.AddAll(other.ConstructorArgumentValues); PropertyValues.AddAll(other.PropertyValues.PropertyValues); EventHandlerValues.AddAll(other.EventHandlerValues); if (StringUtils.HasText(other.ObjectTypeName)) { ObjectTypeName = other.ObjectTypeName; } if (StringUtils.HasText(other.InitMethodName)) { InitMethodName = other.InitMethodName; } if (StringUtils.HasText(other.DestroyMethodName)) { DestroyMethodName = other.DestroyMethodName; } if (StringUtils.HasText(other.FactoryObjectName)) { FactoryObjectName = other.FactoryObjectName; } if (StringUtils.HasText(other.FactoryMethodName)) { FactoryMethodName = other.FactoryMethodName; } if (ArrayUtils.HasLength(other.DependsOn)) { ArrayList deps = new ArrayList(other.DependsOn); if (ArrayUtils.HasLength(DependsOn)) { deps.AddRange(DependsOn); } DependsOn = (string[]) deps.ToArray(typeof(string)); } AutowireMode = other.AutowireMode; ResourceDescription = other.ResourceDescription; AbstractObjectDefinition aod = other as AbstractObjectDefinition; if (aod != null) { if (aod.HasObjectType) { ObjectType = other.ObjectType; } MethodOverrides.AddAll(aod.MethodOverrides); DependencyCheck = aod.DependencyCheck; } }
/// <summary> /// Allows deriving classes to post process the name and aliases for the current element. By default /// does nothing and returns the unmodified <paramref name="objectName"/>. /// </summary> /// <remarks> /// The <paramref name="aliases"/> list passed in may be modified by an implementation of this method to reflect special needs. /// </remarks> /// <param name="objectName">the object name obtained by the default algorithm from 'id' and 'name' attributes so far.</param> /// <param name="aliases">the object aliases obtained by the default algorithm from 'name' attribute so far.</param> /// <param name="element">the currently processed element.</param> /// <param name="containingDefinition">the containing object definition, may be <c>null</c></param> /// <returns>the new object name to be used.</returns> protected virtual string PostProcessObjectNameAndAliases(string objectName, List<string> aliases, XmlElement element, IObjectDefinition containingDefinition) { if (!StringUtils.HasText(objectName) && aliases.Count == 0) { string result = this.objectsNamespaceParser.CalculateId(element, aliases); if (result != null) { return result; } } return objectName; }
/// <summary> /// Injects dependencies into the supplied <paramref name="target"/> instance /// using the supplied <paramref name="definition"/>. /// </summary> /// <param name="target"> /// The object instance that is to be so configured. /// </param> /// <param name="name"> /// The name of the object definition expressing the dependencies that are to /// be injected into the supplied <parameref name="target"/> instance. /// </param> /// <param name="definition"> /// An object definition that should be used to configure object. /// </param> /// <seealso cref="Spring.Objects.Factory.IObjectFactory.ConfigureObject(object, string)"/> public object ConfigureObject(object target, string name, IObjectDefinition definition) { return ObjectFactory.ConfigureObject(target, name, definition); }
/// <summary> /// Overrides this object's values using values from <c>other</c> argument. /// </summary> /// <param name="other">The object to copy values from.</param> public override void OverrideFrom(IObjectDefinition other) { base.OverrideFrom(other); if (other is IWebObjectDefinition) { // this._scope = ((IWebObjectDefinition) other).Scope; this._pageName = ((IWebObjectDefinition) other).PageName; } }
/// <summary> /// Creates a new instance of the /// <see cref="Spring.Objects.Factory.Support.RootWebObjectDefinition"/> class /// </summary> /// <param name="other"> /// The definition that is to be copied. /// </param> /// <remarks> /// <p> /// Deep copy constructor. /// </p> /// </remarks> public RootWebObjectDefinition(IObjectDefinition other) : base(other) { if (other is IWebObjectDefinition) { // this._scope = ((IWebObjectDefinition) other).Scope; this._pageName = ((IWebObjectDefinition) other).PageName; } }
/// <summary> /// Parses an element in a custom namespace. /// </summary> /// <param name="ele"></param> /// <param name="containingDefinition">if a nested element, the containing object definition</param> /// <returns>the parsed object definition or null if not supported by the corresponding parser.</returns> public IObjectDefinition ParseCustomElement(XmlElement ele, IObjectDefinition containingDefinition) { String namespaceUri = ele.NamespaceURI; INamespaceParser handler = NamespaceParserRegistry.GetParser(namespaceUri); if (handler == null) { Error("Unable to locate Spring NamespaceHandler for XML schema namespace [" + namespaceUri + "]", ele); return null; } return handler.ParseElement(ele, new ParserContext(this, containingDefinition)); }
/// <summary> /// Parse a standard object definition into a /// <see cref="Spring.Objects.Factory.Config.ObjectDefinitionHolder"/>, /// including object name and aliases. /// </summary> /// <param name="element">The element containing the object definition.</param> /// <param name="containingDefinition">The containing object definition if <paramref name="element"/> is a nested element.</param> /// <returns> /// The parsed object definition wrapped within an /// <see cref="Spring.Objects.Factory.Config.ObjectDefinitionHolder"/> /// instance. /// </returns> /// <remarks> /// <para> /// Object elements specify their canonical name via the "id" attribute /// and their aliases as a delimited "name" attribute. /// </para> /// <para> /// If no "id" is specified, uses the first name in the "name" attribute /// as the canonical name, registering all others as aliases. /// </para> /// </remarks> public ObjectDefinitionHolder ParseObjectDefinitionElement(XmlElement element, IObjectDefinition containingDefinition) { string id = GetAttributeValue(element, ObjectDefinitionConstants.IdAttribute); string nameAttr = GetAttributeValue(element, ObjectDefinitionConstants.NameAttribute); List<string> aliases = new List<string>(); if (StringUtils.HasText(nameAttr)) { aliases.AddRange(GetObjectNames(nameAttr)); } // if we ain't got an id, check if object is page definition or assign any existing (first) alias... string objectName = id; if (StringUtils.IsNullOrEmpty(objectName)) { if (aliases.Count > 0) { objectName = (string) aliases[0]; aliases.RemoveAt(0); if (log.IsDebugEnabled) { log.Debug(string.Format("No XML 'id' specified using '{0}' as object name and '{1}' as aliases", objectName, string.Join(",", aliases.ToArray()))); } } } objectName = PostProcessObjectNameAndAliases(objectName, aliases, element, containingDefinition); if (containingDefinition == null) { CheckNameUniqueness(objectName, aliases, element); } ParserContext parserContext = new ParserContext(this, containingDefinition); IConfigurableObjectDefinition definition = objectsNamespaceParser.ParseObjectDefinitionElement(element, objectName, parserContext); if (definition != null) { if (StringUtils.IsNullOrEmpty(objectName)) { if (containingDefinition != null) { objectName = ObjectDefinitionReaderUtils.GenerateObjectName(definition, readerContext.Registry, true); } else { objectName = readerContext.GenerateObjectName(definition); // Register an alias for the plain object type name, if possible. string objectTypeName = definition.ObjectTypeName; if (objectTypeName != null && objectName.StartsWith(objectTypeName) && objectName.Length>objectTypeName.Length && !readerContext.Registry.IsObjectNameInUse(objectTypeName)) { aliases.Add(objectTypeName); } } #region Instrumentation if (log.IsDebugEnabled) { log.Debug(string.Format( "Neither XML '{0}' nor '{1}' specified - using generated object name [{2}]", ObjectDefinitionConstants.IdAttribute, ObjectDefinitionConstants.NameAttribute, objectName)); } #endregion } return CreateObjectDefinitionHolder(element, definition, objectName, aliases); } return null; }
/// <summary> /// Register a new object definition with this registry. /// </summary> /// <param name="name"> /// The name of the object instance to register. /// </param> /// <param name="objectDefinition"> /// The definition of the object instance to register. /// </param> /// <exception cref="Spring.Objects.ObjectsException"> /// If the object definition is invalid. /// </exception> /// <seealso cref="Spring.Objects.Factory.Support.IObjectDefinitionRegistry.RegisterObjectDefinition(string, IObjectDefinition)"/> public override void RegisterObjectDefinition( string name, IObjectDefinition objectDefinition) { if (objectDefinition is AbstractObjectDefinition) { try { ((AbstractObjectDefinition)objectDefinition).Validate(); } catch (ObjectDefinitionValidationException ex) { throw new ObjectDefinitionStoreException( objectDefinition.ResourceDescription, name, "Validation of object definition failed.", ex); } } object oldObjectDefinition = objectDefinitionMap[name]; if (oldObjectDefinition != null) { if (!AllowObjectDefinitionOverriding) { throw new ObjectDefinitionStoreException( string.Format( "Cannot register object definition [{0}] for object '{1}': there's already [{2}] bound.", objectDefinition, name, oldObjectDefinition)); } else { #region Instrumentation if (log.IsDebugEnabled) { log.Debug( string.Format( "Overriding object definition for object '{0}': replacing [{1}] with [{2}].", name, oldObjectDefinition, objectDefinition)); } #endregion } } else { objectDefinitionNames.Add(name); } objectDefinitionMap[name] = objectDefinition; }
/// <summary> /// Register a new object definition with this registry. /// Must support /// <see cref="Spring.Objects.Factory.Support.RootObjectDefinition"/> /// and <see cref="Spring.Objects.Factory.Support.ChildObjectDefinition"/>. /// </summary> /// <param name="name">The name of the object instance to register.</param> /// <param name="definition">The definition of the object instance to register.</param> /// <remarks> /// <p> /// Must support /// <see cref="Spring.Objects.Factory.Support.RootObjectDefinition"/> and /// <see cref="Spring.Objects.Factory.Support.ChildObjectDefinition"/>. /// </p> /// </remarks> /// <exception cref="Spring.Objects.ObjectsException"> /// If the object definition is invalid. /// </exception> public virtual void RegisterObjectDefinition(string name, IObjectDefinition definition) { ObjectFactory.RegisterObjectDefinition(name, definition); }
/// <summary> /// Creates a new instance of the /// <see cref="Spring.Objects.Factory.Support.AbstractObjectDefinition"/> /// class. /// </summary> /// <param name="other"> /// The object definition used to initialise the member fields of this /// instance. /// </param> /// <remarks> /// <p> /// This is an <see langword="abstract"/> class, and as such exposes no /// public constructors. /// </p> /// </remarks> protected AbstractObjectDefinition(IObjectDefinition other) { AssertUtils.ArgumentNotNull(other, "other"); this.OverrideFrom(other); AbstractObjectDefinition aod = other as AbstractObjectDefinition; if (aod != null) { if (aod.HasObjectType) { ObjectType = other.ObjectType; } else { ObjectTypeName = other.ObjectTypeName; } MethodOverrides = new MethodOverrides(aod.MethodOverrides); DependencyCheck = aod.DependencyCheck; } ParentName = other.ParentName; IsAbstract = other.IsAbstract; // IsSingleton = other.IsSingleton; Scope = other.Scope; Role = other.Role; IsLazyInit = other.IsLazyInit; ConstructorArgumentValues = new ConstructorArgumentValues(other.ConstructorArgumentValues); PropertyValues = new MutablePropertyValues(other.PropertyValues); EventHandlerValues = new EventValues(other.EventHandlerValues); InitMethodName = other.InitMethodName; DestroyMethodName = other.DestroyMethodName; DependsOn = new string[other.DependsOn.Length]; IsAutowireCandidate = other.IsAutowireCandidate; Array.Copy(other.DependsOn, DependsOn, other.DependsOn.Length); FactoryMethodName = other.FactoryMethodName; FactoryObjectName = other.FactoryObjectName; AutowireMode = other.AutowireMode; ResourceDescription = other.ResourceDescription; }