コード例 #1
0
        public void OneEventValue()
        {
            EventValues eventValues = new EventValues();

            eventValues.AddHandler(new MyEventHandler());
            Assert.AreEqual(1, eventValues.Events.Count);
        }
コード例 #2
0
        public void NullEventHandlerValue()
        {
            EventValues eventValues = new EventValues();

            eventValues.AddAll(null);
            Assert.AreEqual(0, eventValues.Events.Count);
        }
コード例 #3
0
			public void TwoEventHandlersForSameEvent()
		{
			EventValues eventValues = new EventValues();
			eventValues.AddHandler( new MyEventHandler());
			eventValues.AddHandler( new MyEventHandler());
			Assert.AreEqual( 1, eventValues.Events.Count );
		}
コード例 #4
0
 /// <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;
 }
コード例 #5
0
			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 );
		}
コード例 #6
0
        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);
        }
コード例 #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);
             }
         }
     }
 }
コード例 #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]);
             }
         }
     }
 }
コード例 #9
0
        /// <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;
        }
コード例 #10
0
 /// <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;
 }
コード例 #11
0
        /// <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);
        }
コード例 #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);
 }
コード例 #13
0
        public void EmptyEventValues()
        {
            EventValues eventValues = new EventValues();

            Assert.AreEqual(0, eventValues.Events.Count);
        }
コード例 #14
0
			public void NullEventHandlerValue()
		{
			EventValues eventValues = new EventValues();
			eventValues.AddAll( null );
			Assert.AreEqual( 0, eventValues.Events.Count );
		}
コード例 #15
0
			public void EmptyEventValues()
		{
			EventValues eventValues = new EventValues();
			Assert.AreEqual( 0, eventValues.Events.Count );
		}
コード例 #16
0
ファイル: EventValues.cs プロジェクト: smnbss/spring-net
 /// <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);
 }
コード例 #17
0
ファイル: EventValues.cs プロジェクト: smnbss/spring-net
 /// <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);
             }
         }
     }
 }