/// <summary>
        /// Detects the petsistence exception translators in the given object factory.
        /// </summary>
        /// <param name="objectFactory">The object factory for obtaining all IPersistenceExceptionTranslators.</param>
        /// <returns>A chained IPersistenceExceptionTranslator, combining all PersistenceExceptionTranslators found in the factory
        /// </returns>
        /// <seealso cref="ChainedPersistenceExceptionTranslator"/>
        protected IPersistenceExceptionTranslator DetectPersistenceExceptionTranslators(IListableObjectFactory objectFactory)
        {
            // Find all translators, being careful not to activate FactoryObjects.
            IDictionary <string, object> pets =
                ObjectFactoryUtils.ObjectsOfTypeIncludingAncestors(objectFactory,
                                                                   typeof(IPersistenceExceptionTranslator), false,
                                                                   false);

            if (pets.Count == 0)
            {
                throw new InvalidOperationException("No persistence exception translators found in container. Cannot perform exception translation.");
            }

            ChainedPersistenceExceptionTranslator cpet = new ChainedPersistenceExceptionTranslator();

            foreach (KeyValuePair <string, object> pet in pets)
            {
                cpet.AddTranslator((IPersistenceExceptionTranslator)pet.Value);
            }
            return(cpet);
        }
コード例 #2
0
 /// <summary>
 /// Find object instances that match the <paramref name="requiredType"/>.
 /// </summary>
 /// <remarks>
 /// <p>
 /// Called by autowiring. If a subclass cannot obtain information about object
 /// names by <see cref="System.Type"/>, a corresponding exception should be thrown.
 /// </p>
 /// </remarks>
 /// <param name="requiredType">
 /// The type of the objects to look up.
 /// </param>
 /// <returns>
 /// An <see cref="System.Collections.IDictionary"/> of object names and object
 /// instances that match the <paramref name="requiredType"/>, or
 /// <see langword="null"/> if none is found.
 /// </returns>
 /// <exception cref="Spring.Objects.ObjectsException">
 /// In case of errors.
 /// </exception>
 protected override IDictionary FindMatchingObjects(Type requiredType)
 {
     return(ObjectFactoryUtils.ObjectsOfTypeIncludingAncestors(
                this, requiredType, true, true));
 }