Exemplo n.º 1
0
        /// <summary>
        /// Process the object element
        /// </summary>
        protected virtual void ProcessObjectDefinition(XmlElement element, ObjectDefinitionParserHelper helper)
        {
            // TODO: add event handling
            try
            {
                ObjectDefinitionHolder bdHolder = helper.ParseObjectDefinitionElement(element);
                if (bdHolder == null)
                {
                    return;
                }
                bdHolder = helper.DecorateObjectDefinitionIfRequired(element, bdHolder);

                #region Instrumentation

                if (log.IsDebugEnabled)
                {
                    log.Debug(string.Format(CultureInfo.InvariantCulture, "Registering object definition with id '{0}'.", bdHolder.ObjectName));
                }

                #endregion

                ObjectDefinitionReaderUtils.RegisterObjectDefinition(bdHolder, ReaderContext.Registry);
                // TODO: Send registration event.
                // ReaderContext.FireComponentRegistered(new BeanComponentDefinition(bdHolder));
            }
            catch (ObjectDefinitionStoreException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new ObjectDefinitionStoreException(
                          string.Format("Failed parsing object definition '{0}'", element.OuterXml), ex);
            }
        }
Exemplo n.º 2
0
 private void ParseDefaultElement(XmlElement element, ObjectDefinitionParserHelper helper)
 {
     if (element.LocalName == ObjectDefinitionConstants.ImportElement)
     {
         ImportObjectDefinitionResource(element);
     }
     else if (element.LocalName == ObjectDefinitionConstants.AliasElement)
     {
         ParseAlias(element, helper.ReaderContext.Registry);
     }
     else if (element.LocalName == ObjectDefinitionConstants.ObjectElement)
     {
         ProcessObjectDefinition(element, helper);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Read object definitions from the given DOM element, and register
        /// them with the given object registry.
        /// </summary>
        /// <param name="doc">The DOM element containing object definitions, usually the
        /// root (document) element.</param>
        /// <param name="readerContext">The current context of the reader.  Includes
        /// the resource being parsed</param>
        /// <returns>
        /// The number of object definitions that were loaded.
        /// </returns>
        /// <exception cref="Oragon.Spring.Objects.ObjectsException">
        /// In case of parsing errors.
        /// </exception>
        public void RegisterObjectDefinitions(XmlDocument doc, XmlReaderContext readerContext)
        {
            //int objectDefinitionCounter = 0;

            this.readerContext = readerContext;

            #region Instrumentation

            if (log.IsDebugEnabled)
            {
                log.Debug("Loading object definitions.");
            }

            #endregion

            XmlElement root = doc.DocumentElement;

            ObjectDefinitionParserHelper parserHelper = CreateHelper(readerContext, root);


            PreProcessXml(root);

            ParseObjectDefinitions(root, parserHelper);

            PostProcessXml(root);

            #region Instrumentation

            if (log.IsDebugEnabled)
            {
                log.Debug(
                    string.Format(
                        "Found {0} <{1}> elements defining objects.",
                        readerContext.Registry.ObjectDefinitionCount,
                        ObjectDefinitionConstants.ObjectElement));
            }

            #endregion
        }
Exemplo n.º 4
0
        /// <summary>
        /// Parses object definitions starting at the given <see cref="XmlElement"/>
        /// using the passed <see cref="ObjectDefinitionParserHelper"/>.
        /// </summary>
        /// <param name="root">The root element to start parsing from.</param>
        /// <param name="helper">The <see cref="ObjectDefinitionParserHelper"/> instance to use.</param>
        /// <exception cref="ObjectDefinitionStoreException">
        /// in case an error happens during parsing and registering object definitions
        /// </exception>
        protected virtual void ParseObjectDefinitions(XmlElement root, ObjectDefinitionParserHelper helper)
        {
            if (helper.IsDefaultNamespace(root.NamespaceURI))
            {
                foreach (XmlNode node in root.ChildNodes)
                {
                    if (node.NodeType != XmlNodeType.Element)
                    {
                        continue;
                    }

                    try
                    {
                        XmlElement element = (XmlElement)node;
                        if (helper.IsDefaultNamespace(element.NamespaceURI))
                        {
                            ParseDefaultElement(element, helper);
                        }
                        else
                        {
                            helper.ParseCustomElement(element);
                        }
                    }
                    catch (ObjectDefinitionStoreException)
                    {
                        throw;
                    }
                    catch (Exception ex)
                    {
                        helper.ReaderContext.ReportException(node, null, "Failed parsing element", ex);
                    }
                }
            }
            else
            {
                helper.ParseCustomElement(root);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates an <see cref="ObjectDefinitionParserHelper"/> instance for the given <paramref name="readerContext"/> and <paramref name="root"/> element.
        /// </summary>
        /// <param name="readerContext">the <see cref="XmlReaderContext"/> to create the <see cref="ObjectDefinitionParserHelper"/> </param>
        /// <param name="root">the root <see cref="XmlElement"/> to start reading from</param>
        /// <returns>a new <see cref="ObjectDefinitionParserHelper"/> instance</returns>
        protected virtual ObjectDefinitionParserHelper CreateHelper(XmlReaderContext readerContext, XmlElement root)
        {
            ObjectDefinitionParserHelper helper = new ObjectDefinitionParserHelper(readerContext, root);

            return(helper);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Parse an object definition and register it with the object factory..
 /// </summary>
 /// <param name="element">The element containing the object definition.</param>
 /// <param name="helper">The helper.</param>
 /// <seealso cref="Oragon.Spring.Objects.Factory.Support.ObjectDefinitionReaderUtils.RegisterObjectDefinition"/>
 protected virtual void RegisterObjectDefinition(XmlElement element, ObjectDefinitionParserHelper helper)
 {
     ProcessObjectDefinition(element, helper);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ParserContext"/> class.
 /// </summary>
 /// <param name="parserHelper">The parser helper.</param>
 /// <param name="containingObjectDefinition">The containing object definition.</param>
 public ParserContext(ObjectDefinitionParserHelper parserHelper, IObjectDefinition containingObjectDefinition)
 {
     this.readerContext = parserHelper.ReaderContext;
     this.parserHelper  = parserHelper;
     this.containingObjectDefinition = containingObjectDefinition;
 }
Exemplo n.º 8
0
//        private Stack containingComponents = new Stack();

        /// <summary>
        /// Initializes a new instance of the <see cref="ParserContext"/> class.
        /// </summary>
        /// <param name="parserHelper">The parser helper.</param>
        public ParserContext(ObjectDefinitionParserHelper parserHelper)
        {
            this.readerContext = parserHelper.ReaderContext;
            this.parserHelper  = parserHelper;
        }