1 5 package com.tc.bundles; 6 7 import com.tc.logging.CustomerLogging; 8 import com.tc.logging.TCLogger; 9 10 import java.text.MessageFormat ; 11 import java.util.Locale ; 12 import java.util.MissingResourceException ; 13 import java.util.ResourceBundle ; 14 15 abstract class AbstractEmbeddedOSGiRuntime implements EmbeddedOSGiRuntime { 16 17 static class Message { 18 19 static final Message BUNDLE_INSTALLED = new Message("bundle.installed"); 20 static final Message BUNDLE_UNINSTALLED = new Message("bundle.uninstalled"); 21 static final Message BUNDLE_STARTED = new Message("bundle.started"); 22 static final Message BUNDLE_STOPPED = new Message("bundle.stopped"); 23 static final Message SERVICE_REGISTERED = new Message("service.registered"); 24 static final Message SHUTDOWN = new Message("framework.shutdown"); 25 26 private final String resourceBundleKey; 27 28 private Message(final String resourceBundleKey) { 29 this.resourceBundleKey = resourceBundleKey; 30 } 31 32 String key() { 33 return resourceBundleKey; 34 } 35 } 36 37 private static final TCLogger logger = CustomerLogging.getDSORuntimeLogger(); 38 private static final ResourceBundle resourceBundle; 39 40 static { 41 try { 42 resourceBundle = ResourceBundle.getBundle(EmbeddedOSGiRuntime.class.getName(), Locale.getDefault(), 43 EmbeddedOSGiRuntime.class.getClassLoader()); 44 } catch (MissingResourceException mre) { 45 throw new RuntimeException ("No resource bundle exists for " + EmbeddedOSGiRuntime.class.getName()); 46 } catch (Throwable t) { 47 throw new RuntimeException ("Unexpected error loading resource bundle for " + EmbeddedOSGiRuntime.class.getName(), 48 t); 49 } 50 } 51 52 protected final void info(final Message message, final Object [] arguments) { 53 logger.info(formatMessage(message, arguments)); 54 } 55 56 private final static String formatMessage(final Message message, final Object [] arguments) { 57 return MessageFormat.format(resourceBundle.getString(message.key()), arguments); 58 } 59 60 } 61 | Popular Tags |