Skip to content

Commit 5572681

Browse files
Snipxyulian-gaponenko
authored andcommitted
Add possibility to unregister namespaces from ContextManager
DEVSIX-5795 Autoported commit. Original commit hash: [96c7ed6d4]
1 parent 68c8be4 commit 5572681

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,19 @@ public virtual void GetRecognisedNamespaceForSpecificNamespaceTest() {
7575
[NUnit.Framework.Test]
7676
public virtual void NotRegisteredNamespaceTest() {
7777
String notRegisteredNamespace = "com.hello.world";
78-
NUnit.Framework.Assert.AreEqual(null, ContextManager.GetInstance().GetRecognisedNamespace(notRegisteredNamespace
78+
NUnit.Framework.Assert.IsNull(ContextManager.GetInstance().GetRecognisedNamespace(notRegisteredNamespace));
79+
}
80+
81+
[NUnit.Framework.Test]
82+
public virtual void UnregisterNamespaceTest() {
83+
String testNamespace = "com.hello.world";
84+
ContextManager manager = new ContextManager();
85+
NUnit.Framework.Assert.IsNull(manager.GetRecognisedNamespace(testNamespace));
86+
manager.RegisterGenericContextForProducts(JavaUtil.ArraysAsList(testNamespace), JavaUtil.ArraysAsList("myProduct"
7987
));
88+
NUnit.Framework.Assert.AreEqual(testNamespace, manager.GetRecognisedNamespace(testNamespace + ".MyClass"));
89+
manager.UnregisterGenericContextForProducts(JavaUtil.ArraysAsList(testNamespace));
90+
NUnit.Framework.Assert.IsNull(manager.GetRecognisedNamespace(testNamespace));
8091
}
8192

8293
[NUnit.Framework.Test]

itext/itext.commons/itext/commons/actions/contexts/AbstractContextManagerConfigurationEvent.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,9 @@ protected internal virtual void RegisterGenericContext(ICollection<String> names
3737
products) {
3838
ContextManager.GetInstance().RegisterGenericContextForProducts(namespaces, products);
3939
}
40+
41+
protected internal virtual void UnregisterGenericContext(ICollection<String> namespaces) {
42+
ContextManager.GetInstance().UnregisterGenericContextForProducts(namespaces);
43+
}
4044
}
4145
}

itext/itext.commons/itext/commons/actions/contexts/ContextManager.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@ internal virtual void RegisterGenericContextForProducts(ICollection<String> name
144144
RegisterGenericContextForProducts(namespaces, JavaCollectionsUtil.EmptyList<String>(), products);
145145
}
146146

147+
// TODO DEVSIX-5311 consider renaming to be in sync with renamed registerGenericContextForProducts
148+
internal virtual void UnregisterGenericContextForProducts(ICollection<String> namespaces) {
149+
foreach (String @namespace in namespaces) {
150+
UnregisterContext(@namespace);
151+
}
152+
}
153+
147154
private IContext GetNamespaceMapping(String @namespace) {
148155
if (@namespace != null) {
149156
return contextMappings.Get(@namespace);
@@ -171,6 +178,10 @@ private void RegisterContext(String @namespace, IContext context) {
171178
contextMappings.Put(@namespace, context);
172179
}
173180

181+
private void UnregisterContext(String @namespace) {
182+
contextMappings.JRemove(@namespace);
183+
}
184+
174185
private class LengthComparator : IComparer<String> {
175186
public virtual int Compare(String o1, String o2) {
176187
int lengthComparison = -JavaUtil.IntegerCompare(o1.Length, o2.Length);

0 commit comments

Comments
 (0)