A graphical tab that is automatically downloaded and included in the JMX Console
git-svn-id: https://svn.apache.org/repos/asf/incubator/felix/trunk@424252 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/org.apache.felix.mosgi.managedelements.osgiprobes.tab/pom.xml b/org.apache.felix.mosgi.managedelements.osgiprobes.tab/pom.xml
new file mode 100644
index 0000000..1512abf
--- /dev/null
+++ b/org.apache.felix.mosgi.managedelements.osgiprobes.tab/pom.xml
@@ -0,0 +1,63 @@
+<project>
+ <parent>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>felix</artifactId>
+ <version>0.8.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>osgi-bundle</packaging>
+ <name>MOSGi OSGi gateway status tab for the JMX console</name>
+ <artifactId>org.apache.felix.mosgi.managedelements.osgiprobes.tab</artifactId>
+ <dependencies>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>${pom.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <version>${pom.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.apache.felix.mosgi.console.ifc</artifactId>
+ <version>${pom.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix.plugins</groupId>
+ <artifactId>maven-osgi-plugin</artifactId>
+ <version>${pom.version}</version>
+ <extensions>true</extensions>
+ <configuration>
+ <osgiManifest>
+ <bundleName>MOSGi OSGi gateway status tab for the JMX console</bundleName>
+ <bundleDescription>MOSGi OSGi gateway status tab for the JMX console</bundleDescription>
+ <bundleActivator>auto-detect</bundleActivator>
+ <bundleDocUrl>http://oscar-osgi.sf.net/obr2/${pom.artifactId}/</bundleDocUrl>
+ <bundleUrl>http://oscar-osgi.sf.net/obr2/${pom.artifactId}/${pom.artifactId}-${pom.version}.jar</bundleUrl>
+ <bundleSource>http://oscar-osgi.sf.net/obr2/${pom.artifactId}/${pom.artifactId}-${pom.version}-src.jar</bundleSource>
+ <bundleSymbolicName>${pom.artifactId}</bundleSymbolicName>
+ <exportPackage>
+ ${pom.artifactId};specification-version="1.0.0"
+ </exportPackage>
+ <importPackage>
+ javax.management;specification-version="1.0.0",
+ org.osgi.framework;specification-version="1.0.0",
+ javax.swing;specification-version="1.0.0",
+ javax.swing.table;specification-version="1.0.0",
+ org.apache.felix.mosgi.console.ifc;specification-version="1.0.0",
+ ${pom.artifactId};specification-version="1.0.0"
+ </importPackage>
+ </osgiManifest>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/org.apache.felix.mosgi.managedelements.osgiprobes.tab/src/main/java/org/apache/felix/mosgi/managedelements/osgiprobes/tab/OsgiProbesTabUI.java b/org.apache.felix.mosgi.managedelements.osgiprobes.tab/src/main/java/org/apache/felix/mosgi/managedelements/osgiprobes/tab/OsgiProbesTabUI.java
new file mode 100644
index 0000000..f79fced
--- /dev/null
+++ b/org.apache.felix.mosgi.managedelements.osgiprobes.tab/src/main/java/org/apache/felix/mosgi/managedelements/osgiprobes/tab/OsgiProbesTabUI.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.felix.mosgi.managedelements.osgiprobes.tab;
+
+import java.awt.Component;
+import java.beans.PropertyChangeEvent;
+import java.util.ArrayList;
+import java.util.Vector;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import javax.swing.table.DefaultTableModel;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.apache.felix.mosgi.console.ifc.Plugin;
+
+public class OsgiProbesTabUI extends JPanel implements Plugin, BundleActivator {
+
+ private String [] headers = {"Name", "Value"};
+ private JTable innerTable;
+
+ private BundleContext m_context = null;
+ private ServiceRegistration sreg = null;
+
+ public OsgiProbesTabUI(){
+ this.innerTable=new JTable();
+ this.innerTable.setPreferredScrollableViewportSize(new java.awt.Dimension(500,150));
+ JScrollPane table = new JScrollPane(this.innerTable);
+ this.add(table);
+ }
+
+
+ ///////////////////////////////////////////
+ // BundleActivator //
+ ///////////////////////////////////////////
+ public void start(BundleContext context) {
+ m_context = context;
+ this.registerServicePlugin();
+ }
+
+ public void stop(BundleContext context) {
+ }
+
+
+
+ ///////////////////////////////////////////
+ // Plugin //
+ //////////////////////////////////////////
+ public void registerServicePlugin(){
+ sreg = m_context.registerService(Plugin.class.getName(), this, null);
+ }
+
+ public void unregisterServicePlugin(){
+ sreg.unregister();
+ }
+
+ public String pluginLocation(){
+ return m_context.getBundle().getLocation();
+ }
+
+ public String getName(){return "OSGi Platform";}
+
+ public Component getGUI(){return this;}
+
+ public void propertyChange(PropertyChangeEvent e){
+ /*
+ * This a static tab, each new visit will provide the same
+ * information. A dynamic tab update is provided in LinuxTab
+ *
+ */
+ if (e.getPropertyName().equals(Plugin.NEW_NODE_READY)){
+ this.getProperties((MBeanServerConnection)e.getNewValue());
+ }else if(e.getPropertyName().equals(Plugin.EMPTY_NODE)){
+ this.innerTable.setModel(new DefaultTableModel());
+ this.invalidate();
+ this.validate();
+ }
+ }
+
+ private void getProperties(MBeanServerConnection mbsc){
+ try{
+ ObjectName on=new ObjectName("TabUI:name=OsgiProbes");
+ MBeanAttributeInfo attrInfo[] = mbsc.getMBeanInfo(on).getAttributes();
+ Object content [][]=new String[attrInfo.length][2];
+ for (int k=0;k<attrInfo.length;k++) {
+ content [k][0]=attrInfo[k].getName();
+ content [k][1]=mbsc.getAttribute(on, attrInfo[k].getName());
+ }
+ DefaultTableModel dtm=new DefaultTableModel(content, this.headers);
+ this.innerTable.setModel(dtm);
+ this.invalidate();
+ this.validate();
+ }catch (Exception e){
+ e.printStackTrace();
+ }
+ }
+}