Tal Nisan has uploaded a new change for review. Change subject: core: Removed the ResXResourceReader class ......................................................................
core: Removed the ResXResourceReader class Removed the class ResXResourceReader from the compat module, this class was used to load the audit log messages from the properties file, it was used only in AuditLogDirector, the logic in the class was improved and moved to a method inside AuditLogDirector Change-Id: If60caa71d0b66d79279409ca534a419b89dcba75 Signed-off-by: Tal Nisan <tni...@redhat.com> --- D backend/manager/modules/compat/src/main/java/org/ovirt/engine/core/compat/backendcompat/ResXResourceReader.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java 2 files changed, 28 insertions(+), 46 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/27/11827/1 diff --git a/backend/manager/modules/compat/src/main/java/org/ovirt/engine/core/compat/backendcompat/ResXResourceReader.java b/backend/manager/modules/compat/src/main/java/org/ovirt/engine/core/compat/backendcompat/ResXResourceReader.java deleted file mode 100644 index b2fc02e..0000000 --- a/backend/manager/modules/compat/src/main/java/org/ovirt/engine/core/compat/backendcompat/ResXResourceReader.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.ovirt.engine.core.compat.backendcompat; - -import java.util.AbstractMap; -import java.util.Enumeration; -import java.util.LinkedList; -import java.util.Map.Entry; -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.ovirt.engine.core.compat.ApplicationException; - -public class ResXResourceReader extends LinkedList<Entry<String, Object>> { - - private static final long serialVersionUID = -1668354571890766752L; - private Log log = LogFactory.getLog(ResXResourceReader.class); - - // Although this is ResXReader the assumption is that the - // string is a path to a properties file. - public ResXResourceReader(String appErrorsFileName) { - try { - ResourceBundle bundle = ResourceBundle.getBundle(appErrorsFileName); - Enumeration<String> keys = bundle.getKeys(); - while (keys.hasMoreElements()) { - String key = keys.nextElement(); - String value = bundle.getString(key); - Entry<String, Object> entry = new AbstractMap.SimpleEntry<String, Object>(key, value); - this.addLast(entry); - } - } catch (MissingResourceException e) { - log.error("Could not load the resources for " + appErrorsFileName); - throw new ApplicationException(e); - } - } - -} diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java index e45126b..28f4435 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java @@ -6,16 +6,18 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.MissingResourceException; +import java.util.ResourceBundle; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.ovirt.engine.core.common.AuditLogSeverity; import org.ovirt.engine.core.common.AuditLogType; import org.ovirt.engine.core.common.businessentities.AuditLog; +import org.ovirt.engine.core.compat.ApplicationException; import org.ovirt.engine.core.compat.DateTime; import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.compat.backendcompat.PropertyInfo; -import org.ovirt.engine.core.compat.backendcompat.ResXResourceReader; import org.ovirt.engine.core.compat.backendcompat.TypeCompat; import org.ovirt.engine.core.dal.dbbroker.DbFacade; import org.ovirt.engine.core.utils.log.Log; @@ -29,6 +31,7 @@ new EnumMap<AuditLogType, AuditLogSeverity>(AuditLogType.class); private static final Pattern pattern = Pattern.compile("\\$\\{\\w*\\}"); // match ${<alphanumeric>...} static final String UNKNOWN_VARIABLE_VALUE = "<UNKNOWN>"; + private static final String APP_ERRORS_MESSAGES_FILE_NAME = "bundles/AuditLogMessages"; static { initMessages(); @@ -713,24 +716,40 @@ } private static void initMessages() { - ResXResourceReader reader = new ResXResourceReader("bundles/AuditLogMessages"); - for (Entry<String, Object> entry : reader) { + Map<String, String> messages = readMessagesFromBundle(); + + for (Entry<String, String> message : messages.entrySet()) { try { - AuditLogType type = AuditLogType.valueOf(entry.getKey()); + AuditLogType type = AuditLogType.valueOf(message.getKey()); if (!mMessages.containsKey(type)) { - mMessages.put(type, (String) entry.getValue()); + mMessages.put(type, message.getValue()); } else { - String secondPart = String.format(" First value : %1$s", mMessages.get(type)); - String thirdPart = String.format("Second value : %1$s", entry.getValue()); - log.errorFormat("Type {0} appears more then once in string table.{0}{1}", secondPart, thirdPart); + log.errorFormat("The type {0} appears more then once in audit log messages bundle with the values '{0}' and '{1}'", + mMessages.get(type), + message.getValue()); } } catch (Exception e) { - log.errorFormat("Cannot convert string {0} to AuditLogType", entry.getKey()); + log.errorFormat("Cannot convert the string {0} to AuditLogType, the key does not exist in the AuditLogType declared types", + message.getKey()); } } checkMessages(); } + private static Map<String, String> readMessagesFromBundle() { + try { + ResourceBundle bundle = ResourceBundle.getBundle(APP_ERRORS_MESSAGES_FILE_NAME); + Map<String, String> messages = new HashMap<String, String>(); + for (String key : bundle.keySet()) { + messages.put(key, bundle.getString(key)); + } + return messages; + } catch (MissingResourceException e) { + log.error("Could not load audit log messages from the file " + APP_ERRORS_MESSAGES_FILE_NAME); + throw new ApplicationException(e); + } + } + static void checkMessages() { AuditLogType[] values = AuditLogType.values(); if (values.length != mMessages.size()) { -- To view, visit http://gerrit.ovirt.org/11827 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If60caa71d0b66d79279409ca534a419b89dcba75 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Tal Nisan <tni...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches