aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r1195697 - in /aries/trunk/sandbox/jmx-next: jmx-api/src/main/java/org/osgi/jmx/framework/ jmx-core/src/main/java/org/apache/aries/jmx/framework/ jmx-itests/src/test/java/org/apache/aries/jmx/framework/
Date Mon, 31 Oct 2011 22:07:56 GMT
Author: davidb
Date: Mon Oct 31 22:07:56 2011
New Revision: 1195697

URL: http://svn.apache.org/viewvc?rev=1195697&view=rev
Log:
Add support for localized getHeader()/getHeaders() calls.

Modified:
    aries/trunk/sandbox/jmx-next/jmx-api/src/main/java/org/osgi/jmx/framework/BundleStateMBean.java
    aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/framework/BundleState.java
    aries/trunk/sandbox/jmx-next/jmx-itests/src/test/java/org/apache/aries/jmx/framework/BundleStateMBeanTest.java

Modified: aries/trunk/sandbox/jmx-next/jmx-api/src/main/java/org/osgi/jmx/framework/BundleStateMBean.java
URL: http://svn.apache.org/viewvc/aries/trunk/sandbox/jmx-next/jmx-api/src/main/java/org/osgi/jmx/framework/BundleStateMBean.java?rev=1195697&r1=1195696&r2=1195697&view=diff
==============================================================================
--- aries/trunk/sandbox/jmx-next/jmx-api/src/main/java/org/osgi/jmx/framework/BundleStateMBean.java
(original)
+++ aries/trunk/sandbox/jmx-next/jmx-api/src/main/java/org/osgi/jmx/framework/BundleStateMBean.java
Mon Oct 31 22:07:56 2011
@@ -32,7 +32,7 @@ import org.osgi.jmx.JmxConstants;
  * emits events that clients can use to get notified of the changes in the
  * bundle state of the framework.
  *
- * @version $Revision$
+ * @version $Id: f5d5197fdabb4e0c420bc47812d38fd14edb61d0 $
  * @ThreadSafe
  */
 public interface BundleStateMBean {
@@ -427,7 +427,12 @@ public interface BundleStateMBean {
 																BUNDLE_TYPE,
 																IDENTIFIER);
 
-    CompositeData getBundle(long id) throws IOException;
+	/** New!!
+	 * @param id The Bundle ID
+	 * @return The Bundle Data
+	 * @throws IOException
+	 */
+	CompositeData getBundle(long id) throws IOException;
 
 	/**
 	 * Answer the list of identifiers of the bundles this bundle depends upon
@@ -494,7 +499,9 @@ public interface BundleStateMBean {
 	 *             if the bundle indicated does not exist
 	 */
 	TabularData getHeaders(long bundleId) throws IOException;
+    TabularData getHeaders(long bundleId, String locale) throws IOException;
     String getHeader(long bundleId, String key) throws IOException;
+    String getHeader(long bundleId, String key, String locale) throws IOException;
 
 	/**
 	 * Answer the list of bundle ids of the bundles which host a fragment

Modified: aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/framework/BundleState.java
URL: http://svn.apache.org/viewvc/aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/framework/BundleState.java?rev=1195697&r1=1195696&r2=1195697&view=diff
==============================================================================
--- aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/framework/BundleState.java
(original)
+++ aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/framework/BundleState.java
Mon Oct 31 22:07:56 2011
@@ -115,11 +115,23 @@ public class BundleState extends Notific
     /**
      * @see org.osgi.jmx.framework.BundleStateMBean#getHeaders(long)
      */
-    @SuppressWarnings("unchecked")
     public TabularData getHeaders(long bundleId) throws IOException, IllegalArgumentException
{
         Bundle bundle = resolveBundle(bundleContext, bundleId);
-        List<Header> headers = new ArrayList<Header>();
         Dictionary<String, String> bundleHeaders = bundle.getHeaders();
+        return getHeaders(bundleHeaders);
+    }
+
+    /**
+     * @see org.osgi.jmx.framework.BundleStateMBean#getHeaders(long, java.lang.String)
+     */
+    public TabularData getHeaders(long bundleId, String locale) throws IOException, IllegalArgumentException
{
+        Bundle bundle = resolveBundle(bundleContext, bundleId);
+        Dictionary<String, String> bundleHeaders = bundle.getHeaders(locale);
+        return getHeaders(bundleHeaders);
+    }
+
+    private TabularData getHeaders(Dictionary<String, String> bundleHeaders) {
+        List<Header> headers = new ArrayList<Header>();
         Enumeration<String> keys = bundleHeaders.keys();
         while (keys.hasMoreElements()) {
             String key = keys.nextElement();
@@ -132,12 +144,23 @@ public class BundleState extends Notific
         return headerTable;
     }
 
+    /**
+     * @see org.osgi.jmx.framework.BundleStateMBean#getHeader(long, java.lang.String)
+     */
     public String getHeader(long bundleId, String key) throws IOException {
         Bundle bundle = resolveBundle(bundleContext, bundleId);
         return bundle.getHeaders().get(key);
     }
 
     /**
+     * @see org.osgi.jmx.framework.BundleStateMBean#getHeader(long, java.lang.String, java.lang.String)
+     */
+    public String getHeader(long bundleId, String key, String locale) throws IOException
{
+        Bundle bundle = resolveBundle(bundleContext, bundleId);
+        return bundle.getHeaders(locale).get(key);
+    }
+
+    /**
      * @see org.osgi.jmx.framework.BundleStateMBean#getHosts(long)
      */
     public long[] getHosts(long fragmentId) throws IOException, IllegalArgumentException
{

Modified: aries/trunk/sandbox/jmx-next/jmx-itests/src/test/java/org/apache/aries/jmx/framework/BundleStateMBeanTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/sandbox/jmx-next/jmx-itests/src/test/java/org/apache/aries/jmx/framework/BundleStateMBeanTest.java?rev=1195697&r1=1195696&r2=1195697&view=diff
==============================================================================
--- aries/trunk/sandbox/jmx-next/jmx-itests/src/test/java/org/apache/aries/jmx/framework/BundleStateMBeanTest.java
(original)
+++ aries/trunk/sandbox/jmx-next/jmx-itests/src/test/java/org/apache/aries/jmx/framework/BundleStateMBeanTest.java
Mon Oct 31 22:07:56 2011
@@ -28,13 +28,20 @@ import static org.ops4j.pax.swissbox.tin
 import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.withBnd;
 import static org.osgi.jmx.framework.BundleStateMBean.OBJECTNAME;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.List;
+import java.util.Properties;
 
 import javax.management.Notification;
 import javax.management.NotificationListener;
 import javax.management.ObjectName;
+import javax.management.openmbean.CompositeData;
 import javax.management.openmbean.TabularData;
 
 import org.apache.aries.jmx.AbstractIntegrationTest;
@@ -109,10 +116,28 @@ public class BundleStateMBeanTest extend
                                 .set(Constants.BUNDLE_SYMBOLICNAME, "org.apache.aries.jmx.test.bundled")
                                 .set(Constants.BUNDLE_VERSION, "3.0.0")
                                 .set(Constants.REQUIRE_BUNDLE, "org.apache.aries.jmx.test.bundlea;bundle-version=2.0.0")
+                                .build(withBnd())),
+                        provision(newBundle()
+                                .set(Constants.BUNDLE_SYMBOLICNAME, "org.apache.aries.jmx.test.bundlee")
+                                .set(Constants.BUNDLE_DESCRIPTION, "%desc")
+                                .add("OSGI-INF/l10n/bundle.properties", getBundleProps("desc",
"Description"))
+                                .add("OSGI-INF/l10n/bundle_nl.properties", getBundleProps("desc",
"Omschrijving"))
                                 .build(withBnd()))
                         );
     }
 
+    private static InputStream getBundleProps(String key, String value) {
+        try {
+            Properties p = new Properties();
+            p.put(key, value);
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            p.store(baos, "");
+            return new ByteArrayInputStream(baos.toByteArray());
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
     @Override
     public void doSetUp() throws Exception {
         waitForMBean(new ObjectName(BundleStateMBean.OBJECTNAME));
@@ -265,6 +290,43 @@ public class BundleStateMBeanTest extend
 
     }
 
+    @Test
+    @SuppressWarnings({ "unchecked" })
+    public void testHeaderLocalization() throws Exception {
+        BundleStateMBean mbean = getMBean(OBJECTNAME, BundleStateMBean.class);
+        Bundle b = context().getBundleByName("org.apache.aries.jmx.test.bundlee");
+
+        CompositeData cd = mbean.getBundle(b.getBundleId());
+        long id = (Long) cd.get(BundleStateMBean.IDENTIFIER);
+        assertEquals("Description", mbean.getHeader(id, Constants.BUNDLE_DESCRIPTION));
+        assertEquals("Description", mbean.getHeader(id, Constants.BUNDLE_DESCRIPTION, "en"));
+        assertEquals("Omschrijving", mbean.getHeader(id, Constants.BUNDLE_DESCRIPTION, "nl"));
+
+        TabularData td = mbean.getHeaders(id);
+        boolean found = false;
+        for (CompositeData d : (Collection<CompositeData>) td.values()) {
+            if (Constants.BUNDLE_DESCRIPTION.equals(d.get(BundleStateMBean.KEY))) {
+                assertEquals("Description", d.get(BundleStateMBean.VALUE));
+                found = true;
+                break;
+            }
+        }
+        assertTrue(found);
+
+        TabularData tdNL = mbean.getHeaders(id, "nl");
+        boolean foundNL = false;
+        for (CompositeData d : (Collection<CompositeData>) tdNL.values()) {
+            if (Constants.BUNDLE_DESCRIPTION.equals(d.get(BundleStateMBean.KEY))) {
+                assertEquals("Omschrijving", d.get(BundleStateMBean.VALUE));
+                foundNL = true;
+                break;
+            }
+        }
+        assertTrue(foundNL);
+    }
+
+
+    @SuppressWarnings({ "rawtypes", "deprecation" })
     private Version getPackageVersion(String packageName) {
         ServiceReference paRef = context().getServiceReference(PackageAdmin.class.getName());
         PackageAdmin pa = (PackageAdmin) context().getService(paRef);



Mime
View raw message