Skip to content

Commit b84e364

Browse files
ar3emyulian-gaponenko
authored andcommitted
Add setMetaInfo to AbstractContextBasedITextEvent
DEVSIX-5664
1 parent a5497fd commit b84e364

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

itext/itext.commons/itext/commons/actions/AbstractContextBasedITextEvent.cs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ You should have received a copy of the GNU Affero General Public License
2323
using System;
2424
using iText.Commons.Actions.Contexts;
2525
using iText.Commons.Actions.Data;
26+
using iText.Commons.Exceptions;
2627

2728
namespace iText.Commons.Actions {
2829
/// <summary>Represents a context-based event.</summary>
@@ -32,7 +33,7 @@ namespace iText.Commons.Actions {
3233
/// Only for internal usage.
3334
/// </remarks>
3435
public abstract class AbstractContextBasedITextEvent : AbstractProductITextEvent {
35-
private readonly IMetaInfo metaInfo;
36+
private IMetaInfo metaInfo;
3637

3738
/// <summary>Creates an event containing auxiliary meta data.</summary>
3839
/// <param name="productData">is a description of the product which has generated an event</param>
@@ -42,16 +43,25 @@ protected internal AbstractContextBasedITextEvent(ProductData productData, IMeta
4243
this.metaInfo = metaInfo;
4344
}
4445

46+
/// <summary>Obtains the current event context class.</summary>
47+
/// <returns>context class</returns>
48+
public virtual Type GetClassFromContext() {
49+
return this.GetType();
50+
}
51+
52+
/// <summary>Sets meta info.</summary>
53+
/// <param name="metaInfo">meta info</param>
54+
public virtual void SetMetaInfo(IMetaInfo metaInfo) {
55+
if (this.metaInfo != null) {
56+
throw new InvalidOperationException(CommonsExceptionMessageConstant.META_INFO_SHOULDNT_BE_NULL);
57+
}
58+
this.metaInfo = metaInfo;
59+
}
60+
4561
/// <summary>Obtains stored meta info associated with the event.</summary>
4662
/// <returns>meta info</returns>
4763
internal virtual IMetaInfo GetMetaInfo() {
4864
return metaInfo;
4965
}
50-
51-
/// <summary>Obtains a current event context class.</summary>
52-
/// <returns>context class</returns>
53-
public virtual Type GetClassFromContext() {
54-
return this.GetType();
55-
}
5666
}
5767
}

itext/itext.commons/itext/commons/exceptions/CommonsExceptionMessageConstant.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,16 @@ public sealed class CommonsExceptionMessageConstant {
3535
/// </description></item>
3636
/// </list>
3737
/// </remarks>
38-
public const String ELEMENT_ALREADY_HAS_IDENTIFIER = "Element already has sequence id: {0}, new id {1} will be ignored";
38+
public const String ELEMENT_ALREADY_HAS_IDENTIFIER = "Element already has sequence id: {0}, new id {1} " +
39+
"will be ignored";
3940

40-
public const String INVALID_USAGE_CONFIGURATION_FORBIDDEN = "Invalid usage of placeholder \"{0}\": any configuration is forbidden";
41+
public const String INVALID_USAGE_CONFIGURATION_FORBIDDEN = "Invalid usage of placeholder \"{0}\": any " +
42+
"configuration is forbidden";
4143

4244
public const String INVALID_USAGE_FORMAT_REQUIRED = "Invalid usage of placeholder \"{0}\": format is required";
4345

46+
public const String META_INFO_SHOULDNT_BE_NULL = "Meta info shouldn't be null";
47+
4448
public const String NO_EVENTS_WERE_REGISTERED_FOR_THE_DOCUMENT = "No events were registered for the document!";
4549

4650
public const String PATTERN_CONTAINS_OPEN_QUOTATION = "Pattern contains open quotation!";

0 commit comments

Comments
 (0)