001: /*
002: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package com.tc.bundles;
006:
007: import org.osgi.framework.BundleException;
008:
009: import com.tc.logging.CustomerLogging;
010: import com.tc.logging.TCLogger;
011:
012: import java.text.MessageFormat;
013: import java.util.Locale;
014: import java.util.MissingResourceException;
015: import java.util.ResourceBundle;
016:
017: abstract class AbstractEmbeddedOSGiRuntime implements
018: EmbeddedOSGiRuntime {
019:
020: static class Message {
021:
022: static final Message INSTALLING_BUNDLE = new Message(
023: "installing.bundle");
024: static final Message BUNDLE_INSTALLED = new Message(
025: "bundle.installed");
026: static final Message UNINSTALLING_BUNDLE = new Message(
027: "uninstalling.bundle");
028: static final Message BUNDLE_UNINSTALLED = new Message(
029: "bundle.uninstalled");
030: static final Message STARTING_BUNDLE = new Message(
031: "starting.bundle");
032: static final Message BUNDLE_STARTED = new Message(
033: "bundle.started");
034: static final Message STOPPING_BUNDLE = new Message(
035: "stopping.bundle");
036: static final Message BUNDLE_STOPPED = new Message(
037: "bundle.stopped");
038: static final Message REGISTERING_SERVICE = new Message(
039: "registering.service");
040: static final Message SERVICE_REGISTERED = new Message(
041: "service.registered");
042: static final Message STOPPING_FRAMEWORK = new Message(
043: "stopping.framework");
044: static final Message SHUTDOWN = new Message(
045: "framework.shutdown");
046:
047: static final Message WARN_MISSING_REPOSITORY = new Message(
048: "warn.missing.repository");
049: static final Message WARN_SKIPPED_ALREADY_ACTIVE = new Message(
050: "warn.skipped.activation");
051: static final Message WARN_SKIPPED_FILE_INSTALLATION = new Message(
052: "warn.skipped.file.installation");
053: static final Message WARN_SKIPPED_FILE_UNREADABLE = new Message(
054: "warn.skipped.file.unreadable");
055: static final Message WARN_SKIPPED_MISNAMED_FILE = new Message(
056: "warn.skipped.misnamed.file");
057: static final Message ERROR_INVALID_REPOSITORY = new Message(
058: "error.missing.repository");
059: static final Message ERROR_BUNDLE_INACCESSIBLE = new Message(
060: "error.bundle.inaccessible");
061: static final Message ERROR_BUNDLE_NOT_FOUND = new Message(
062: "error.bundle.not.found");
063: static final Message ERROR_BUNDLE_URL_UNRESOLVABLE = new Message(
064: "error.bundle.unresolved");
065: static final Message ERROR_REQUIRED_BUNDLE_MISSING = new Message(
066: "error.bundle.dependency.missing");
067:
068: private final String resourceBundleKey;
069:
070: private Message(final String resourceBundleKey) {
071: this .resourceBundleKey = resourceBundleKey;
072: }
073:
074: String key() {
075: return resourceBundleKey;
076: }
077: }
078:
079: private static final TCLogger logger = CustomerLogging
080: .getDSORuntimeLogger();
081: private static final ResourceBundle resourceBundle;
082:
083: static {
084: try {
085: resourceBundle = ResourceBundle.getBundle(
086: EmbeddedOSGiRuntime.class.getName(), Locale
087: .getDefault(), EmbeddedOSGiRuntime.class
088: .getClassLoader());
089: } catch (MissingResourceException mre) {
090: throw new RuntimeException("No resource bundle exists for "
091: + EmbeddedOSGiRuntime.class.getName());
092: } catch (Throwable t) {
093: throw new RuntimeException(
094: "Unexpected error loading resource bundle for "
095: + EmbeddedOSGiRuntime.class.getName(), t);
096: }
097: }
098:
099: protected final void info(final Message message,
100: final Object[] arguments) {
101: logger.info(formatMessage(message, arguments));
102: }
103:
104: protected final void warn(final Message message,
105: final Object[] arguments) {
106: logger.warn(formatMessage(message, arguments));
107: }
108:
109: protected final void exception(final Message message,
110: final Object[] arguments, final Throwable t)
111: throws BundleException {
112: final String msg = formatMessage(message, arguments);
113: logger.error(msg, t);
114: throw new BundleException(msg, t);
115: }
116:
117: private final static String formatMessage(final Message message,
118: final Object[] arguments) {
119: return MessageFormat.format(resourceBundle.getString(message
120: .key()), arguments);
121: }
122:
123: }
|