Skip to content

Commit fff8592

Browse files
Egor Martsynkovskyintrofog
authored andcommitted
Clean up context manager mechanism Rename some classes related to DEVSIX-5311
DEVSIX-5659 Autoported commit. Original commit hash: [dba9ad6]
1 parent 225644e commit fff8592

File tree

14 files changed

+56
-99
lines changed

14 files changed

+56
-99
lines changed

itext.tests/itext.commons.tests/itext/commons/actions/AbstractContextBasedEventHandlerTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public virtual bool WasInvoked() {
7676
}
7777
}
7878

79-
private class UnknownEvent : IBaseEvent {
79+
private class UnknownEvent : IEvent {
8080
}
8181
}
8282
}

itext.tests/itext.commons.tests/itext/commons/actions/EventManagerTest.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ public virtual void ConfigurationEventTest() {
4040
[NUnit.Framework.Test]
4141
public virtual void ThrowSomeExceptionsTest() {
4242
EventManager eventManager = EventManager.GetInstance();
43-
IBaseEventHandler handler1 = new EventManagerTest.ThrowArithmeticExpHandler();
44-
IBaseEventHandler handler2 = new EventManagerTest.ThrowIllegalArgumentExpHandler();
43+
IEventHandler handler1 = new EventManagerTest.ThrowArithmeticExpHandler();
44+
IEventHandler handler2 = new EventManagerTest.ThrowIllegalArgumentExpHandler();
4545
eventManager.Register(handler1);
4646
eventManager.Register(handler2);
4747
SequenceId sequenceId = new SequenceId();
@@ -63,7 +63,7 @@ public virtual void ThrowSomeExceptionsTest() {
6363
[NUnit.Framework.Test]
6464
public virtual void ThrowOneUncheckedExceptionsTest() {
6565
EventManager eventManager = EventManager.GetInstance();
66-
IBaseEventHandler handler1 = new EventManagerTest.ThrowArithmeticExpHandler();
66+
IEventHandler handler1 = new EventManagerTest.ThrowArithmeticExpHandler();
6767
eventManager.Register(handler1);
6868
try {
6969
SequenceId sequenceId = new SequenceId();
@@ -81,7 +81,7 @@ public virtual void ThrowOneUncheckedExceptionsTest() {
8181
[NUnit.Framework.Test]
8282
public virtual void ConfigureHandlersTest() {
8383
EventManager eventManager = EventManager.GetInstance();
84-
IBaseEventHandler handler = new EventManagerTest.ThrowArithmeticExpHandler();
84+
IEventHandler handler = new EventManagerTest.ThrowArithmeticExpHandler();
8585
NUnit.Framework.Assert.IsFalse(eventManager.IsRegistered(handler));
8686
eventManager.Register(handler);
8787
NUnit.Framework.Assert.IsTrue(eventManager.IsRegistered(handler));
@@ -90,14 +90,14 @@ public virtual void ConfigureHandlersTest() {
9090
NUnit.Framework.Assert.IsFalse(eventManager.Unregister(handler));
9191
}
9292

93-
private class ThrowArithmeticExpHandler : IBaseEventHandler {
94-
public virtual void OnEvent(IBaseEvent @event) {
93+
private class ThrowArithmeticExpHandler : IEventHandler {
94+
public virtual void OnEvent(IEvent @event) {
9595
throw new ArithmeticException("ThrowArithmeticExpHandler");
9696
}
9797
}
9898

99-
private class ThrowIllegalArgumentExpHandler : IBaseEventHandler {
100-
public virtual void OnEvent(IBaseEvent @event) {
99+
private class ThrowIllegalArgumentExpHandler : IEventHandler {
100+
public virtual void OnEvent(IEvent @event) {
101101
throw new ArgumentException("ThrowIllegalArgumentExpHandler");
102102
}
103103
}

itext.tests/itext.commons.tests/itext/commons/actions/contexts/ContextManagerTest.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,19 @@ public virtual void GetRecognisedNamespaceForSpecificNamespaceTest() {
5353
String innerNamespaces = NamespaceConstant.PDF_HTML.ToLowerInvariant();
5454
NUnit.Framework.Assert.IsTrue(innerNamespaces.StartsWith(outerNamespaces));
5555
ContextManager managerOuterBeforeInner = new ContextManager();
56-
managerOuterBeforeInner.RegisterGenericContextForProducts(JavaCollectionsUtil.SingletonList(outerNamespaces
57-
), JavaCollectionsUtil.EmptyList<String>());
58-
managerOuterBeforeInner.RegisterGenericContextForProducts(JavaCollectionsUtil.SingletonList(innerNamespaces
59-
), JavaCollectionsUtil.EmptyList<String>());
56+
managerOuterBeforeInner.RegisterGenericContext(JavaCollectionsUtil.SingletonList(outerNamespaces), JavaCollectionsUtil
57+
.EmptyList<String>());
58+
managerOuterBeforeInner.RegisterGenericContext(JavaCollectionsUtil.SingletonList(innerNamespaces), JavaCollectionsUtil
59+
.EmptyList<String>());
6060
NUnit.Framework.Assert.AreEqual(outerNamespaces, managerOuterBeforeInner.GetRecognisedNamespace(outerNamespaces
6161
));
6262
NUnit.Framework.Assert.AreEqual(innerNamespaces, managerOuterBeforeInner.GetRecognisedNamespace(innerNamespaces
6363
));
6464
ContextManager managerInnerBeforeOuter = new ContextManager();
65-
managerInnerBeforeOuter.RegisterGenericContextForProducts(JavaCollectionsUtil.SingletonList(innerNamespaces
66-
), JavaCollectionsUtil.EmptyList<String>());
67-
managerInnerBeforeOuter.RegisterGenericContextForProducts(JavaCollectionsUtil.SingletonList(outerNamespaces
68-
), JavaCollectionsUtil.EmptyList<String>());
65+
managerInnerBeforeOuter.RegisterGenericContext(JavaCollectionsUtil.SingletonList(innerNamespaces), JavaCollectionsUtil
66+
.EmptyList<String>());
67+
managerInnerBeforeOuter.RegisterGenericContext(JavaCollectionsUtil.SingletonList(outerNamespaces), JavaCollectionsUtil
68+
.EmptyList<String>());
6969
NUnit.Framework.Assert.AreEqual(outerNamespaces, managerInnerBeforeOuter.GetRecognisedNamespace(outerNamespaces
7070
));
7171
NUnit.Framework.Assert.AreEqual(innerNamespaces, managerInnerBeforeOuter.GetRecognisedNamespace(innerNamespaces
@@ -83,10 +83,9 @@ public virtual void UnregisterNamespaceTest() {
8383
String testNamespace = "com.hello.world";
8484
ContextManager manager = new ContextManager();
8585
NUnit.Framework.Assert.IsNull(manager.GetRecognisedNamespace(testNamespace));
86-
manager.RegisterGenericContextForProducts(JavaUtil.ArraysAsList(testNamespace), JavaUtil.ArraysAsList("myProduct"
87-
));
86+
manager.RegisterGenericContext(JavaUtil.ArraysAsList(testNamespace), JavaUtil.ArraysAsList("myProduct"));
8887
NUnit.Framework.Assert.AreEqual(testNamespace, manager.GetRecognisedNamespace(testNamespace + ".MyClass"));
89-
manager.UnregisterGenericContextForProducts(JavaUtil.ArraysAsList(testNamespace));
88+
manager.UnregisterContext(JavaUtil.ArraysAsList(testNamespace));
9089
NUnit.Framework.Assert.IsNull(manager.GetRecognisedNamespace(testNamespace));
9190
}
9291

itext.tests/itext.kernel.tests/itext/kernel/pdf/statistics/NumberOfPagesStatisticsTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ public virtual void SeveralPdfDocumentsTest() {
9898
NUnit.Framework.Assert.AreEqual(1, numberOfPagesEvents[2].GetNumberOfPages());
9999
}
100100

101-
private class NumberOfPagesStatisticsHandler : IBaseEventHandler {
101+
private class NumberOfPagesStatisticsHandler : IEventHandler {
102102
private IList<NumberOfPagesStatisticsEvent> numberOfPagesEvents = new List<NumberOfPagesStatisticsEvent>();
103103

104-
public virtual void OnEvent(IBaseEvent @event) {
104+
public virtual void OnEvent(IEvent @event) {
105105
if (!(@event is NumberOfPagesStatisticsEvent)) {
106106
return;
107107
}

itext.tests/itext.kernel.tests/itext/kernel/pdf/statistics/SizeOfPdfStatisticsTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ public virtual void SeveralPdfDocumentsTest() {
108108
());
109109
}
110110

111-
private class SizeOfPdfStatisticsHandler : IBaseEventHandler {
111+
private class SizeOfPdfStatisticsHandler : IEventHandler {
112112
private IList<SizeOfPdfStatisticsEvent> sizeOfPdfEvents = new List<SizeOfPdfStatisticsEvent>();
113113

114-
public virtual void OnEvent(IBaseEvent @event) {
114+
public virtual void OnEvent(IEvent @event) {
115115
if (!(@event is SizeOfPdfStatisticsEvent)) {
116116
return;
117117
}

itext/itext.commons/itext/commons/actions/AbstractContextBasedEventHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ You should have received a copy of the GNU Affero General Public License
2424

2525
namespace iText.Commons.Actions {
2626
/// <summary>Base class for events handling depending on the context.</summary>
27-
public abstract class AbstractContextBasedEventHandler : IBaseEventHandler {
27+
public abstract class AbstractContextBasedEventHandler : IEventHandler {
2828
private readonly IContext defaultContext;
2929

3030
/// <summary>
@@ -42,7 +42,7 @@ protected internal AbstractContextBasedEventHandler(IContext onUnknownContext)
4242
/// <see cref="OnAcceptedEvent(AbstractContextBasedITextEvent)"/>.
4343
/// </summary>
4444
/// <param name="event">to handle</param>
45-
public void OnEvent(IBaseEvent @event) {
45+
public void OnEvent(IEvent @event) {
4646
if (!(@event is AbstractContextBasedITextEvent)) {
4747
return;
4848
}

itext/itext.commons/itext/commons/actions/AbstractITextEvent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ You should have received a copy of the GNU Affero General Public License
2626

2727
namespace iText.Commons.Actions {
2828
/// <summary>Abstract class which defines events only for internal usage.</summary>
29-
public abstract class AbstractITextEvent : IBaseEvent {
29+
public abstract class AbstractITextEvent : IEvent {
3030
private const String ONLY_FOR_INTERNAL_USE = "AbstractITextEvent is only for internal usage.";
3131

3232
private static readonly IDictionary<String, Object> INTERNAL_PACKAGES = new ConcurrentDictionary<String, Object

itext/itext.commons/itext/commons/actions/EventManager.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public sealed class EventManager {
3636
private static readonly iText.Commons.Actions.EventManager INSTANCE = new iText.Commons.Actions.EventManager
3737
();
3838

39-
private readonly ICollection<IBaseEventHandler> handlers = new LinkedHashSet<IBaseEventHandler>();
39+
private readonly ICollection<IEventHandler> handlers = new LinkedHashSet<IEventHandler>();
4040

4141
private EventManager() {
4242
handlers.Add(ProductEventHandler.INSTANCE);
@@ -50,9 +50,9 @@ public static iText.Commons.Actions.EventManager GetInstance() {
5050

5151
/// <summary>Handles the event.</summary>
5252
/// <param name="event">to handle</param>
53-
public void OnEvent(IBaseEvent @event) {
53+
public void OnEvent(IEvent @event) {
5454
IList<Exception> caughtExceptions = new List<Exception>();
55-
foreach (IBaseEventHandler handler in handlers) {
55+
foreach (IEventHandler handler in handlers) {
5656
try {
5757
handler.OnEvent(@event);
5858
}
@@ -79,11 +79,11 @@ public void OnEvent(IBaseEvent @event) {
7979

8080
/// <summary>
8181
/// Add new
82-
/// <see cref="IBaseEventHandler"/>
82+
/// <see cref="IEventHandler"/>
8383
/// to the event handling process.
8484
/// </summary>
8585
/// <param name="handler">is a handler to add</param>
86-
public void Register(IBaseEventHandler handler) {
86+
public void Register(IEventHandler handler) {
8787
if (handler != null) {
8888
handlers.Add(handler);
8989
}
@@ -92,7 +92,7 @@ public void Register(IBaseEventHandler handler) {
9292
/// <summary>Check if the handler was registered for event handling process.</summary>
9393
/// <param name="handler">is a handler to check</param>
9494
/// <returns>true if handler has been already registered and false otherwise</returns>
95-
public bool IsRegistered(IBaseEventHandler handler) {
95+
public bool IsRegistered(IEventHandler handler) {
9696
if (handler != null) {
9797
return handlers.Contains(handler);
9898
}
@@ -105,7 +105,7 @@ public bool IsRegistered(IBaseEventHandler handler) {
105105
/// true if the handler had been registered previously and was removed. False if the
106106
/// handler was not found among registered handlers
107107
/// </returns>
108-
public bool Unregister(IBaseEventHandler handler) {
108+
public bool Unregister(IEventHandler handler) {
109109
if (handler != null) {
110110
return handlers.Remove(handler);
111111
}

itext/itext.commons/itext/commons/actions/IBaseEvent.cs renamed to itext/itext.commons/itext/commons/actions/IEvent.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ You should have received a copy of the GNU Affero General Public License
2222
*/
2323
namespace iText.Commons.Actions {
2424
/// <summary>Base marker interface for any generated event of any source.</summary>
25-
/// <remarks>
26-
/// Base marker interface for any generated event of any source.
27-
/// <para />TODO: DEVSIX-5311 rename it IEvent when the oldest mechanism is deleted
28-
/// </remarks>
29-
public interface IBaseEvent {
25+
public interface IEvent {
3026
}
3127
}

itext/itext.commons/itext/commons/actions/IBaseEventHandler.cs renamed to itext/itext.commons/itext/commons/actions/IEventHandler.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,9 @@ You should have received a copy of the GNU Affero General Public License
2222
*/
2323
namespace iText.Commons.Actions {
2424
/// <summary>The interface for an event handler.</summary>
25-
/// <remarks>
26-
/// The interface for an event handler.
27-
/// <para />TODO: DEVSIX-5311 rename it IEventHandler when the oldest mechanism is deleted
28-
/// </remarks>
29-
public interface IBaseEventHandler {
25+
public interface IEventHandler {
3026
/// <summary>Handles the event.</summary>
3127
/// <param name="event">to handle</param>
32-
void OnEvent(IBaseEvent @event);
28+
void OnEvent(IEvent @event);
3329
}
3430
}

0 commit comments

Comments
 (0)