public ObjectDefinitionHolder Decorate(XmlNode node, ObjectDefinitionHolder definition, ParserContext parserContext)
 {
     throw new System.NotImplementedException();
 }
Пример #2
0
        /// <summary>
        /// Parse a standard object definition into a
        /// <see cref="Oragon.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="Oragon.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);
        }
 public IObjectDefinition ParseElement(XmlElement element, ParserContext parserContext)
 {
     throw new System.NotImplementedException();
 }