public void OneEventValue()
        {
            EventValues eventValues = new EventValues();

            eventValues.AddHandler(new MyEventHandler());
            Assert.AreEqual(1, eventValues.Events.Count);
        }
        public void NullEventHandlerValue()
        {
            EventValues eventValues = new EventValues();

            eventValues.AddAll(null);
            Assert.AreEqual(0, eventValues.Events.Count);
        }
			public void TwoEventHandlersForSameEvent()
		{
			EventValues eventValues = new EventValues();
			eventValues.AddHandler( new MyEventHandler());
			eventValues.AddHandler( new MyEventHandler());
			Assert.AreEqual( 1, eventValues.Events.Count );
		}
 /// <summary>
 /// Creates a new instance of the
 /// <see cref="Spring.Objects.Factory.Support.AbstractObjectDefinition"/>
 /// class.
 /// </summary>
 /// <remarks>
 /// <p>
 /// This is an <see langword="abstract"/> class, and as such exposes no
 /// public constructors.
 /// </p>
 /// </remarks>
 protected AbstractObjectDefinition(ConstructorArgumentValues arguments, MutablePropertyValues properties)
 {
     constructorArgumentValues =
         (arguments != null) ? arguments : new ConstructorArgumentValues();
     propertyValues =
         (properties != null) ? properties : new MutablePropertyValues();
     eventHandlerValues = new EventValues();
     DependsOn = StringUtils.EmptyStrings;
 }
			public void CopyEventHandlerValues()
		{
			EventValues eventValues = new EventValues();
			eventValues.AddHandler( new MyEventHandler());
			eventValues.AddHandler( new MyEventHandler());
			Assert.AreEqual( 1, eventValues.Events.Count );
			EventValues eventValues2 = new EventValues(eventValues);
			Assert.AreEqual( 1, eventValues2.Events.Count );
		}
        public void CopyEventHandlerValues()
        {
            EventValues eventValues = new EventValues();

            eventValues.AddHandler(new MyEventHandler());
            eventValues.AddHandler(new MyEventHandler());
            Assert.AreEqual(1, eventValues.Events.Count);
            EventValues eventValues2 = new EventValues(eventValues);

            Assert.AreEqual(1, eventValues2.Events.Count);
        }
Beispiel #7
0
 /// <summary>
 /// Copy all given argument values into this object.
 /// </summary>
 /// <param name="other">
 /// The <see cref="Spring.Objects.Factory.Config.EventValues"/>
 /// to be used to populate this instance.
 /// </param>
 public void AddAll(EventValues other)
 {
     if (other != null)
     {
         foreach (IList handlers in other.EventHandlers.Values)
         {
             foreach (IEventHandlerValue handler in handlers)
             {
                 AddHandler(handler);
             }
         }
     }
 }
Beispiel #8
0
 /// <summary>
 /// Copy all given argument values into this object.
 /// </summary>
 /// <param name="other">
 /// The <see cref="Spring.Objects.Factory.Config.EventValues"/>
 /// to be used to populate this instance.
 /// </param>
 public void AddAll(EventValues other)
 {
     if (other?._eventHandlers != null)
     {
         foreach (var pair in other._eventHandlers)
         {
             var list = pair.Value;
             for (var i = 0; i < list.Count; i++)
             {
                 AddHandler(list[i]);
             }
         }
     }
 }
        /// <summary>
        /// Creates a new instance of the
        /// <see cref="Spring.Objects.Factory.Support.AbstractObjectDefinition"/>
        /// class.
        /// </summary>
        /// <param name="other">
        /// The object definition used to initialise the member fields of this
        /// instance.
        /// </param>
        /// <remarks>
        /// <p>
        /// This is an <see langword="abstract"/> class, and as such exposes no
        /// public constructors.
        /// </p>
        /// </remarks>
        protected AbstractObjectDefinition(IObjectDefinition other)
        {
            AssertUtils.ArgumentNotNull(other, "other");
            this.OverrideFrom(other);

            AbstractObjectDefinition aod = other as AbstractObjectDefinition;
            if (aod != null)
            {
                if (aod.HasObjectType)
                {
                    ObjectType = other.ObjectType;
                }
                else
                {
                    ObjectTypeName = other.ObjectTypeName;
                }
                MethodOverrides = new MethodOverrides(aod.MethodOverrides);
                DependencyCheck = aod.DependencyCheck;
            }
            ParentName = other.ParentName;
            IsAbstract = other.IsAbstract;
//            IsSingleton = other.IsSingleton;
            Scope = other.Scope;
            Role = other.Role;
            IsLazyInit = other.IsLazyInit;
            ConstructorArgumentValues
                = new ConstructorArgumentValues(other.ConstructorArgumentValues);
            PropertyValues = new MutablePropertyValues(other.PropertyValues);
            EventHandlerValues = new EventValues(other.EventHandlerValues);

            InitMethodName = other.InitMethodName;
            DestroyMethodName = other.DestroyMethodName;
            DependsOn = new string[other.DependsOn.Length];
            IsAutowireCandidate = other.IsAutowireCandidate;
            Array.Copy(other.DependsOn, DependsOn, other.DependsOn.Length);
            FactoryMethodName = other.FactoryMethodName;
            FactoryObjectName = other.FactoryObjectName;
            AutowireMode = other.AutowireMode;
            ResourceDescription = other.ResourceDescription;
        }
 /// <summary>
 /// Parse event handler subelements of the given object element.
 /// </summary>
 protected EventValues ParseEventHandlerSubElements(
     string name, XmlElement element, ParserContext parserContext)
 {
     EventValues events = new EventValues();
     foreach (XmlNode node in this.SelectNodes(element, ObjectDefinitionConstants.ListenerElement))
     {
         ParseEventListenerDefinition(name, events, (XmlElement)node, parserContext);
     }
     return events;
 }
        /// <summary>Parses an event listener definition.</summary>
        /// <param name="name">
        /// The name associated with the object that the event handler is being defined on.
        /// </param>
        /// <param name="events">The events being populated.</param>
        /// <param name="element">
        /// The element containing the event listener definition.
        /// </param>
        /// <param name="parserContext">
        /// The namespace-aware parser.
        /// </param>
        protected virtual void ParseEventListenerDefinition(
            string name, EventValues events, XmlElement element, ParserContext parserContext)
        {
            // get an appropriate IEventHandlerValue instance based upon the
            // attribute values of the listener element...
            IEventHandlerValue myHandler = ObjectDefinitionReaderUtils.CreateEventHandlerValue(
                GetAttributeValue(element, ObjectDefinitionConstants.ListenerMethodAttribute),
                GetAttributeValue(element, ObjectDefinitionConstants.ListenerEventAttribute));

            // and then get the source of the event (another managed object instance
            // or a Type reference (i.e. a static event exposed on a class)...
            XmlElement sourceElement = this.SelectSingleNode(element, ObjectDefinitionConstants.RefElement) as XmlElement;

            XmlAttribute sourceAtt = sourceElement.Attributes[0];
            if (StringUtils.IsNullOrEmpty(sourceAtt.Value))
            {
                parserContext.ReaderContext.ReportFatalException(sourceElement, string.Format(
                    CultureInfo.InvariantCulture,
                    "The single attribute of the <{0}/> element cannot be empty. Specify the " +
                        "object id (alias) or the full, assembly qualified Type name that is the " +
                        "source of the event.",
                    ObjectDefinitionConstants.RefElement));
                return;
            }
            switch (sourceAtt.LocalName)
            {
                case ObjectDefinitionConstants.LocalRefAttribute:
                case ObjectDefinitionConstants.ObjectRefAttribute:
                    // we're wiring up to an event exposed on another managed object (instance)
                    RuntimeObjectReference ror = new RuntimeObjectReference(sourceAtt.Value);
                    myHandler.Source = ror;
                    break;
                case ObjectDefinitionConstants.TypeAttribute:
                    // we're wiring up to a static event exposed on a Type (class)
                    myHandler.Source = parserContext.ReaderContext.Reader.Domain == null ?
                        (object)sourceAtt.Value :
                        (object)TypeResolutionUtils.ResolveType(sourceAtt.Value);
                    break;
            }
            events.AddHandler(myHandler);
        }
Beispiel #12
0
 /// <summary>
 /// Creates a new instance of the
 /// <see cref="Spring.Objects.Factory.Config.EventValues"/> class.
 /// </summary>
 /// <param name="other">
 /// The <see cref="Spring.Objects.Factory.Config.EventValues"/>
 /// to be used to populate this instance.
 /// </param>
 public EventValues(EventValues other)
 {
     AddAll(other);
 }
        public void EmptyEventValues()
        {
            EventValues eventValues = new EventValues();

            Assert.AreEqual(0, eventValues.Events.Count);
        }
Beispiel #14
0
			public void NullEventHandlerValue()
		{
			EventValues eventValues = new EventValues();
			eventValues.AddAll( null );
			Assert.AreEqual( 0, eventValues.Events.Count );
		}
Beispiel #15
0
			public void EmptyEventValues()
		{
			EventValues eventValues = new EventValues();
			Assert.AreEqual( 0, eventValues.Events.Count );
		}
Beispiel #16
0
 /// <summary>
 /// Creates a new instance of the
 /// <see cref="Spring.Objects.Factory.Config.EventValues"/> class.
 /// </summary>
 /// <param name="other">
 /// The <see cref="Spring.Objects.Factory.Config.EventValues"/>
 /// to be used to populate this instance.
 /// </param>
 public EventValues(EventValues other)
 {
     AddAll (other);
 }
Beispiel #17
0
 /// <summary>
 /// Copy all given argument values into this object.
 /// </summary>
 /// <param name="other">
 /// The <see cref="Spring.Objects.Factory.Config.EventValues"/>
 /// to be used to populate this instance.
 /// </param>
 public void AddAll(EventValues other)
 {
     if (other != null)
     {
         foreach (IList handlers in other.EventHandlers.Values)
         {
             foreach (IEventHandlerValue handler in handlers)
             {
                 AddHandler (handler);
             }
         }
     }
 }