Package: StandardMessageResolver

StandardMessageResolver

nameinstructionbranchcomplexitylinemethod
StandardMessageResolver(LocaleResolver, PropertyResourceBundleResolver, Bundle, Bundle)
M: 0 C: 15
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
resolveLogEventMessage(String)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
resolveLogEventMessage(String, Locale)
M: 0 C: 22
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
resolveMessageInBundle(Bundle, String, List)
M: 1 C: 38
97%
M: 1 C: 5
83%
M: 1 C: 3
75%
M: 1 C: 7
88%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2008, 2010 VMware Inc.
3: * All rights reserved. This program and the accompanying materials
4: * are made available under the terms of the Eclipse Public License v1.0
5: * which accompanies this distribution, and is available at
6: * http://www.eclipse.org/legal/epl-v10.html
7: *
8: * Contributors:
9: * VMware Inc. - initial contribution
10: *******************************************************************************/
11:
12: package org.eclipse.virgo.medic.eventlog.impl;
13:
14: import java.util.List;
15: import java.util.Locale;
16: import java.util.MissingResourceException;
17: import java.util.PropertyResourceBundle;
18:
19: import org.osgi.framework.Bundle;
20:
21: public final class StandardMessageResolver implements MessageResolver {
22:
23: private static final String RESOURCE_BUNDLE_NAME = "EventLogMessages";
24:
25: private final LocaleResolver localeResolver;
26:
27: private final PropertyResourceBundleResolver resourceBundleLocator;
28:
29: private final Bundle primaryBundle;
30:
31: private final Bundle secondaryBundle;
32:
33: public StandardMessageResolver(LocaleResolver localeResolver, PropertyResourceBundleResolver resourceBundleLocator, Bundle primaryBundle,
34: Bundle secondaryBundle) {
35: this.localeResolver = localeResolver;
36: this.resourceBundleLocator = resourceBundleLocator;
37: this.primaryBundle = primaryBundle;
38: this.secondaryBundle = secondaryBundle;
39: }
40:
41: public String resolveLogEventMessage(String eventCode) {
42: return resolveLogEventMessage(eventCode, this.localeResolver.getLocale());
43: }
44:
45: public String resolveLogEventMessage(String eventCode, Locale locale) {
46: List<String> candidatePropertiesFileNames = ResourceBundleUtils.generateCandidatePropertiesFileNames(RESOURCE_BUNDLE_NAME, locale);
47:
48: String message = resolveMessageInBundle(this.primaryBundle, eventCode, candidatePropertiesFileNames);
49:
50:• if (message == null) {
51: message = resolveMessageInBundle(this.secondaryBundle, eventCode, candidatePropertiesFileNames);
52: }
53:
54: return message;
55: }
56:
57: private String resolveMessageInBundle(Bundle bundle, String key, List<String> candidatePropertiesFileNames) {
58:• for (String candidatePropertiesFileName : candidatePropertiesFileNames) {
59: List<PropertyResourceBundle> resourceBundles = this.resourceBundleLocator.getResourceBundles(bundle, candidatePropertiesFileName);
60:• for (PropertyResourceBundle resourceBundle : resourceBundles) {
61: try {
62: String string = resourceBundle.getString(key);
63:• if (string != null) {
64: return string;
65: }
66: } catch (MissingResourceException mre) {
67: // Continue searching
68: }
69: }
70: }
71: return null;
72: }
73: }