diff options
Diffstat (limited to 'src/main/java/org/uic/barcode')
4 files changed, 76 insertions, 15 deletions
diff --git a/src/main/java/org/uic/barcode/asn1/datatypes/Asn1SequenceOf.java b/src/main/java/org/uic/barcode/asn1/datatypes/Asn1SequenceOf.java index 4924b50..8e24222 100644 --- a/src/main/java/org/uic/barcode/asn1/datatypes/Asn1SequenceOf.java +++ b/src/main/java/org/uic/barcode/asn1/datatypes/Asn1SequenceOf.java @@ -3,8 +3,7 @@ package org.uic.barcode.asn1.datatypes; import java.lang.reflect.ParameterizedType; import java.util.*; -import org.uic.barcode.logger.Logger; -import org.uic.barcode.logger.LoggerFactory; +import org.uic.barcode.asn1.uper.UperEncoder; /** @@ -35,8 +34,7 @@ import org.uic.barcode.logger.LoggerFactory; * @param <T> type of elements contained. */ public abstract class Asn1SequenceOf<T> extends AbstractList<T> { - private final static Logger logger = LoggerFactory.getLogger("asnLogger"); - + private final List<T> bakingList; @Override public T get(int index) { return bakingList.get(index); } @@ -45,7 +43,7 @@ public abstract class Asn1SequenceOf<T> extends AbstractList<T> { public Asn1SequenceOf() { this(new ArrayList<T>()); } public Asn1SequenceOf(Collection<T> coll) { - logger.debug(String.format("Instantiating Sequence Of %s with %s", + UperEncoder.logger.debug(String.format("Instantiating Sequence Of %s with %s", ((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments()[0], coll)); bakingList = new ArrayList<>(coll); diff --git a/src/main/java/org/uic/barcode/asn1/uper/StringCoder.java b/src/main/java/org/uic/barcode/asn1/uper/StringCoder.java index a504096..94e0aad 100644 --- a/src/main/java/org/uic/barcode/asn1/uper/StringCoder.java +++ b/src/main/java/org/uic/barcode/asn1/uper/StringCoder.java @@ -17,14 +17,10 @@ import org.uic.barcode.asn1.datatypes.DefaultAlphabet; import org.uic.barcode.asn1.datatypes.FixedSize; import org.uic.barcode.asn1.datatypes.RestrictedString; import org.uic.barcode.asn1.datatypes.SizeRange; -import org.uic.barcode.logger.Logger; -import org.uic.barcode.logger.LoggerFactory; class StringCoder implements Decoder, Encoder { - private static final Logger LOGGER = LoggerFactory.getLogger("asnLogger"); - @Override public <T> boolean canEncode(T obj, Annotation[] extraAnnotations) { return obj instanceof String || obj instanceof Asn1String; } @@ -231,7 +227,7 @@ class StringCoder implements Decoder, Encoder { try { chars = UperEncoder.instantiate(restriction.alphabet()).chars().toCharArray(); } catch (IllegalArgumentException e) { - LOGGER.info("Uninstantinatable alphabet ", e); + UperEncoder.logger.info("Uninstantinatable alphabet ", e); throw new IllegalArgumentException("Uninstantinatable alphabet" + restriction.alphabet().getName()); } if (BigInteger.valueOf(chars.length - 1).bitLength() < BigInteger.valueOf(126) @@ -293,7 +289,7 @@ class StringCoder implements Decoder, Encoder { try { chars = UperEncoder.instantiate(restrictionAnnotation.alphabet()).chars().toCharArray(); } catch (IllegalArgumentException e) { - LOGGER.info("Uninstantinatable alphabet ", e); + UperEncoder.logger.info("Uninstantinatable alphabet ", e); throw new IllegalArgumentException("Uninstantinatable alphabet " + restrictionAnnotation.alphabet().getName()); } if (BigInteger.valueOf(chars.length - 1).bitLength() < BigInteger.valueOf(126) diff --git a/src/main/java/org/uic/barcode/logger/Logger.java b/src/main/java/org/uic/barcode/logger/Logger.java index b536154..baae70d 100644 --- a/src/main/java/org/uic/barcode/logger/Logger.java +++ b/src/main/java/org/uic/barcode/logger/Logger.java @@ -3,11 +3,23 @@ package org.uic.barcode.logger; import java.util.logging.Level;
-public class Logger {
+public class Logger {
+
+ private boolean consoleLog = false;
+
+ public Logger(boolean consoleLog) {
+ this.consoleLog = consoleLog;
+ }
+
+ public Logger() {
+ this.consoleLog = false;
+ }
public void debug(String text){
java.util.logging.Logger.getGlobal().log(Level.FINEST,text);
- System.out.println(text);
+ if (consoleLog) {
+ System.out.println(text);
+ }
}
public void log(Level level,String text){
@@ -17,6 +29,10 @@ public class Logger { public void info(String text, IllegalArgumentException e) {
java.util.logging.Logger.getGlobal().log(Level.INFO,text);
}
+
+ public void activateConsoleLog(boolean consoleLogActive) {
+ this.consoleLog = consoleLogActive;
+ }
}
diff --git a/src/main/java/org/uic/barcode/logger/LoggerFactory.java b/src/main/java/org/uic/barcode/logger/LoggerFactory.java index 0a1a83c..be5736e 100644 --- a/src/main/java/org/uic/barcode/logger/LoggerFactory.java +++ b/src/main/java/org/uic/barcode/logger/LoggerFactory.java @@ -1,9 +1,60 @@ package org.uic.barcode.logger;
+import java.util.HashMap;
+
+/**
+ * A factory for creating Logger objects. This allows to replace the default logger by your own loggers.
+ */
public class LoggerFactory {
+
+ /** The registered loggers. */
+ private static HashMap<String,Logger> registeredLoggers = new HashMap<String,Logger>();
+
+ /** The activate console log. */
+ public static boolean activateConsoleLog = false;
+
+ /**
+ * Gets the logger.
+ *
+ * @param name the name of the logger. UperEncoder uses asnLogger
+ * @return the logger
+ */
public static Logger getLogger(String name) {
- return new Logger();
- }
+ Logger logger = registeredLoggers.get(name);
+ if (logger == null) {
+ logger = new Logger(activateConsoleLog);
+ registeredLoggers.put(name, logger);
+ }
+ return logger;
+ }
+ /**
+ * Checks if console log is on.
+ *
+ * @return true, if console log is on
+ */
+ public static boolean isActivateConsoleLog() {
+ return activateConsoleLog;
+ }
+
+ /**
+ * Sets the console log on
+ *
+ * @param activateConsoleLog the new activate console log
+ */
+ public static void setActivateConsoleLog(boolean activateConsoleLog) {
+ LoggerFactory.activateConsoleLog = activateConsoleLog;
+ }
+
+ /**
+ * Register logger.
+ *
+ * @param name the name of the logger
+ * @param logger the logger to be registered
+ */
+ public void registerLogger(String name, Logger logger) {
+ registeredLoggers.put(name, logger);
+ }
+
}
|