public void Instantiation () { MutablePropertyValues root = new MutablePropertyValues (); root.Add (new PropertyValue ("Name", "Fiona Apple")); root.Add (new PropertyValue ("Age", 24)); MutablePropertyValues props = new MutablePropertyValues (root); Assert.AreEqual (2, props.PropertyValues.Count); }
/// <summary> /// Return the difference (changes, additions, but not removals) of /// property values between the supplied argument and the values /// contained in the collection. /// </summary> /// <param name="old">Another property values collection.</param> /// <returns> /// The collection of property values that are different than the supplied one. /// </returns> public IPropertyValues ChangesSince(IPropertyValues old) { MutablePropertyValues changes = new MutablePropertyValues(); if (old == this) { return(changes); } // for each property value in this (the newer set) foreach (PropertyValue newProperty in propertyValuesList) { PropertyValue oldProperty = old.GetPropertyValue(newProperty.Name); if (oldProperty == null) { // if there wasn't an old one, add it changes.Add(newProperty); } else if (!oldProperty.Equals(newProperty)) { // it's changed changes.Add(newProperty); } } return(changes); }
public void AddAllInNullList() { MutablePropertyValues props = new MutablePropertyValues (); props.Add (new PropertyValue ("Name", "Fiona Apple")); props.Add (new PropertyValue ("Age", 24)); props.AddAll ((IList) null); Assert.AreEqual (2, props.PropertyValues.Length); }
public void Contains() { MutablePropertyValues props = new MutablePropertyValues(); props.Add(new PropertyValue("Name", "Fiona Apple")); props.Add(new PropertyValue("Age", 24)); // must be case insensitive to be CLS compliant... Assert.IsTrue(props.Contains("nAmE")); }
public void AddAllInNullList() { MutablePropertyValues props = new MutablePropertyValues(); props.Add(new PropertyValue("Name", "Fiona Apple")); props.Add(new PropertyValue("Age", 24)); props.AddAll((IList <PropertyValue>)null); Assert.AreEqual(2, props.PropertyValues.Count); }
public void Instantiation() { MutablePropertyValues root = new MutablePropertyValues(); root.Add(new PropertyValue("Name", "Fiona Apple")); root.Add(new PropertyValue("Age", 24)); MutablePropertyValues props = new MutablePropertyValues(root); Assert.AreEqual(2, props.PropertyValues.Count); }
public void RemoveByName() { MutablePropertyValues props = new MutablePropertyValues(); props.Add(new PropertyValue("Name", "Fiona Apple")); props.Add(new PropertyValue("Age", 24)); Assert.AreEqual(2, props.PropertyValues.Count); props.Remove("name"); Assert.AreEqual(1, props.PropertyValues.Count); }
public void RemoveByPropertyValue() { MutablePropertyValues props = new MutablePropertyValues(); PropertyValue propName = new PropertyValue("Name", "Fiona Apple"); props.Add(propName); props.Add(new PropertyValue("Age", 24)); Assert.AreEqual(2, props.PropertyValues.Length); props.Remove(propName); Assert.AreEqual(1, props.PropertyValues.Length); }
public void ChangesSince() { IDictionary <string, object> map = new Dictionary <string, object>(); PropertyValue propName = new PropertyValue("Name", "Fiona Apple"); map.Add(propName.Name, propName.Value); map.Add("Age", 24); MutablePropertyValues props = new MutablePropertyValues(map); MutablePropertyValues newProps = new MutablePropertyValues(map); // change the name... this is the change we'll be looking for newProps.SetPropertyValueAt(new PropertyValue(propName.Name, "Naomi Woolf"), 0); IPropertyValues changes = newProps.ChangesSince(props); Assert.AreEqual(1, changes.PropertyValues.Count); // the name was changed, so its the name property that should be in the changed list Assert.IsTrue(changes.Contains("name")); newProps.Add(new PropertyValue("Commentator", "Naomi Woolf")); changes = newProps.ChangesSince(props); Assert.AreEqual(2, changes.PropertyValues.Count); // the Commentator was added, so its the Commentator property that should be in the changed list Assert.IsTrue(changes.Contains("commentator")); // the name was changed, so its the name property that should be in the changed list Assert.IsTrue(changes.Contains("name")); }
private ObjectDefinitionHolder ParseTestObjectDefinition(XmlElement rootElement, ParserContext parserContext) { MutablePropertyValues properties = new MutablePropertyValues(); XmlNodeList childNodes = rootElement.ChildNodes; //Get all properties (from non whitespace nodes) foreach (XmlNode childNode in childNodes) { if (XmlNodeType.Whitespace != childNode.NodeType) { properties.Add(new PropertyValue(childNode.LocalName, childNode.InnerText)); } } IConfigurableObjectDefinition od = new RootObjectDefinition(typeof (TestObject), null, properties); od.IsSingleton = false; //HardCoded for now. string id = "testObject"; //id = ObjectDefinitionReaderUtils.GenerateObjectName(od, reader.ObjectReader.Registry); return new ObjectDefinitionHolder(od, id); }
public void AddAllInNullMap() { MutablePropertyValues props = new MutablePropertyValues (); props.Add (new PropertyValue ("Name", "Fiona Apple")); props.AddAll ((IDictionary) null); Assert.AreEqual (1, props.PropertyValues.Length); }
public void AddAllInNullMap() { MutablePropertyValues props = new MutablePropertyValues(); props.Add(new PropertyValue("Name", "Fiona Apple")); props.AddAll((IDictionary <string, object>)null); Assert.AreEqual(1, props.PropertyValues.Count); }
public void AddAllInNullMap() { MutablePropertyValues props = new MutablePropertyValues(); props.Add(new PropertyValue("Name", "Fiona Apple")); props.AddAll((IDictionary)null); Assert.AreEqual(1, props.PropertyValues.Length); }
private MutablePropertyValues getMutablePropertyValues(TypeRegistration registrationEntry) { MutablePropertyValues properties = new MutablePropertyValues(); foreach (InjectedProperty property in registrationEntry.InjectedProperties) { properties.Add(new PropertyValue(property.PropertyName,getInjectionParameterValue(property.PropertyValue))); } return properties; }
public override IPropertyValues PostProcessPropertyValues(IPropertyValues propertyValues, PropertyInfo[] propertyInfos, object objectInstance, string objectName) { MutablePropertyValues mpv = new MutablePropertyValues(propertyValues); IConfigurableObjectDefinition objectDefinition = (IConfigurableObjectDefinition)_objectFactory.GetObjectDefinition(objectName); DependencyCheckingMode checkMode = objectDefinition.DependencyCheck; PropertyInfo[] unresolvedProperties = AutowireUtils.GetUnsatisfiedDependencies(propertyInfos, propertyValues, checkMode); foreach(PropertyInfo propertyInfo in unresolvedProperties) { object value = ResolveDependency(objectName, objectDefinition, new ObjectWrapper(objectInstance), propertyInfo); if (value != null) { mpv.Add(propertyInfo.Name, value); } } return base.PostProcessPropertyValues(mpv, propertyInfos, objectInstance, objectName); }
public void RemoveByPropertyValue () { MutablePropertyValues props = new MutablePropertyValues (); PropertyValue propName = new PropertyValue ("Name", "Fiona Apple"); props.Add (propName); props.Add (new PropertyValue ("Age", 24)); Assert.AreEqual (2, props.PropertyValues.Count); props.Remove (propName); Assert.AreEqual (1, props.PropertyValues.Count); }
/// <summary> /// Parses the CaoExporter definition. /// </summary> /// <param name="element">The element to parse.</param> /// <param name="name">The name of the object definition.</param> /// <param name="parserContext">The parser context.</param> /// <returns>CaoExporter object definition.</returns> private IConfigurableObjectDefinition ParseCaoExporter( XmlElement element, string name, ParserContext parserContext) { string typeName = GetTypeName(element); string targetName = element.GetAttribute(CaoExporterConstants.TargetNameAttribute); string infinite = element.GetAttribute(CaoExporterConstants.InfiniteAttribute); MutablePropertyValues properties = new MutablePropertyValues(); if (StringUtils.HasText(targetName)) { properties.Add("TargetName", targetName); } if (StringUtils.HasText(infinite)) { properties.Add("Infinite", infinite); } foreach (XmlElement child in element.ChildNodes) { switch (child.LocalName) { case LifeTimeConstants.LifeTimeElement: ParseLifeTime(properties, child, parserContext); break; case InterfacesConstants.InterfacesElement: properties.Add("Interfaces", base.ParseListElement(child, name, parserContext)); break; } } IConfigurableObjectDefinition cod = parserContext.ReaderContext.ObjectDefinitionFactory.CreateObjectDefinition( typeName, null, parserContext.ReaderContext.Reader.Domain); cod.PropertyValues = properties; return cod; }
/// <summary> /// Parses the LifeTime definition. /// </summary> private void ParseLifeTime(MutablePropertyValues properties, XmlElement child, ParserContext parserContext) { string initialLeaseTime = child.GetAttribute(LifeTimeConstants.InitialLeaseTimeAttribute); string renewOnCallTime = child.GetAttribute(LifeTimeConstants.RenewOnCallTimeAttribute); string sponsorshipTimeout = child.GetAttribute(LifeTimeConstants.SponsorshipTimeoutAttribute); if (StringUtils.HasText(initialLeaseTime)) { properties.Add("InitialLeaseTime", initialLeaseTime); } if (StringUtils.HasText(renewOnCallTime)) { properties.Add("RenewOnCallTime", renewOnCallTime); } if (StringUtils.HasText(sponsorshipTimeout)) { properties.Add("SponsorshipTimeout", sponsorshipTimeout); } }
/// <summary> /// Parses the object definition for the engine object, configures a single NVelocity template engine based /// on the element definitions. /// </summary> /// <param name="element">the root element defining the velocity engine</param> /// <param name="parserContext">the parser context</param> private IConfigurableObjectDefinition ParseNVelocityEngine(XmlElement element, ParserContext parserContext) { string typeName = GetTypeName(element); IConfigurableObjectDefinition configurableObjectDefinition = parserContext.ReaderContext.ObjectDefinitionFactory.CreateObjectDefinition( typeName, null, parserContext.ReaderContext.Reader.Domain); string preferFileSystemAccess = GetAttributeValue(element, TemplateDefinitionConstants.AttributePreferFileSystemAccess); string overrideLogging = GetAttributeValue(element, TemplateDefinitionConstants.AttributeOverrideLogging); string configFile = GetAttributeValue(element, TemplateDefinitionConstants.AttributeConfigFile); MutablePropertyValues objectDefinitionProperties = new MutablePropertyValues(); if (StringUtils.HasText(preferFileSystemAccess)) { objectDefinitionProperties.Add(TemplateDefinitionConstants.PropertyPreferFileSystemAccess, preferFileSystemAccess); } if (StringUtils.HasText(overrideLogging)) { objectDefinitionProperties.Add(TemplateDefinitionConstants.PropertyOverrideLogging, overrideLogging); } if (StringUtils.HasText(configFile)) { objectDefinitionProperties.Add(TemplateDefinitionConstants.PropertyConfigFile, configFile); } XmlNodeList childElements = element.ChildNodes; if (childElements.Count > 0) { ParseChildDefinitions(childElements, parserContext, objectDefinitionProperties); } configurableObjectDefinition.PropertyValues = objectDefinitionProperties; return configurableObjectDefinition; }
public void AllValid() { TestObject t = new TestObject(); string newName = "tony"; int newAge = 65; string newTouchy = "valid"; IObjectWrapper wrapper = GetWrapper(t); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.Add(new PropertyValue("Age", newAge)); pvs.Add(new PropertyValue("Name", newName)); pvs.Add(new PropertyValue("Touchy", newTouchy)); wrapper.SetPropertyValues(pvs); Assert.IsTrue(t.Name.Equals(newName), "Validly set property must stick"); Assert.IsTrue(t.Touchy.Equals(newTouchy), "Validly set property must stick"); Assert.IsTrue(t.Age == newAge, "Validly set property must stick"); }
public void ChangesSince () { IDictionary<string, object> map = new Dictionary<string, object>(); PropertyValue propName = new PropertyValue("Name", "Fiona Apple"); map.Add (propName.Name, propName.Value); map.Add ("Age", 24); MutablePropertyValues props = new MutablePropertyValues (map); MutablePropertyValues newProps = new MutablePropertyValues (map); // change the name... this is the change we'll be looking for newProps.SetPropertyValueAt (new PropertyValue (propName.Name, "Naomi Woolf"), 0); IPropertyValues changes = newProps.ChangesSince (props); Assert.AreEqual (1, changes.PropertyValues.Count); // the name was changed, so its the name property that should be in the changed list Assert.IsTrue (changes.Contains ("name")); newProps.Add (new PropertyValue ("Commentator", "Naomi Woolf")); changes = newProps.ChangesSince (props); Assert.AreEqual (2, changes.PropertyValues.Count); // the Commentator was added, so its the Commentator property that should be in the changed list Assert.IsTrue (changes.Contains ("commentator")); // the name was changed, so its the name property that should be in the changed list Assert.IsTrue (changes.Contains ("name")); }
/// <summary> /// Parses child element definitions for the NVelocity engine. Typically resource loaders and locally defined properties are parsed here /// </summary> /// <param name="childElements">the XmlNodeList representing the child configuration of the root NVelocity engine element</param> /// <param name="parserContext">the parser context</param> /// <param name="objectDefinitionProperties">the MutablePropertyValues used to configure this object</param> private void ParseChildDefinitions(XmlNodeList childElements, ParserContext parserContext, MutablePropertyValues objectDefinitionProperties) { IDictionary<string, object> properties = new Dictionary<string, object>(); foreach (XmlElement element in childElements) { switch (element.LocalName) { case TemplateDefinitionConstants.ElementResourceLoader: ParseResourceLoader(element, objectDefinitionProperties, properties); break; case TemplateDefinitionConstants.ElementNVelocityProperties: ParseNVelocityProperties(element, parserContext, properties); break; } } if (properties.Count > 0) { objectDefinitionProperties.Add(TemplateDefinitionConstants.PropertyVelocityProperties, properties); } }
private IObjectDefinition ParseExceptionAction(XmlElement element, ParserContext parserContext) { string typeName = "Spring.Validation.Actions.ExceptionAction, Spring.Core"; string throwExpression = GetAttributeValue(element, ValidatorDefinitionConstants.ThrowAttribute); ConstructorArgumentValues ctorArgs = new ConstructorArgumentValues(); ctorArgs.AddGenericArgumentValue(throwExpression); string when = GetAttributeValue(element, ValidatorDefinitionConstants.WhenAttribute); MutablePropertyValues properties = new MutablePropertyValues(); if (StringUtils.HasText(when)) { properties.Add("When", when); } IConfigurableObjectDefinition action = parserContext.ReaderContext.ObjectDefinitionFactory.CreateObjectDefinition(typeName, null, parserContext.ReaderContext.Reader.Domain); action.ConstructorArgumentValues = ctorArgs; action.PropertyValues = properties; return action; }
/// <summary> /// Creates object definition for the validator reference. /// </summary> /// <param name="element">The action definition element.</param> /// <param name="parserContext">The parser helper.</param> /// <returns>Generic validation action definition.</returns> private IObjectDefinition ParseValidatorReference(XmlElement element, ParserContext parserContext) { string typeName = "Spring.Validation.ValidatorReference, Spring.Core"; string name = GetAttributeValue(element, ValidatorDefinitionConstants.ReferenceNameAttribute); string context = GetAttributeValue(element, ValidatorDefinitionConstants.ReferenceContextAttribute); string when = GetAttributeValue(element, ValidatorDefinitionConstants.WhenAttribute); MutablePropertyValues properties = new MutablePropertyValues(); properties.Add("Name", name); if (StringUtils.HasText(context)) { properties.Add("Context", context); } if (StringUtils.HasText(when)) { properties.Add("When", when); } IConfigurableObjectDefinition reference = parserContext.ReaderContext.ObjectDefinitionFactory.CreateObjectDefinition(typeName, null, parserContext.ReaderContext.Reader.Domain); reference.PropertyValues = properties; return reference; }
/// <summary> /// Parses the attribute of the given <paramref name="attName"/> from the XmlElement and, if available, adds a property of the given <paramref name="propName"/> with /// the parsed value. /// </summary> private void ParseAttributeIntoProperty(XmlElement element, string attName, MutablePropertyValues properties, string propName) { string test = GetAttributeValue(element, attName); if (StringUtils.HasText(test)) { properties.Add(propName, test); } }
/// <summary> /// Creates an error message action based on the specified message element. /// </summary> /// <param name="message">The message element.</param> /// <param name="parserContext">The parser helper.</param> /// <returns>The error message action definition.</returns> private static IObjectDefinition ParseErrorMessageAction(XmlElement message, ParserContext parserContext) { string messageId = GetAttributeValue(message, MessageConstants.IdAttribute); string[] providers = GetAttributeValue(message, MessageConstants.ProvidersAttribute).Split(','); ArrayList parameters = new ArrayList(); foreach (XmlElement param in message.ChildNodes) { IExpression paramExpression = Expression.Parse(GetAttributeValue(param, MessageConstants.ParameterValueAttribute)); parameters.Add(paramExpression); } string typeName = "Spring.Validation.Actions.ErrorMessageAction, Spring.Core"; ConstructorArgumentValues ctorArgs = new ConstructorArgumentValues(); ctorArgs.AddGenericArgumentValue(messageId); ctorArgs.AddGenericArgumentValue(providers); string when = GetAttributeValue(message, ValidatorDefinitionConstants.WhenAttribute); MutablePropertyValues properties = new MutablePropertyValues(); if (StringUtils.HasText(when)) { properties.Add("When", when); } if (parameters.Count > 0) { properties.Add("Parameters", parameters.ToArray(typeof(IExpression))); } IConfigurableObjectDefinition action = parserContext.ReaderContext.ObjectDefinitionFactory.CreateObjectDefinition(typeName, null, parserContext.ReaderContext.Reader.Domain); action.ConstructorArgumentValues = ctorArgs; action.PropertyValues = properties; return action; }
public void SetPropertyValuesFailsWhenSettingReadOnlyProperty() { TestObject to = new TestObject(); ObjectWrapper wrapper = GetWrapper(to); MutablePropertyValues values = new MutablePropertyValues(); values.Add("ReadOnlyObjectNumber", 123); Assert.Throws<NotWritablePropertyException>(() => wrapper.SetPropertyValues(values, false)); }
/// <summary> /// Return the difference (changes, additions, but not removals) of /// property values between the supplied argument and the values /// contained in the collection. /// </summary> /// <param name="old">Another property values collection.</param> /// <returns> /// The collection of property values that are different than the supplied one. /// </returns> public IPropertyValues ChangesSince(IPropertyValues old) { MutablePropertyValues changes = new MutablePropertyValues (); if (old == this) { return changes; } // for each property value in this (the newer set) foreach (PropertyValue newProperty in propertyValuesList) { PropertyValue oldProperty = old.GetPropertyValue (newProperty.Name); if (oldProperty == null) { // if there wasn't an old one, add it changes.Add (newProperty); } else if (!oldProperty.Equals (newProperty)) { // it's changed changes.Add (newProperty); } } return changes; }
public void SettingAnInvalidValue() { TestObject t = new TestObject(); string newName = "tony"; try { IObjectWrapper wrapper = GetWrapper(t); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.Add(new PropertyValue("Age", "foobar")); pvs.Add(new PropertyValue("Name", newName)); wrapper.SetPropertyValues(pvs); Assert.Fail("Should throw exception when setting an invalid value"); } catch (PropertyAccessExceptionsException ex) { Assert.IsTrue(ex.ExceptionCount == 1, "Must contain 2 exceptions"); // Test validly set property matches Assert.IsTrue(t.Name.Equals(newName), "Validly set property must stick"); Assert.IsTrue(t.Age == 0, "Invalidly set property must retain old value"); } catch (Exception ex) { Assert.Fail( "Shouldn't throw exception other than PropertyAccessExceptions. Exception Message = " + ex.Message); } }
public void Contains () { MutablePropertyValues props = new MutablePropertyValues (); props.Add (new PropertyValue ("Name", "Fiona Apple")); props.Add (new PropertyValue ("Age", 24)); // must be case insensitive to be CLS compliant... Assert.IsTrue (props.Contains ("nAmE")); }
public void DoTestMessageAccess(bool hasParentContext, bool useCodeAsDefaultMessage) { StaticApplicationContext ac = new StaticApplicationContext(); if (hasParentContext) { StaticApplicationContext parent = new StaticApplicationContext(); parent.Refresh(); ac.ParentContext = parent; } MutablePropertyValues pvs = new MutablePropertyValues(); pvs.Add("resourceManagers", resourceManagerList); if (useCodeAsDefaultMessage) { pvs.Add("UseCodeAsDefaultMessage", true); } ac.RegisterSingleton("messageSource", typeof(ResourceSetMessageSource), pvs); ac.Refresh(); // Localizaiton fallbacks GetMessageLocalizationFallbacks(ac); // MessageSourceAccessor functionality MessageSourceAccessor accessor = new MessageSourceAccessor(ac); Assert.AreEqual("message3", accessor.GetMessage("code3", CultureInfo.CurrentUICulture, (object[])null)); // IMessageSourceResolveable Assert.AreEqual("message3", ac.GetMessage("code3", CultureInfo.CurrentUICulture, (object[])null)); IMessageSourceResolvable resolvable = new DefaultMessageSourceResolvable("code3"); Assert.AreEqual("message3", ac.GetMessage(resolvable, CultureInfo.CurrentUICulture)); resolvable = new DefaultMessageSourceResolvable(new string[] { "code4", "code3" }); Assert.AreEqual("message3", ac.GetMessage(resolvable, CultureInfo.CurrentUICulture)); Assert.AreEqual("message3", ac.GetMessage("code3", CultureInfo.CurrentUICulture, (object[])null)); resolvable = new DefaultMessageSourceResolvable(new string[] { "code4", "code3" }); Assert.AreEqual("message3", ac.GetMessage(resolvable, CultureInfo.CurrentUICulture)); object[] arguments = new object[] { "Hello", new DefaultMessageSourceResolvable(new string[] { "code1" }) }; Assert.AreEqual("Hello, message1", ac.GetMessage("hello", CultureInfo.CurrentUICulture, arguments)); // test default message without and with args Assert.AreEqual("default", ac.GetMessage(null, "default", CultureInfo.CurrentUICulture, null)); Assert.AreEqual("default", ac.GetMessage(null, "default", CultureInfo.CurrentUICulture, arguments)); /* not supported Assert.AreEqual("{0}, default", ac.GetMessage(null, "{0}, default", CultureInfo.CurrentUICulture, null)); */ Assert.AreEqual("Hello, default", ac.GetMessage(null, "{0}, default", CultureInfo.CurrentUICulture, arguments)); // test resolvable with default message, without and with args resolvable = new DefaultMessageSourceResolvable(null, null, "default"); Assert.AreEqual("default", ac.GetMessage(resolvable, CultureInfo.CurrentUICulture)); resolvable = new DefaultMessageSourceResolvable(null, arguments, "default"); Assert.AreEqual("default", ac.GetMessage(resolvable, CultureInfo.CurrentUICulture)); /* not supported resolvable = new DefaultMessageSourceResolvable(null, null, "{0}, default"); Assert.AreEqual("{0}, default", ac.GetMessage(resolvable, CultureInfo.CurrentUICulture)); */ resolvable = new DefaultMessageSourceResolvable(null, arguments, "{0}, default"); Assert.AreEqual("Hello, default", ac.GetMessage(resolvable, CultureInfo.CurrentUICulture)); // test message args Assert.AreEqual("Arg1, Arg2", ac.GetMessage("hello", CultureInfo.CurrentUICulture, new object[] { "Arg1", "Arg2" })); /* not supported Assert.AreEqual("{0}, {1}", ac.GetMessage("hello", CultureInfo.CurrentUICulture, null)); */ /* not supported Assert.AreEqual("Hello\nWorld", ac.GetMessage("escaped")); } else { Assert.AreEqual("Hello\\nWorld", ac.GetMessage("escaped")); } */ try { Assert.AreEqual("MyNonExistantMessage", ac.GetMessage("MyNonExistantMessage")); if (!useCodeAsDefaultMessage) { Assert.Fail("Should have thrown NoSuchMessagException"); } } catch (NoSuchMessageException e) { if (useCodeAsDefaultMessage) { Assert.Fail("Should have returned code as default message."); e.ToString(); } } }
public void AddAllInNullMap () { MutablePropertyValues props = new MutablePropertyValues (); props.Add (new PropertyValue ("Name", "Fiona Apple")); props.AddAll ((IDictionary<string, object>) null); Assert.AreEqual (1, props.PropertyValues.Count); }
/// <summary> /// Parses the RemotingConfigurer definition. /// </summary> /// <param name="element">The element to parse.</param> /// <param name="name">The name of the object definition.</param> /// <param name="parserContext">The parser context.</param> /// <returns>RemotingConfigurer object definition.</returns> private IConfigurableObjectDefinition ParseRemotingConfigurer( XmlElement element, string name, ParserContext parserContext) { string typeName = GetTypeName(element); string filename = element.GetAttribute(RemotingConfigurerConstants.FilenameAttribute); string useConfigFile = element.GetAttribute(RemotingConfigurerConstants.UseConfigFileAttribute); string ensureSecurity = element.GetAttribute(RemotingConfigurerConstants.EnsureSecurityAttribute); MutablePropertyValues properties = new MutablePropertyValues(); if (StringUtils.HasText(filename)) { properties.Add("Filename", filename); } if (StringUtils.HasText(useConfigFile)) { properties.Add("UseConfigFile", useConfigFile); } if (StringUtils.HasText(ensureSecurity)) { properties.Add("EnsureSecurity", ensureSecurity); } IConfigurableObjectDefinition cod = parserContext.ReaderContext.ObjectDefinitionFactory.CreateObjectDefinition( typeName, null, parserContext.ReaderContext.Reader.Domain); cod.PropertyValues = properties; return cod; }
public void SetPropertyValuesDoesNotFailWhenSettingNonExistantPropertyWithIgnorUnknownSetToTrue() { TestObject to = new TestObject(); ObjectWrapper wrapper = GetWrapper(to); MutablePropertyValues values = new MutablePropertyValues(); values.Add("Age", 19); values.Add("JeepersCreepersWhereDidYaGetThosePeepers", "OhThisWeirdBatGuySoldEmToMe..."); // the unknown and ridiculously named property should fail wrapper.SetPropertyValues(values, true); Assert.AreEqual(19, to.Age, "The single good property in the property values should have been set though..."); }
/// <summary> /// Parses the SaoFactoryObject definition. /// </summary> /// <param name="element">The element to parse.</param> /// <param name="name">The name of the object definition.</param> /// <param name="parserContext">The parser context.</param> /// <returns>SaoFactoryObject object definition.</returns> private IConfigurableObjectDefinition ParseSaoFactoryObject( XmlElement element, string name, ParserContext parserContext) { string typeName = GetTypeName(element); string serviceInterface = element.GetAttribute(SaoFactoryObjectConstants.ServiceInterfaceAttribute); string serviceUrl = element.GetAttribute(SaoFactoryObjectConstants.ServiceUrlAttribute); MutablePropertyValues properties = new MutablePropertyValues(); if (StringUtils.HasText(serviceInterface)) { properties.Add("ServiceInterface", serviceInterface); } if (StringUtils.HasText(serviceUrl)) { properties.Add("ServiceUrl", serviceUrl); } IConfigurableObjectDefinition cod = parserContext.ReaderContext.ObjectDefinitionFactory.CreateObjectDefinition( typeName, null, parserContext.ReaderContext.Reader.Domain); cod.PropertyValues = properties; return cod; }
/// <summary> /// Creates a spring resource loader by setting the ResourceLoaderPaths of the /// engine factory (the resource loader itself will be created internally either as /// spring or as file resource loader based on the value of prefer-file-system-access /// attribute). /// </summary> /// <param name="elements">list of resource loader path elements</param> /// <param name="objectDefinitionProperties">the MutablePropertyValues to set the property for the engine factory</param> private void AppendResourceLoaderPaths(XmlNodeList elements, MutablePropertyValues objectDefinitionProperties) { IList<string> paths = new List<string>(); foreach (XmlElement element in elements) { string path = GetAttributeValue(element, TemplateDefinitionConstants.AttributeUri); paths.Add(path); } objectDefinitionProperties.Add(TemplateDefinitionConstants.PropertyResourceLoaderPaths, paths); }
/// <summary> /// Parses the CaoFactoryObject definition. /// </summary> /// <param name="element">The element to parse.</param> /// <param name="name">The name of the object definition.</param> /// <param name="parserContext">The parser context.</param> /// <returns>CaoFactoryObject object definition.</returns> private IConfigurableObjectDefinition ParseCaoFactoryObject( XmlElement element, string name, ParserContext parserContext) { string typeName = GetTypeName(element); string remoteTargetName = element.GetAttribute(CaoFactoryObjectConstants.RemoteTargetNameAttribute); string serviceUrl = element.GetAttribute(CaoFactoryObjectConstants.ServiceUrlAttribute); MutablePropertyValues properties = new MutablePropertyValues(); if (StringUtils.HasText(remoteTargetName)) { properties.Add("RemoteTargetName", remoteTargetName); } if (StringUtils.HasText(serviceUrl)) { properties.Add("ServiceUrl", serviceUrl); } foreach (XmlElement child in element.ChildNodes) { switch (child.LocalName) { case CaoFactoryObjectConstants.ConstructorArgumentsElement: properties.Add("ConstructorArguments", base.ParseListElement(child, name, parserContext)); break; } } IConfigurableObjectDefinition cod = parserContext.ReaderContext.ObjectDefinitionFactory.CreateObjectDefinition( typeName, null, parserContext.ReaderContext.Reader.Domain); cod.PropertyValues = properties; return cod; }
/// <summary> /// Parses the validator definition. /// </summary> /// <param name="id">Validator's identifier.</param> /// <param name="element">The element to parse.</param> /// <param name="parserContext">The parser helper.</param> /// <returns>Validator object definition.</returns> private IObjectDefinition ParseValidator(string id, XmlElement element, ParserContext parserContext) { string typeName = GetTypeName(element); string parent = GetAttributeValue(element, ObjectDefinitionConstants.ParentAttribute); string name = "validator: " + (StringUtils.HasText(id) ? id : this.definitionCount.ToString()); MutablePropertyValues properties = new MutablePropertyValues(); IConfigurableObjectDefinition od = parserContext.ReaderContext.ObjectDefinitionFactory.CreateObjectDefinition( typeName, parent, parserContext.ReaderContext.Reader.Domain); od.PropertyValues = properties; od.IsSingleton = true; od.IsLazyInit = true; ParseAttributeIntoProperty(element, ValidatorDefinitionConstants.TestAttribute, properties, "Test"); ParseAttributeIntoProperty(element, ValidatorDefinitionConstants.WhenAttribute, properties, "When"); ParseAttributeIntoProperty(element, ValidatorDefinitionConstants.GroupFastValidateAttribute, properties, "FastValidate"); ParseAttributeIntoProperty(element, ValidatorDefinitionConstants.RegexExpressionAttribute, properties, "Expression"); ParseAttributeIntoProperty(element, ValidatorDefinitionConstants.CollectionValidateAllAttribute, properties, "ValidateAll"); ParseAttributeIntoProperty(element, ValidatorDefinitionConstants.CollectionContextAttribute, properties, "Context"); ParseAttributeIntoProperty(element, ValidatorDefinitionConstants.CollectionIncludeElementsErrors, properties, "IncludeElementErrors"); // TODO: (EE) - is this a mistake to check 'validateAll' but add 'context' then? // if (StringUtils.HasText(validateAll)) // { // properties.Add("Context", context); // } ManagedList nestedValidators = new ManagedList(); ManagedList actions = new ManagedList(); ParserContext childParserContext = new ParserContext(parserContext.ParserHelper, od); foreach (XmlNode node in element.ChildNodes) { XmlElement child = node as XmlElement; if (child != null) { switch (child.LocalName) { case ValidatorDefinitionConstants.PropertyElement: string propertyName = GetAttributeValue(child, ValidatorDefinitionConstants.PropertyNameAttribute); properties.Add(propertyName, base.ParsePropertyValue(child, name, childParserContext)); break; case ValidatorDefinitionConstants.MessageElement: actions.Add(ParseErrorMessageAction(child, childParserContext)); break; case ValidatorDefinitionConstants.ActionElement: actions.Add(ParseGenericAction(child, childParserContext)); break; case ValidatorDefinitionConstants.ExceptionElement: actions.Add(ParseExceptionAction(child, childParserContext)); break; case ValidatorDefinitionConstants.ReferenceElement: nestedValidators.Add(ParseValidatorReference(child, childParserContext)); break; default: nestedValidators.Add(ParseAndRegisterValidator(child, childParserContext)); break; } } } if (nestedValidators.Count > 0) { properties.Add("Validators", nestedValidators); } if (actions.Count > 0) { properties.Add("Actions", actions); } return od; }
public void SetPropertyValuesDoesNotFailWhenSettingReadOnlyPropertyWithIgnorUnknownSetToTrue() { TestObject to = new TestObject(); ObjectWrapper wrapper = GetWrapper(to); MutablePropertyValues values = new MutablePropertyValues(); values.Add("ObjectNumber", 123); values.Add("Age", 19); wrapper.SetPropertyValues(values, true); Assert.AreEqual(19, to.Age, "The single good property in the property values should have been set though..."); }