Exemple #1
0
        /// <summary>
        /// Apply the property replacement using the specified <see cref="IVariableSource"/>s for all
        /// object in the supplied
        /// <see cref="Oragon.Spring.Objects.Factory.Config.IConfigurableListableObjectFactory"/>.
        /// </summary>
        /// <param name="factory">
        /// The <see cref="Oragon.Spring.Objects.Factory.Config.IConfigurableListableObjectFactory"/>
        /// used by the application context.
        /// </param>
        /// <exception cref="Oragon.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));

            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)
                {
                    continue;
                }

                try
                {
                    visitor.VisitObjectDefinition(definition);
                }
                catch (ObjectDefinitionStoreException ex)
                {
                    throw new ObjectDefinitionStoreException(
                              definition.ResourceDescription, name, ex.Message);
                }
            }
        }
        /// <summary>
        /// Apply the given properties to the supplied
        /// <see cref="Oragon.Spring.Objects.Factory.Config.IConfigurableListableObjectFactory"/>.
        /// </summary>
        /// <param name="factory">
        /// The <see cref="Oragon.Spring.Objects.Factory.Config.IConfigurableListableObjectFactory"/>
        /// used by the application context.
        /// </param>
        /// <param name="props">The properties to apply.</param>
        /// <exception cref="Oragon.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);
        }
        public void VisitPropertyValues()
        {
            IObjectDefinition od = new RootObjectDefinition();

            od.PropertyValues.Add("PropertyName", "$Property");

            ObjectDefinitionVisitor odv = new ObjectDefinitionVisitor(new ObjectDefinitionVisitor.ResolveHandler(ParseAndResolveVariables));

            odv.VisitObjectDefinition(od);

            Assert.AreEqual("Value", od.PropertyValues.GetPropertyValue("PropertyName").Value);
        }
        public void VisitObjectTypeName()
        {
            IObjectDefinition od = new RootObjectDefinition();

            od.ObjectTypeName = "$Property";

            ObjectDefinitionVisitor odv = new ObjectDefinitionVisitor(new ObjectDefinitionVisitor.ResolveHandler(ParseAndResolveVariables));

            odv.VisitObjectDefinition(od);

            Assert.AreEqual("Value", od.ObjectTypeName);
        }
        public void VisitNameValueCollection()
        {
            IObjectDefinition   od  = new RootObjectDefinition();
            NameValueCollection nvc = new NameValueCollection();

            nvc["Key"] = "$Property";
            od.PropertyValues.Add("PropertyName", nvc);

            ObjectDefinitionVisitor odv = new ObjectDefinitionVisitor(new ObjectDefinitionVisitor.ResolveHandler(ParseAndResolveVariables));

            odv.VisitObjectDefinition(od);

            NameValueCollection visitedNvc =
                od.PropertyValues.GetPropertyValue("PropertyName").Value as NameValueCollection;

            Assert.AreEqual("Value", visitedNvc["Key"]);
        }
        public void VisitManagedList()
        {
            IObjectDefinition od = new RootObjectDefinition();
            ManagedList       ml = new ManagedList();

            ml.ElementTypeName = "$Property";
            ml.Add("$Property");
            od.PropertyValues.Add("PropertyName", ml);

            ObjectDefinitionVisitor odv = new ObjectDefinitionVisitor(new ObjectDefinitionVisitor.ResolveHandler(ParseAndResolveVariables));

            odv.VisitObjectDefinition(od);

            ManagedList list = od.PropertyValues.GetPropertyValue("PropertyName").Value as ManagedList;

            Assert.IsNotNull(list, "Property value is not of type ManagedList.  Type = [" +
                             od.PropertyValues.GetPropertyValue("PropertyName").Value.GetType() + "]");
            Assert.AreEqual("Value", list.ElementTypeName);
            Assert.AreEqual("Value", list[0]);
        }
        public void VisitManagedDictionary()
        {
            IObjectDefinition od = new RootObjectDefinition();
            ManagedDictionary md = new ManagedDictionary();

            md.KeyTypeName   = "$Property";
            md.ValueTypeName = "$Property";
            md.Add("Key", "$Property");
            od.PropertyValues.Add("PropertyName", md);

            ObjectDefinitionVisitor odv = new ObjectDefinitionVisitor(new ObjectDefinitionVisitor.ResolveHandler(ParseAndResolveVariables));

            odv.VisitObjectDefinition(od);

            ManagedDictionary dictionary = od.PropertyValues.GetPropertyValue("PropertyName").Value as ManagedDictionary;

            Assert.AreEqual("Value", dictionary.KeyTypeName);
            Assert.AreEqual("Value", dictionary.ValueTypeName);
            Assert.AreEqual("Value", dictionary["Key"]);
        }
        public void VisitManagedSet()
        {
            IObjectDefinition od = new RootObjectDefinition();
            ManagedSet        ms = new ManagedSet();

            ms.ElementTypeName = "$Property";
            ms.Add("$Property");
            od.PropertyValues.Add("PropertyName", ms);

            ObjectDefinitionVisitor odv = new ObjectDefinitionVisitor(new ObjectDefinitionVisitor.ResolveHandler(ParseAndResolveVariables));

            odv.VisitObjectDefinition(od);

            ManagedSet set = od.PropertyValues.GetPropertyValue("PropertyName").Value as ManagedSet;

            Assert.AreEqual("Value", set.ElementTypeName);
            IEnumerator enumerator = set.GetEnumerator();

            enumerator.MoveNext();
            Assert.AreEqual("Value", enumerator.Current);
        }