KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > bundles > AbstractEmbeddedOSGiRuntime


1 /*
2  * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
3  * notice. All rights reserved.
4  */

5 package com.tc.bundles;
6
7 import com.tc.logging.CustomerLogging;
8 import com.tc.logging.TCLogger;
9
10 import java.text.MessageFormat JavaDoc;
11 import java.util.Locale JavaDoc;
12 import java.util.MissingResourceException JavaDoc;
13 import java.util.ResourceBundle JavaDoc;
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 JavaDoc resourceBundleKey;
27
28     private Message(final String JavaDoc resourceBundleKey) {
29       this.resourceBundleKey = resourceBundleKey;
30     }
31
32     String JavaDoc key() {
33       return resourceBundleKey;
34     }
35   }
36
37   private static final TCLogger logger = CustomerLogging.getDSORuntimeLogger();
38   private static final ResourceBundle JavaDoc resourceBundle;
39
40   static {
41     try {
42       resourceBundle = ResourceBundle.getBundle(EmbeddedOSGiRuntime.class.getName(), Locale.getDefault(),
43           EmbeddedOSGiRuntime.class.getClassLoader());
44     } catch (MissingResourceException JavaDoc mre) {
45       throw new RuntimeException JavaDoc("No resource bundle exists for " + EmbeddedOSGiRuntime.class.getName());
46     } catch (Throwable JavaDoc t) {
47       throw new RuntimeException JavaDoc("Unexpected error loading resource bundle for " + EmbeddedOSGiRuntime.class.getName(),
48           t);
49     }
50   }
51
52   protected final void info(final Message message, final Object JavaDoc[] arguments) {
53     logger.info(formatMessage(message, arguments));
54   }
55
56   private final static String JavaDoc formatMessage(final Message message, final Object JavaDoc[] arguments) {
57     return MessageFormat.format(resourceBundle.getString(message.key()), arguments);
58   }
59
60 }
61
Popular Tags