Skip to content

Commit 4b0107e

Browse files
ar3emyulian-gaponenko
authored andcommitted
Add setMetaInfo to AbstractContextBasedITextEvent
DEVSIX-5664
1 parent 6fa8df2 commit 4b0107e

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed

commons/src/main/java/com/itextpdf/commons/actions/AbstractContextBasedITextEvent.java

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ This file is part of the iText (R) project.
2424

2525
import com.itextpdf.commons.actions.contexts.IMetaInfo;
2626
import com.itextpdf.commons.actions.data.ProductData;
27+
import com.itextpdf.commons.exceptions.CommonsExceptionMessageConstant;
2728

2829
/**
2930
* Represents a context-based event. See also {@link AbstractContextBasedEventHandler}.
3031
* Only for internal usage.
3132
*/
3233
public abstract class AbstractContextBasedITextEvent extends AbstractProductITextEvent {
33-
private final IMetaInfo metaInfo;
34+
private IMetaInfo metaInfo;
3435

3536
/**
3637
* Creates an event containing auxiliary meta data.
@@ -44,20 +45,34 @@ protected AbstractContextBasedITextEvent(ProductData productData, IMetaInfo meta
4445
}
4546

4647
/**
47-
* Obtains stored meta info associated with the event.
48+
* Obtains the current event context class.
4849
*
49-
* @return meta info
50+
* @return context class
5051
*/
51-
IMetaInfo getMetaInfo() {
52-
return metaInfo;
52+
public Class<?> getClassFromContext() {
53+
return this.getClass();
5354
}
5455

5556
/**
56-
* Obtains a current event context class.
57+
* Sets meta info.
5758
*
58-
* @return context class
59+
* @param metaInfo meta info
60+
*
61+
* @throws IllegalStateException if the current event already has not null meta info associated with it
5962
*/
60-
public Class<?> getClassFromContext() {
61-
return this.getClass();
63+
public void setMetaInfo(IMetaInfo metaInfo) throws IllegalStateException {
64+
if (this.metaInfo != null) {
65+
throw new IllegalStateException(CommonsExceptionMessageConstant.META_INFO_SHOULDNT_BE_NULL);
66+
}
67+
this.metaInfo = metaInfo;
68+
}
69+
70+
/**
71+
* Obtains stored meta info associated with the event.
72+
*
73+
* @return meta info
74+
*/
75+
IMetaInfo getMetaInfo() {
76+
return metaInfo;
6277
}
6378
}

commons/src/main/java/com/itextpdf/commons/exceptions/CommonsExceptionMessageConstant.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,13 @@ public final class CommonsExceptionMessageConstant {
3434
* <li>1st is a new element identifier;
3535
* </ul>
3636
*/
37-
public static final String ELEMENT_ALREADY_HAS_IDENTIFIER =
38-
"Element already has sequence id: {0}, new id {1} will be ignored";
39-
public static final String INVALID_USAGE_CONFIGURATION_FORBIDDEN =
40-
"Invalid usage of placeholder \"{0}\": any configuration is forbidden";
41-
public static final String INVALID_USAGE_FORMAT_REQUIRED =
42-
"Invalid usage of placeholder \"{0}\": format is required";
43-
public static final String NO_EVENTS_WERE_REGISTERED_FOR_THE_DOCUMENT =
44-
"No events were registered for the document!";
37+
public static final String ELEMENT_ALREADY_HAS_IDENTIFIER = "Element already has sequence id: {0}, new id {1} " +
38+
"will be ignored";
39+
public static final String INVALID_USAGE_CONFIGURATION_FORBIDDEN = "Invalid usage of placeholder \"{0}\": any "
40+
+ "configuration is forbidden";
41+
public static final String INVALID_USAGE_FORMAT_REQUIRED = "Invalid usage of placeholder \"{0}\": format is required";
42+
public static final String META_INFO_SHOULDNT_BE_NULL = "Meta info shouldn't be null";
43+
public static final String NO_EVENTS_WERE_REGISTERED_FOR_THE_DOCUMENT = "No events were registered for the document!";
4544
public static final String PATTERN_CONTAINS_OPEN_QUOTATION = "Pattern contains open quotation!";
4645
public static final String PATTERN_CONTAINS_UNEXPECTED_CHARACTER = "Pattern contains unexpected character {0}";
4746
public static final String PATTERN_CONTAINS_UNEXPECTED_COMPONENT = "Pattern contains unexpected component {0}";

0 commit comments

Comments
 (0)