use of org.apache.felix.mosgi.console.ifc.Plugin in project felix by apache.
the class NodePanel method startMBeanTabBundles.
private void startMBeanTabBundles(String connString, MBeanServerConnection mbsc) {
try {
this.clean();
// ioe
Set set_on = mbsc.queryNames(null, null);
Object[] ons = set_on.toArray();
int oldUnstartedBundleNbr = 0;
do {
Vector v_unstartedBundle = new Vector();
oldUnstartedBundleNbr = ons.length;
for (int i = 0; i < ons.length; i++) {
ObjectName name = (ObjectName) ons[i];
if ("TabUI".equals(name.getDomain())) {
/* Get the plugin implementation via a bundle */
try {
// mbe, anfe, be, infe, re
String tabBundle = (String) mbsc.getAttribute(name, "BundleName");
if (tabBundle != null) {
Plugin p = (Plugin) this.pluginList.get(tabBundle);
if (p == null) {
// be
Bundle b = m_context.installBundle(tabBundle);
try {
// be2
b.start();
System.out.println(" - Bundle started: \"" + name.toString() + "\" - " + tabBundle);
} catch (BundleException be2) {
// be2
System.out.println(" - Unable to start: \"" + name.toString() + "\" - " + tabBundle);
be2.printStackTrace();
v_unstartedBundle.add(name);
}
} else {
System.out.println(" - Register service plugin: " + p);
p.registerServicePlugin();
}
/* ServiceReference[] sr = b.getRegisteredServices();
* System.out.println(sr);
* Plugin p;
* for (int j=0 ; j < sr.length ; j++) {
* p=(Plugin)m_context.getService(sr[j]);
* this.add(p.getName(), p.getGUI());
* this.a.addPropertyChangeListener(p);
* }
*
* System.out.println("Delegation for this");
* printcl = this.getClass().getClassLoader();
* while (printcl != null) {
* System.out.println(printcl);
* printcl = printcl.getParent();
* }
* System.out.println("{bootstrap loader}");
* System.out.println("");
*
* // Get the tab object
* Object tabObj = mbsc.getAttribute(name, "Tab");
*
* System.out.println("Delegation for tabObj: " + tabObj);
* printcl = tabObj.getClass().getClassLoader();
* while (printcl != null) {
* System.out.println(printcl);
* printcl = printcl.getParent();
* }
* System.out.println("{bootstrap loader}");
* System.out.println("");
*
* System.out.println("tabObj.getName(): " + ((fr.inria.ares.managedelements.testprobe.tab.TestProbeTabUI) tabObj).getName());
*
* // Cast the tab
* Plugin tab = (Plugin)tabObj;
* // register the tab on the JTabbedPane
* this.add(tab.getName(), tab.getGUI());
*/
} else {
System.out.println(" - No bundleName attribute defined for \"" + name.toString() + "\". I cannot install tab");
}
} catch (MBeanException mbe) {
// mbe
mbe.printStackTrace();
} catch (AttributeNotFoundException anfe) {
// anfe
anfe.printStackTrace();
} catch (BundleException be) {
// be
be.printStackTrace();
} catch (InstanceNotFoundException infe) {
// infe
infe.printStackTrace();
} catch (ReflectionException re) {
// re
re.printStackTrace();
}
}
}
ons = v_unstartedBundle.toArray();
} while (oldUnstartedBundleNbr != ons.length);
} catch (IOException ioe) {
// ioe
ioe.printStackTrace();
}
a.firePropertyChangedEvent(Plugin.NEW_NODE_READY, connString, mbsc);
a.firePropertyChangedEvent(Plugin.PLUGIN_ACTIVATED, null, this.getComponentAt(0).getName());
}
use of org.apache.felix.mosgi.console.ifc.Plugin in project felix by apache.
the class NodePanel method propertyChange.
// ///////////////////////////////////////
// PropertyChangeListener Impl. //
// ///////////////////////////////////////
public void propertyChange(PropertyChangeEvent event) {
// System.out.println(" PCE : "+event.getPropertyName());
if (event.getPropertyName().equals(Plugin.PLUGIN_ADDED)) {
Plugin cp = (Plugin) event.getNewValue();
this.add(cp.getName(), cp.getGUI());
System.out.println("Add gui \"" + cp.getName() + "\" into NodePanel");
this.a.addPropertyChangeListener(cp);
this.pluginList.put(cp.pluginLocation(), cp);
} else if (event.getPropertyName().equals(Plugin.PLUGIN_REMOVED)) {
Plugin cp = (Plugin) event.getNewValue();
String cpLoc = cp.pluginLocation();
this.remove(cp.getGUI());
// this.a.removePropertyChangeListener(cp);
// this.pluginList.remove(cpLoc);
} else if (event.getPropertyName().equals(Plugin.EMPTY_NODE)) {
// System.out.println("******* Debug No node selected");
this.clean();
} else if (event.getPropertyName().equals(Plugin.NEW_NODE_SELECTED)) {
/* Update the tabs (Plugin) in the JTabbedPane (NodePanel) */
MBeanServerConnection mbsc = (MBeanServerConnection) event.getNewValue();
String connString = (String) event.getOldValue();
startMBeanTabBundles(connString, mbsc);
} else if (event.getPropertyName().equals(CommonPlugin.COMMON_PLUGIN_ADDED)) {
Iterator it = Gateway.HT_GATEWAY.values().iterator();
while (it.hasNext()) {
Gateway g = (Gateway) it.next();
if (g.isConnected()) {
a.firePropertyChangedEvent(Plugin.NEW_NODE_CONNECTION, g.toString(), g.getMbsc());
}
}
}
}
use of org.apache.felix.mosgi.console.ifc.Plugin in project felix by apache.
the class Activator method start.
// /////////////////////////////////////
// BundleActivator //
// /////////////////////////////////////
public void start(BundleContext context) {
m_context = context;
// Listen for factory service events.
ServiceListener sl = new ServiceListener() {
public void serviceChanged(ServiceEvent event) {
ServiceReference ref = event.getServiceReference();
Object svcObj = m_context.getService(ref);
if (event.getType() == ServiceEvent.REGISTERED) {
synchronized (Activator.this) {
// !!!!!!!!!! ORDER MATTERS (Inheritance pb)
if (!m_pluginList.contains(svcObj)) {
if (svcObj instanceof CommonPlugin) {
m_commonpluginList.add(svcObj);
firePropertyChangedEvent(CommonPlugin.COMMON_PLUGIN_ADDED, null, svcObj);
} else if (svcObj instanceof Plugin) {
m_pluginList.add(svcObj);
firePropertyChangedEvent(Plugin.PLUGIN_ADDED, null, svcObj);
}
}
}
} else if (event.getType() == ServiceEvent.UNREGISTERING) {
synchronized (Activator.this) {
removePropertyChangeListener((PropertyChangeListener) svcObj);
if (svcObj instanceof CommonPlugin) {
m_commonpluginList.remove(svcObj);
firePropertyChangedEvent(CommonPlugin.COMMON_PLUGIN_REMOVED, null, svcObj);
} else if (svcObj instanceof Plugin) {
m_pluginList.remove(svcObj);
firePropertyChangedEvent(Plugin.PLUGIN_REMOVED, null, svcObj);
}
}
} else {
m_context.ungetService(ref);
}
}
};
try {
m_context.addServiceListener(sl, "(|(objectClass=" + Plugin.class.getName() + ")(objectClass=" + CommonPlugin.class.getName() + "))");
} catch (InvalidSyntaxException ex) {
System.err.println("ShellGuiActivator: Cannot add service listener.");
System.err.println("ShellGuiActivator: " + ex);
}
// Create and display the frame.
if (m_frame == null) {
m_frame = new JFrame("OSGi GUI Remote Manager");
m_frame.setUndecorated(true);
m_frame.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
m_frame.setIconImage(Toolkit.getDefaultToolkit().getImage(m_context.getBundle().getResource("images/logo.gif")));
// m_frame.setResizable(false);
// m_frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
// TODO : add a windowListener and use a Preferences service to save screen size
m_frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
JFrame jf = (JFrame) we.getWindow();
System.out.println(" Console.gui : window closing (" + jf.getSize().height + "*" + jf.getSize().width + ")");
}
public void windowClosed(WindowEvent we) {
JFrame jf = (JFrame) we.getWindow();
System.out.println(" Console.gui : window closed (" + jf.getSize().height + "*" + jf.getSize().width + ")");
}
});
Dimension maxdim = m_frame.getToolkit().getScreenSize();
int m_width = maxdim.width - 100;
int m_height = maxdim.height - 100;
m_frame.setBounds((int) ((maxdim.width - m_width) / 2), 20, m_width, m_height);
// Right panel
JSplitPane rightSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, new NodePanel(this, context), new CommonPanel(this));
rightSplitPane.setOneTouchExpandable(true);
rightSplitPane.setDividerLocation((int) (m_height * 2 / 3));
// General Panel
this.nodesTree = new NodesTree(this, context);
JSplitPane gSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, this.nodesTree, rightSplitPane);
gSplitPane.setOneTouchExpandable(true);
gSplitPane.setDividerLocation((int) (m_width / 4));
m_frame.getContentPane().add(gSplitPane);
}
// Now try to manually initialize the plugin list
// since some might already be available.
// initializePlugins();
m_frame.setVisible(true);
this.nodesTree.runDiscovery();
}
use of org.apache.felix.mosgi.console.ifc.Plugin in project felix by apache.
the class NodePanel method clean.
private void clean() {
this.removeAll();
Vector pluginList_tmp = new Vector();
for (Iterator i = pluginList.keySet().iterator(); i.hasNext(); ) {
Object o = i.next();
pluginList_tmp.add(o);
}
for (int i = 0; i < pluginList_tmp.size(); i++) {
Plugin p = (Plugin) pluginList.get(pluginList_tmp.elementAt(i));
try {
p.unregisterServicePlugin();
} catch (Exception ex) {
// System.out.println("\""+p.getName()+"\" : "+ex);
}
}
}
Aggregations