aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/gv/egiz/pdfas/placeholder/SignaturePlaceholderContext.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/gv/egiz/pdfas/placeholder/SignaturePlaceholderContext.java')
-rw-r--r--src/main/java/at/gv/egiz/pdfas/placeholder/SignaturePlaceholderContext.java49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/main/java/at/gv/egiz/pdfas/placeholder/SignaturePlaceholderContext.java b/src/main/java/at/gv/egiz/pdfas/placeholder/SignaturePlaceholderContext.java
new file mode 100644
index 0000000..e8c157c
--- /dev/null
+++ b/src/main/java/at/gv/egiz/pdfas/placeholder/SignaturePlaceholderContext.java
@@ -0,0 +1,49 @@
+package at.gv.egiz.pdfas.placeholder;
+
+/**
+ * Store and retrieve {@link SignaturePlaceholderData} in/from a thread local context.
+ *
+ * @author exthex
+ *
+ */
+public class SignaturePlaceholderContext {
+
+ private ThreadLocal sigHolder = new ThreadLocal();
+
+ private static SignaturePlaceholderContext instance = new SignaturePlaceholderContext();
+
+ /**
+ * Constructor. Private because this is a singleton.
+ */
+ private SignaturePlaceholderContext() {
+
+ }
+
+ /**
+ * Get the {@link SignaturePlaceholderData} which is currently bound to this thread.
+ * Might be null.
+ *
+ * @return
+ */
+ public static SignaturePlaceholderData getSignaturePlaceholderData(){
+ return (SignaturePlaceholderData)instance.sigHolder.get();
+ }
+
+ /**
+ *
+ * @return true if there is currently a {@link SignaturePlaceholderData} bound to this thread, false otherwise.
+ */
+ public static boolean isSignaturePlaceholderDataSet() {
+ return instance.sigHolder.get() != null;
+ }
+
+ /**
+ * Bind a {@link SignaturePlaceholderData} to this thread.
+ * If the given data is null, the context will be cleared.
+ *
+ * @param data if null, clears the ThreadLocal, else binds the data to the current thread.
+ */
+ public static void setSignaturePlaceholderData(SignaturePlaceholderData data) {
+ instance.sigHolder.set(data);
+ }
+}