You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by fu...@apache.org on 2006/11/03 14:44:27 UTC
svn commit: r470811 [1/2] - in
/incubator/felix/sandbox/furfari/upnp.jmxbridge.tab: ./ src/ src/main/
src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/felix/ src/main/java/org/apache/felix/upnp/
src/main/java/org/apa...
Author: furfari
Date: Fri Nov 3 05:44:25 2006
New Revision: 470811
URL: http://svn.apache.org/viewvc?view=rev&rev=470811
Log:
First version of the console plugin for Remote UPnP networks according to the mosgi implementation.
Embedded device are not parsed properly yet.
Service subscription is not working.
You can just discover plugging and unplugging of simple devices and to invoke their actions
Added:
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/pom.xml
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/ControlPoint.java
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/Mediator.java
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/RemoteUPnPAction.java
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/RemoteUPnPDevice.java
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/RemoteUPnPService.java
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/RemoteUPnPStateVariable.java
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/RemoteUPnPTabUI.java
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/UPnPSubscriber.java
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/discovery/
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/discovery/DeviceChangeListener.java
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/discovery/DeviceNode.java
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/discovery/DeviceNodeListener.java
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/discovery/MBeanDeviceListener.java
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/gui/
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/gui/ActionPanel.java
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/gui/Converter.java
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/gui/LogPanel.java
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/gui/PropertiesViewer.java
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/gui/SubscriptionPanel.java
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/gui/TreeViewer.java
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/gui/UPnPDeviceTreeNode.java
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/gui/Util.java
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/resources/
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/resources/org/
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/resources/org/apache/
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/resources/org/apache/felix/
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/resources/org/apache/felix/upnp/
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/resources/org/apache/felix/upnp/jmxbridge/
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/resources/org/apache/felix/upnp/jmxbridge/tab/
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/resources/org/apache/felix/upnp/jmxbridge/tab/gui/
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/resources/org/apache/felix/upnp/jmxbridge/tab/gui/IMAGES/
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/resources/org/apache/felix/upnp/jmxbridge/tab/gui/IMAGES/AnimatedStateVariable.gif (with props)
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/resources/org/apache/felix/upnp/jmxbridge/tab/gui/IMAGES/DeviceNode.gif (with props)
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/resources/org/apache/felix/upnp/jmxbridge/tab/gui/IMAGES/EventedStateVariable.gif (with props)
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/resources/org/apache/felix/upnp/jmxbridge/tab/gui/IMAGES/RootDeviceNode.gif (with props)
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/resources/org/apache/felix/upnp/jmxbridge/tab/gui/IMAGES/SubscribedStateVariable.gif (with props)
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/resources/org/apache/felix/upnp/jmxbridge/tab/gui/IMAGES/UPnPAction.gif (with props)
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/resources/org/apache/felix/upnp/jmxbridge/tab/gui/IMAGES/UPnPService.gif (with props)
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/resources/org/apache/felix/upnp/jmxbridge/tab/gui/IMAGES/UPnPStateVariable.gif (with props)
incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/resources/org/apache/felix/upnp/jmxbridge/tab/gui/IMAGES/logo.gif (with props)
Added: incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/pom.xml
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/pom.xml?view=auto&rev=470811
==============================================================================
--- incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/pom.xml (added)
+++ incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/pom.xml Fri Nov 3 05:44:25 2006
@@ -0,0 +1,76 @@
+<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>Apache Felix Remote UPnP Control Point tab for the JMX console</name>
+ <artifactId>org.apache.felix.upnp.jmxbridge.tab</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+
+ <dependencies>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.apache.felix.mosgi.console.ifc</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix.plugins</groupId>
+ <artifactId>maven-osgi-plugin</artifactId>
+ <!--version>${felix.version}</version-->
+ <extensions>true</extensions>
+ <configuration>
+ <osgiManifest>
+ <bundleName>Remote UPnP Control Point tab for the JMX console</bundleName>
+ <bundleDescription>Remote UPnP Control Point 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",
+ org.xml.sax,
+ javax.xml.parsers,
+ org.w3c.dom,
+ javax.swing.event,
+ org.osgi.service.upnp,
+ javax.swing.tree
+ </importPackage>
+ </osgiManifest>
+ </configuration>
+ </plugin>
+ </plugins>
+ <resources>
+ <resource>
+ <directory>src/main/resources</directory>
+ </resource>
+ </resources>
+ </build>
+
+</project>
Added: incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/ControlPoint.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/ControlPoint.java?view=auto&rev=470811
==============================================================================
--- incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/ControlPoint.java (added)
+++ incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/ControlPoint.java Fri Nov 3 05:44:25 2006
@@ -0,0 +1,352 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.upnp.jmxbridge.tab;
+
+
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.util.Hashtable;
+import java.util.Set;
+
+import javax.management.MBeanServerConnection;
+import javax.swing.JPanel;
+import javax.swing.JSplitPane;
+
+import org.apache.felix.upnp.jmxbridge.tab.discovery.MBeanDeviceListener;
+import org.apache.felix.upnp.jmxbridge.tab.gui.LogPanel;
+import org.apache.felix.upnp.jmxbridge.tab.gui.PropertiesViewer;
+import org.apache.felix.upnp.jmxbridge.tab.gui.TreeViewer;
+import org.osgi.framework.BundleContext;
+
+/*
+* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+*/
+public class ControlPoint /*implements PopupMenuListener*/ {
+ private BundleContext bc;
+ private MBeanServerConnection activeConnection;
+ private Hashtable connections = new Hashtable();
+ TreeViewer viewer;
+ PropertiesViewer properties;
+
+ private JPanel panel;
+
+
+ public ControlPoint(BundleContext bc) {
+ this.bc = bc;
+ //doMenuBar(frame);
+ doControlPanel();
+ Mediator.setControlPoint(this);
+ }
+
+ public void closeConnection(){
+ if (activeConnection != null){
+ MBeanDeviceListener oldMbeanListener = (MBeanDeviceListener)connections.get(activeConnection);
+ oldMbeanListener.deactive();
+ }
+ }
+
+ public void setConnection(MBeanServerConnection mbsc){
+ MBeanDeviceListener MBeanListener = (MBeanDeviceListener) connections.get(mbsc);
+ if (MBeanListener == null){
+ if (activeConnection != null){
+ MBeanDeviceListener oldMbeanListener = (MBeanDeviceListener)connections.get(activeConnection);
+ oldMbeanListener.deactive();
+ }
+ MBeanDeviceListener mbeanListener = new MBeanDeviceListener(mbsc);
+ Mediator.setMBeanDeviceListener(mbeanListener);
+ mbeanListener.setDeviceNodeListener(viewer);
+ mbeanListener.activate();
+ activeConnection = mbsc;
+ connections.put(mbsc, mbeanListener);
+ }
+ else {
+ if (activeConnection != mbsc){
+ MBeanDeviceListener oldMbeanListener = (MBeanDeviceListener)connections.get(activeConnection);
+ oldMbeanListener.deactive();
+ MBeanListener.activate();
+ activeConnection = mbsc;
+ }
+ }
+
+ }
+
+ private void doControlPanel(){
+ panel = new JPanel(new BorderLayout());
+ viewer = new TreeViewer(bc);
+ viewer.setPreferredSize(new Dimension(140,300));
+ properties = new PropertiesViewer(bc);
+ Mediator.setPropertiesViewer(properties);
+
+ JSplitPane treeSplitter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,viewer,properties);
+ JPanel logPanel = new LogPanel();
+ logPanel.setPreferredSize(new Dimension(140,100));
+ JSplitPane logSplitter = new JSplitPane(JSplitPane.VERTICAL_SPLIT,treeSplitter,logPanel);
+ panel.add(logSplitter);
+ }
+
+ public JPanel getPanel(){
+ return panel;
+ }
+
+ /////////////////////////// MENU /////////////////////////////
+// JMenu searchMenu,loggerMenu,cyberMenu;
+// public void doMenuBar(JFrame frame) {
+//
+// JMenuBar menuBar = new JMenuBar();
+//
+// //////////////// FILE
+// JMenu file_menu = new JMenu("File");
+// file_menu.setMnemonic(KeyEvent.VK_F);
+//
+// searchMenu = new JMenu("Search");
+// final String ALL_DEVICE = "ssdp:all";
+// final String ROOT_DEVICE = "upnp:rootdevice";
+// searchMenu.setMnemonic(KeyEvent.VK_L);
+// searchMenu.setEnabled(false);
+// AbstractAction searchAction = new AbstractAction(){
+// public void actionPerformed(ActionEvent e) {
+// DriverProxy controller = Mediator.getDriverProxy();
+// if (e.getActionCommand().equals(ALL_DEVICE))
+// controller.doSearch(ALL_DEVICE);
+// else if (e.getActionCommand().equals(ROOT_DEVICE))
+// controller.doSearch(ROOT_DEVICE);
+// }
+// };
+//
+// JMenuItem rootDeviceItem = new JMenuItem("Root Devices");
+// rootDeviceItem.setMnemonic(KeyEvent.VK_R);
+// rootDeviceItem.addActionListener(searchAction);
+// rootDeviceItem.setActionCommand(ROOT_DEVICE);
+// searchMenu.add(rootDeviceItem);
+//
+// JMenuItem allDeviceItem = new JMenuItem("All Devices");
+// allDeviceItem .setMnemonic(KeyEvent.VK_A);
+// allDeviceItem .addActionListener(searchAction);
+// allDeviceItem .setActionCommand(ALL_DEVICE);
+// searchMenu.add(allDeviceItem);
+//
+//
+// JMenuItem checkIncompleteItem = new JMenuItem("Print Pending Devices");
+// checkIncompleteItem.setMnemonic(KeyEvent.VK_I);
+// checkIncompleteItem.addActionListener(new ActionListener() {
+// public void actionPerformed(ActionEvent e) {
+// Mediator.getRootDeviceListener().checkIncompleteDevice();
+// }
+// });
+//
+// JMenuItem checkErrataItem = new JMenuItem("Check Errata UPnPDevices");
+// checkErrataItem.setMnemonic(KeyEvent.VK_E);
+// checkErrataItem.addActionListener(new ActionListener() {
+// public void actionPerformed(ActionEvent e) {
+// RootDeviceListener.checkErrataDevice();}
+// });
+//
+//
+// loggerMenu = new JMenu("Felix Logger");
+// final String NO_LOGGING ="No Logging";
+// final String ERROR ="Error";
+// final String WARNING ="Warning";
+// final String INFO ="Info";
+// final String DEBUG ="Debug";
+//
+// loggerMenu.getPopupMenu().addPopupMenuListener(this);
+// loggerMenu.setMnemonic(KeyEvent.VK_L);
+// loggerMenu.setEnabled(false);
+// AbstractAction loggerAction = new AbstractAction(){
+// public void actionPerformed(ActionEvent e) {
+// DriverProxy controller = Mediator.getDriverProxy();
+// if (e.getActionCommand().equals(NO_LOGGING))
+// controller.setLogLevel(0);
+// else if (e.getActionCommand().equals(ERROR))
+// controller.setLogLevel(1);
+// else if (e.getActionCommand().equals(WARNING))
+// controller.setLogLevel(2);
+// else if (e.getActionCommand().equals(INFO))
+// controller.setLogLevel(3);
+// else if (e.getActionCommand().equals(DEBUG))
+// controller.setLogLevel(4);
+// }
+// };
+//
+// ButtonGroup group = new ButtonGroup();
+//
+// JRadioButtonMenuItem rbMenuItem = new JRadioButtonMenuItem(NO_LOGGING);
+// rbMenuItem.setSelected(true);
+// rbMenuItem.setMnemonic(KeyEvent.VK_N);
+// rbMenuItem.setActionCommand(NO_LOGGING);
+// rbMenuItem.addActionListener(loggerAction);
+// group.add(rbMenuItem);
+// loggerMenu.add(rbMenuItem);
+// loggerMenu.addSeparator();
+//
+// rbMenuItem = new JRadioButtonMenuItem(ERROR);
+// rbMenuItem.setMnemonic(KeyEvent.VK_E);
+// rbMenuItem.setActionCommand(ERROR);
+// rbMenuItem.addActionListener(loggerAction);
+// group.add(rbMenuItem);
+// loggerMenu.add(rbMenuItem);
+//
+// rbMenuItem = new JRadioButtonMenuItem(WARNING);
+// rbMenuItem.setMnemonic(KeyEvent.VK_W);
+// rbMenuItem.setActionCommand(WARNING);
+// rbMenuItem.addActionListener(loggerAction);
+// group.add(rbMenuItem);
+// loggerMenu.add(rbMenuItem);
+//
+// rbMenuItem = new JRadioButtonMenuItem(INFO);
+// rbMenuItem.setMnemonic(KeyEvent.VK_I);
+// rbMenuItem.setActionCommand(INFO);
+// rbMenuItem.addActionListener(loggerAction);
+// group.add(rbMenuItem);
+// loggerMenu.add(rbMenuItem);
+//
+// rbMenuItem = new JRadioButtonMenuItem(DEBUG);
+// rbMenuItem.setMnemonic(KeyEvent.VK_D);
+// rbMenuItem.setActionCommand(DEBUG);
+// rbMenuItem.addActionListener(loggerAction);
+// group.add(rbMenuItem);
+// loggerMenu.add(rbMenuItem);
+//
+// final String ON ="On";
+// final String OFF ="Off";
+// cyberMenu = new JMenu("Cyber Debugger");
+// cyberMenu.getPopupMenu().addPopupMenuListener(this);
+// cyberMenu.setMnemonic(KeyEvent.VK_C);
+// cyberMenu.setEnabled(false);
+// AbstractAction cyberAction = new AbstractAction(){
+// public void actionPerformed(ActionEvent e) {
+// DriverProxy controller = Mediator.getDriverProxy();
+// if (e.getActionCommand().equals(ON))
+// controller.setCyberDebug(true);
+// else if (e.getActionCommand().equals(OFF))
+// controller.setCyberDebug(false);
+// }
+// };
+//
+//
+// ButtonGroup cyberGroup = new ButtonGroup();
+// rbMenuItem = new JRadioButtonMenuItem(ON);
+// rbMenuItem.setSelected(true);
+// rbMenuItem.setMnemonic(KeyEvent.VK_O);
+// rbMenuItem.setActionCommand(ON);
+// rbMenuItem.addActionListener(cyberAction);
+// cyberGroup.add(rbMenuItem);
+// cyberMenu.add(rbMenuItem);
+//
+// rbMenuItem = new JRadioButtonMenuItem(OFF);
+// rbMenuItem.setMnemonic(KeyEvent.VK_F);
+// rbMenuItem.setActionCommand(OFF);
+// rbMenuItem.addActionListener(cyberAction);
+// cyberGroup.add(rbMenuItem);
+// cyberMenu.add(rbMenuItem);
+//
+// /*
+// JMenuItem clearSubscriptionItem = new JMenuItem("Clear Subscriptions");
+// clearSubscriptionItem.setMnemonic(KeyEvent.VK_S);
+// clearSubscriptionItem.addActionListener(new ActionListener() {
+// public void actionPerformed(ActionEvent e) {
+//// to do
+// }
+// });
+// */
+//
+// JMenuItem exitItem = new JMenuItem("Exit");
+// exitItem.setMnemonic(KeyEvent.VK_X);
+// exitItem.addActionListener(new ActionListener() {
+// public void actionPerformed(ActionEvent e) {
+// try {
+// Activator.context.getBundle().stop();
+// }catch (Exception ex){
+// ex.printStackTrace();
+// }
+// }
+// });
+//
+//
+// file_menu.add(searchMenu);
+// file_menu.addSeparator();
+// file_menu.add(loggerMenu);
+// file_menu.add(cyberMenu);
+// file_menu.addSeparator();
+// file_menu.add(checkIncompleteItem);
+// file_menu.add(checkErrataItem);
+// //file_menu.addSeparator();
+// //file_menu.add(clearSubscriptionItem);
+// file_menu.addSeparator();
+// file_menu.add(exitItem);
+//
+// menuBar.add(file_menu);
+// frame.setJMenuBar(menuBar);
+//
+// }
+
+
+// public void enableMenus(boolean driverAvailable,int logLevel,boolean cyberDebug) {
+// searchMenu.setEnabled(driverAvailable);
+// Component[] items = searchMenu.getPopupMenu().getComponents();
+// for (int i=0;i < items.length;i++)
+// items[i].setEnabled(driverAvailable);
+//
+// loggerMenu.setEnabled(driverAvailable);
+// items = loggerMenu.getPopupMenu().getComponents();
+// for (int i=0;i < items.length;i++)
+// items[i].setEnabled(driverAvailable);
+// if (driverAvailable){
+// ((JRadioButtonMenuItem)items[logLevel>0?logLevel+1:0]).setSelected(true);
+// }
+// cyberMenu.setEnabled(driverAvailable);
+// items = cyberMenu.getPopupMenu().getComponents();
+// for (int i=0;i < items.length;i++)
+// items[i].setEnabled(driverAvailable);
+// if (driverAvailable){
+// if (cyberDebug)
+// ((JRadioButtonMenuItem)items[0]).setSelected(true);
+// else
+// ((JRadioButtonMenuItem)items[1]).setSelected(true);
+// }
+// }
+//
+// public void popupMenuCanceled(PopupMenuEvent e) { }
+// public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { }
+//
+// public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
+// JPopupMenu loggerPopup = loggerMenu.getPopupMenu();
+// JPopupMenu cyberPopup = cyberMenu.getPopupMenu();
+// if (e.getSource()==loggerPopup){
+// int logLevel = Mediator.getDriverProxy().getLogLevel();
+// Component[] items = loggerPopup.getComponents();
+// ((JRadioButtonMenuItem)items[logLevel>0?logLevel+1:0]).setSelected(true);
+// }
+// else if (e.getSource()==cyberPopup){
+// boolean cyberDebug = Mediator.getDriverProxy().getCyberDebug();
+// Component[] items = cyberPopup.getComponents();
+// if (cyberDebug)
+// ((JRadioButtonMenuItem)items[0]).setSelected(true);
+// else
+// ((JRadioButtonMenuItem)items[1]).setSelected(true);
+// }
+//
+//
+// }
+
+
+
+
+}
Added: incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/Mediator.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/Mediator.java?view=auto&rev=470811
==============================================================================
--- incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/Mediator.java (added)
+++ incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/Mediator.java Fri Nov 3 05:44:25 2006
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.upnp.jmxbridge.tab;
+
+
+import javax.swing.*;
+
+import org.apache.felix.upnp.jmxbridge.tab.discovery.*;
+import org.apache.felix.upnp.jmxbridge.tab.gui.*;
+
+/*
+* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+*/
+public class Mediator {
+ static PropertiesViewer props;
+ static JTree tree;
+ static JFrame frame;
+ static MBeanDeviceListener rootDeviceListener;
+ static ControlPoint controlPoint;
+ static TreeViewer treeViewer;
+
+
+ public static void setPropertiesViewer(PropertiesViewer props){
+ Mediator.props=props;
+ }
+ public static PropertiesViewer getPropertiesViewer(){
+ return props;
+ }
+
+ public static void setUPnPDeviceTree(JTree tree){
+ Mediator.tree=tree;
+ }
+ public static JTree getUPnPDeviceTree(){
+ return tree;
+ }
+
+ public static void setTreeViewer(TreeViewer treeViewer){
+ Mediator.treeViewer=treeViewer;
+ }
+ public static TreeViewer getTreeViewer(){
+ return treeViewer;
+ }
+
+ public static void setControlPoint(ControlPoint controlPoint){
+ Mediator.controlPoint=controlPoint;
+ }
+ public static ControlPoint getControlPoint(){
+ return controlPoint;
+ }
+
+
+ public static void setMBeanDeviceListener(MBeanDeviceListener listener) {
+ Mediator.rootDeviceListener = listener;
+ }
+
+ public static MBeanDeviceListener getMBeanDeviceListener(){
+ return rootDeviceListener;
+ }
+}
Added: incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/RemoteUPnPAction.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/RemoteUPnPAction.java?view=auto&rev=470811
==============================================================================
--- incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/RemoteUPnPAction.java (added)
+++ incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/RemoteUPnPAction.java Fri Nov 3 05:44:25 2006
@@ -0,0 +1,122 @@
+package org.apache.felix.upnp.jmxbridge.tab;
+
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+
+import org.osgi.service.upnp.UPnPAction;
+import org.osgi.service.upnp.UPnPService;
+import org.osgi.service.upnp.UPnPStateVariable;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+public class RemoteUPnPAction implements UPnPAction {
+
+
+ private MBeanServerConnection mbsc;
+ private ObjectName mbeanName;
+ private UPnPService service;
+ private String name;
+ private Hashtable args;
+ private String inputArg[];
+ private String outputArg[];
+
+ class Argument {
+ String name;
+ String direction;
+ String relatedStateVariable;
+ }
+
+ public RemoteUPnPAction(MBeanServerConnection mbsc, ObjectName mbeanName, Node actionNode, UPnPService service) {
+ this.service = service;
+ this.mbsc = mbsc;
+ this.mbeanName = mbeanName;
+ args = new Hashtable();
+
+ NodeList list = actionNode.getChildNodes();
+ for (int i =0; i< list.getLength(); i++ ){
+ Node node = list.item(i);
+ String tag = node.getNodeName();
+ if (tag.equals("name")){
+ name = node.getTextContent();
+ } else if (tag.equals("argumentList")){
+ NodeList arguments = node.getChildNodes();
+ ArrayList inArgs = new ArrayList();
+ ArrayList outArgs = new ArrayList();
+ for (int j = 0; j < arguments.getLength();j++){
+ Argument arg = buildArgument(arguments.item(j));
+ if (arg != null){
+ args.put(arg.name,arg.relatedStateVariable);
+ if (arg.direction.equals("in"))
+ inArgs.add(arg.name);
+ else
+ outArgs.add(arg.name);
+ }
+ }
+ if (inArgs.size() > 0)
+ inputArg = (String[]) inArgs.toArray(new String[]{});
+ if (outArgs.size() > 0)
+ outputArg = (String[]) outArgs.toArray(new String[]{});
+ }
+
+
+ }
+ }
+
+ private Argument buildArgument(Node argumentNode) {
+ if (argumentNode.getNodeName().equals("argument")){
+ NodeList list = argumentNode.getChildNodes();
+ Argument arg = new Argument();
+ for (int i = 0; i<list.getLength();i++){
+ Node node = list.item(i);
+ String tag = node.getNodeName();
+ if (tag.equals("name")){
+ arg.name= node.getTextContent();
+ } else if (tag.equals("direction")){
+ arg.direction = node.getTextContent();
+ }else if (tag.equals("relatedStateVariable")){
+ arg.relatedStateVariable = node.getTextContent();
+ }
+ }
+ return arg;
+ }
+ return null;
+ }
+
+ public String[] getInputArgumentNames() {
+ return inputArg;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String[] getOutputArgumentNames() {
+ return outputArg;
+ }
+
+ public String getReturnArgumentName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public UPnPStateVariable getStateVariable(String argumentName) {
+ String relatedStateVariable = (String) args.get(argumentName);
+ if (relatedStateVariable != null)
+ return service.getStateVariable(relatedStateVariable);
+ return null;
+ }
+
+ public Dictionary invoke(Dictionary args) throws Exception {
+ Dictionary result = (Dictionary) mbsc.invoke(
+ mbeanName,
+ "invokeAction",
+ new Object[]{service.getId(), name, args},
+ new String[]{String.class.getName(),String.class.getName(),Dictionary.class.getName()});
+ return result;
+ }
+
+}
Added: incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/RemoteUPnPDevice.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/RemoteUPnPDevice.java?view=auto&rev=470811
==============================================================================
--- incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/RemoteUPnPDevice.java (added)
+++ incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/RemoteUPnPDevice.java Fri Nov 3 05:44:25 2006
@@ -0,0 +1,109 @@
+package org.apache.felix.upnp.jmxbridge.tab;
+
+import java.io.StringReader;
+import java.util.Dictionary;
+
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanException;
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+import javax.management.ReflectionException;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.osgi.service.upnp.UPnPDevice;
+import org.osgi.service.upnp.UPnPIcon;
+import org.osgi.service.upnp.UPnPService;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+
+public class RemoteUPnPDevice implements Runnable, UPnPDevice {
+ private ObjectName name;
+ private MBeanServerConnection mbsc;
+ private Dictionary properties;
+ private UPnPService[] upnpServices;
+
+ public RemoteUPnPDevice(MBeanServerConnection mbsc,ObjectName name){
+ this.mbsc=mbsc;
+ this.name=name;
+ run();
+ }
+
+ public void run() {
+ try {
+ properties= (Dictionary) mbsc.getAttribute(name, "DeviceDescription");
+ System.out.println("dictionary::" +properties);
+
+ String xmlDescription = (String) mbsc.getAttribute(name, "XMLDeviceDescription");
+ DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ Document doc = parser.parse(new InputSource(new StringReader(xmlDescription)));
+ Element root = doc.getDocumentElement();
+ System.out.println("root:"+root);
+
+ NodeList serviceList = root.getElementsByTagName("service");
+ int numOfServices = serviceList.getLength();
+ if (serviceList.getLength() > 0)
+ upnpServices = new UPnPService[numOfServices];
+ for (int i = 0; i < numOfServices;i++){
+ Node service = serviceList.item(i);
+ upnpServices[i] = makeUPnPService(service);
+ }
+
+ } catch (InstanceNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (MBeanException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (ReflectionException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (ParserConfigurationException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ private UPnPService makeUPnPService(Node service) {
+ String type = null, id = null;
+ NodeList list = service.getChildNodes();
+ for (int i = 0; i< list.getLength();i++){
+ Node node = list.item(i);
+ if (node.getNodeName().equals("serviceType"))
+ type = node.getTextContent();
+ else if (node.getNodeName().equals("serviceId"))
+ id = node.getTextContent();
+ }
+ return new RemoteUPnPService(mbsc,name, id, type);
+ }
+
+ public Dictionary getDescriptions(String locale) {
+ return properties;
+ }
+
+ public UPnPIcon[] getIcons(String locale) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public UPnPService getService(String serviceId) {
+ for (int i =0; i< upnpServices.length; i++){
+ UPnPService service = upnpServices[i];
+ if (service.getId().equals(serviceId))
+ return service;
+ }
+ return null;
+ }
+
+ public UPnPService[] getServices() {
+ return upnpServices;
+ }
+
+}
Added: incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/RemoteUPnPService.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/RemoteUPnPService.java?view=auto&rev=470811
==============================================================================
--- incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/RemoteUPnPService.java (added)
+++ incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/RemoteUPnPService.java Fri Nov 3 05:44:25 2006
@@ -0,0 +1,125 @@
+package org.apache.felix.upnp.jmxbridge.tab;
+
+import java.io.IOException;
+import java.io.StringReader;
+
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanException;
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+import javax.management.ReflectionException;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.osgi.service.upnp.UPnPAction;
+import org.osgi.service.upnp.UPnPService;
+import org.osgi.service.upnp.UPnPStateVariable;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+public class RemoteUPnPService implements UPnPService {
+
+ private MBeanServerConnection mbsc;
+ private ObjectName name;
+ private String id;
+ private String type;
+ private UPnPAction[] upnpActions;
+ private UPnPStateVariable[] upnpStateVariables;
+
+ public RemoteUPnPService(MBeanServerConnection mbsc, ObjectName name, String id, String type) {
+ this.id = id;
+ this.type = type;
+ this.mbsc = mbsc;
+ this.name = name;
+ try {
+ String xmlservice = (String) mbsc.invoke(name, "getXMLServiceDescription", new Object[]{id}, new String[]{String.class.getName()});
+
+ DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ Document doc = parser.parse(new InputSource(new StringReader(xmlservice)));
+ Element root = doc.getDocumentElement();
+
+ NodeList variableList =root.getElementsByTagName("stateVariable");
+ int numOfVariables = variableList.getLength();
+ upnpStateVariables = new UPnPStateVariable[numOfVariables];
+ for (int i =0; i<numOfVariables;i++){
+ Node node = variableList.item(i);
+ upnpStateVariables[i] = new RemoteUPnPStateVariable(node);
+ }
+
+ NodeList actionList =root.getElementsByTagName("action");
+ int numOfActions = actionList.getLength();
+ upnpActions = new UPnPAction[numOfActions];
+ for (int i =0; i<numOfActions;i++){
+ Node node = actionList.item(i);
+ upnpActions[i] = new RemoteUPnPAction(mbsc,name, node, this);;
+ }
+
+ } catch (InstanceNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (MBeanException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (ReflectionException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (ParserConfigurationException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (SAXException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+
+ }
+
+
+ public UPnPAction getAction(String name) {
+ for (int i =0; i< upnpStateVariables.length; i++){
+ UPnPAction action = upnpActions[i];
+ if (action.getName().equals(name))
+ return action;
+ }
+ return null;
+ }
+
+ public UPnPAction[] getActions() {
+ return upnpActions;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public UPnPStateVariable getStateVariable(String name) {
+ for (int i =0; i< upnpStateVariables.length; i++){
+ UPnPStateVariable variable = upnpStateVariables[i];
+ if (variable.getName().equals(name))
+ return variable;
+ }
+ return null;
+ }
+
+ public UPnPStateVariable[] getStateVariables() {
+ return upnpStateVariables;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public String getVersion() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Added: incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/RemoteUPnPStateVariable.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/RemoteUPnPStateVariable.java?view=auto&rev=470811
==============================================================================
--- incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/RemoteUPnPStateVariable.java (added)
+++ incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/RemoteUPnPStateVariable.java Fri Nov 3 05:44:25 2006
@@ -0,0 +1,138 @@
+package org.apache.felix.upnp.jmxbridge.tab;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Hashtable;
+
+import org.osgi.service.upnp.UPnPStateVariable;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+public class RemoteUPnPStateVariable implements UPnPStateVariable {
+
+ private String name;
+ private String dataType;
+ private String sendEvents;
+ private String[] values;
+
+ private static Hashtable upnp2javaTable = null;
+
+ static{
+ upnp2javaTable = new Hashtable(30);
+ String[] upnpType = null;
+ upnpType = new String[]{"ui1","ui2","i1","i2","i4","int"};
+ for (int i = 0; i < upnpType.length; i++) {
+ upnp2javaTable.put(upnpType[i],Integer.class);
+ }
+
+ upnpType = new String[]{"ui4","time","time.tz"};
+ for (int i = 0; i < upnpType.length; i++) {
+ upnp2javaTable.put(upnpType[i],Long.class);
+ }
+
+ upnpType = new String[]{"r4","float"};
+ for (int i = 0; i < upnpType.length; i++) {
+ upnp2javaTable.put(upnpType[i],Float.class);
+ }
+
+ upnpType = new String[]{"r8","number","fixed.14.4"};
+ for (int i = 0; i < upnpType.length; i++) {
+ upnp2javaTable.put(upnpType[i],Double.class);
+ }
+
+ upnpType = new String[]{"char"};
+ for (int i = 0; i < upnpType.length; i++) {
+ upnp2javaTable.put(upnpType[i],Character.class);
+ }
+
+ upnpType = new String[]{"string","uri","uuid"};
+ for (int i = 0; i < upnpType.length; i++) {
+ upnp2javaTable.put(upnpType[i],String.class);
+ }
+
+ upnpType = new String[]{"date","dateTime","dateTime.tz"};
+ for (int i = 0; i < upnpType.length; i++) {
+ upnp2javaTable.put(upnpType[i],Date.class);
+ }
+
+ upnpType = new String[]{"boolean"};
+ for (int i = 0; i < upnpType.length; i++) {
+ upnp2javaTable.put(upnpType[i],Boolean.class);
+ }
+
+ upnpType = new String[]{"bin.base64","bin.hex"};
+ for (int i = 0; i < upnpType.length; i++) {
+ upnp2javaTable.put(upnpType[i],byte[].class);
+ }
+
+ }
+
+ public RemoteUPnPStateVariable(Node variablenode) {
+ NamedNodeMap attributes = variablenode.getAttributes();
+ if (attributes != null){
+ Node attribute = attributes.getNamedItem("sendEvents");
+ sendEvents = attribute.getTextContent();
+ }
+ NodeList list = variablenode.getChildNodes();
+ for (int i =0; i< list.getLength(); i++ ){
+ Node node = list.item(i);
+ String tag = node.getNodeName();
+ if (tag.equals("name")){
+ name = node.getTextContent();
+ } else if (tag.equals("dataType")){
+ dataType = node.getTextContent();
+ }else if (tag.equals("allowedValueList")){
+ NodeList valueNodes = node.getChildNodes();
+ ArrayList allowedValues = new ArrayList();
+ for (int j = 0; j < valueNodes.getLength();j++){
+ Node valueNode = valueNodes.item(j);
+ allowedValues.add(valueNode.getTextContent());
+ }
+ values = (String[])allowedValues.toArray(new String[]{});
+ }
+ }
+ }
+
+ public String[] getAllowedValues() {
+ return values;
+ }
+
+ public Object getDefaultValue() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Class getJavaDataType() {
+ return (Class) upnp2javaTable.get(getUPnPDataType());
+ }
+
+ public Number getMaximum() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Number getMinimum() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Number getStep() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getUPnPDataType() {
+ return dataType;
+ }
+
+ public boolean sendsEvents() {
+ if (sendEvents == null) return false;
+ return sendEvents.equals("yes")? true: false;
+ }
+
+}
Added: incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/RemoteUPnPTabUI.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/RemoteUPnPTabUI.java?view=auto&rev=470811
==============================================================================
--- incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/RemoteUPnPTabUI.java (added)
+++ incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/RemoteUPnPTabUI.java Fri Nov 3 05:44:25 2006
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.upnp.jmxbridge.tab;
+
+import java.awt.Component;
+import java.beans.PropertyChangeEvent;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+import javax.swing.JPanel;
+
+import org.apache.felix.mosgi.console.ifc.Plugin;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+public class RemoteUPnPTabUI extends JPanel implements Plugin, BundleActivator {
+
+ private BundleContext m_context = null;
+ private ServiceRegistration sreg = null;
+ private MBeanServerConnection mbsc;
+ private ControlPoint controlPoint;
+
+ public RemoteUPnPTabUI(){}
+
+
+ ///////////////////////////////////////////
+ // 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(){
+ if (sreg!=null){
+ sreg.unregister();
+ sreg=null;
+ }
+ }
+
+ public String pluginLocation(){
+ return m_context.getBundle().getLocation();
+ }
+
+ public String getName(){return "Remote UPnP Network";}
+
+ public Component getGUI(){
+ if (controlPoint == null){
+ controlPoint = new ControlPoint(m_context);
+ controlPoint.getPanel().setName(getName());
+ }
+ return controlPoint.getPanel();
+ }
+
+ 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
+ *
+ */
+
+ String action=e.getPropertyName();
+
+ if (action.equals(Plugin.NEW_NODE_READY)){
+ Mediator.getTreeViewer().clearAll();
+ this.mbsc=(MBeanServerConnection)e.getNewValue();
+ this.initControlPoint(mbsc);
+ }else if(action.equals(Plugin.EMPTY_NODE)){
+ Mediator.getTreeViewer().clearAll();
+ }else if(action.equals(Plugin.PLUGIN_ACTIVATED) && e.getNewValue().equals(this.getName())){
+ //this.initControlPoint(mbsc);
+ }
+ }
+
+ private void initControlPoint(MBeanServerConnection mbsc){
+ try{
+
+ this.mbsc = mbsc;
+ controlPoint.setConnection(mbsc);
+ ObjectName name =new ObjectName("UPnPDevice:*");
+ Set objects = mbsc.queryNames(name, null);
+
+
+ Iterator list = objects.iterator();
+ while (list.hasNext()){
+ ObjectName obj = (ObjectName) list.next();
+ RemoteUPnPDevice device = new RemoteUPnPDevice(mbsc,obj);
+ Mediator.getMBeanDeviceListener().addNewDevice(device);
+ }
+ }catch (Exception e){
+ e.printStackTrace();
+ }
+ }
+
+
+}
Added: incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/UPnPSubscriber.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/UPnPSubscriber.java?view=auto&rev=470811
==============================================================================
--- incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/UPnPSubscriber.java (added)
+++ incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/UPnPSubscriber.java Fri Nov 3 05:44:25 2006
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.upnp.jmxbridge.tab;
+
+import java.util.*;
+
+import org.osgi.framework.*;
+import org.osgi.service.upnp.*;
+
+/*
+* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+*/
+public class UPnPSubscriber {
+ private BundleContext context;
+ private UPnPEventListener listener;
+ private HashMap hash;
+
+ private class Subscription implements UPnPEventListener{
+ ServiceRegistration registration;
+
+ Subscription(String keys){
+ try {
+ Filter filter = context.createFilter(keys);
+ Properties props = new Properties();
+ props.put(UPnPEventListener.UPNP_FILTER, filter);
+ registration = context.registerService(UPnPEventListener.class.getName(), this, props);
+ }catch (Exception ex){
+ System.out.println(ex);
+ }
+ }
+
+ public void unsubscribe(){
+ registration.unregister();
+ }
+
+ public void notifyUPnPEvent(String arg0, String arg1, Dictionary arg2) {
+ listener.notifyUPnPEvent( arg0, arg1, arg2);
+ }
+ }
+
+
+ public UPnPSubscriber(BundleContext context,UPnPEventListener listener){
+ this.context = context;
+ this.listener = listener;
+ hash = new HashMap();
+ }
+
+ public void subscribe(String deviceId, String serviceId){
+ String keys = "(&(" + UPnPDevice.ID + "="+ deviceId + ")(" + UPnPService.ID + "=" + serviceId + "))";
+ if (hash.get(keys) == null){
+ hash.put(keys, new Subscription(keys));
+ }
+ }
+
+ public void unsubscribe(String deviceId, String serviceId){
+ String keys = "(&(" + UPnPDevice.ID + "="+ deviceId + ")(" + UPnPService.ID + "=" + serviceId + "))";
+ if (hash.containsKey(keys)) {
+ Subscription subscription = (Subscription) hash.get(keys);
+ subscription.unsubscribe();
+ hash.remove(keys);
+ }
+ }
+
+
+
+
+}
Added: incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/discovery/DeviceChangeListener.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/discovery/DeviceChangeListener.java?view=auto&rev=470811
==============================================================================
--- incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/discovery/DeviceChangeListener.java (added)
+++ incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/discovery/DeviceChangeListener.java Fri Nov 3 05:44:25 2006
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.upnp.jmxbridge.tab.discovery;
+
+/*
+* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+*/
+public interface DeviceChangeListener {
+
+ public void addedDevice(DeviceNode dn);
+
+ public void removedDevice(DeviceNode dn);
+
+}
Added: incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/discovery/DeviceNode.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/discovery/DeviceNode.java?view=auto&rev=470811
==============================================================================
--- incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/discovery/DeviceNode.java (added)
+++ incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/discovery/DeviceNode.java Fri Nov 3 05:44:25 2006
@@ -0,0 +1,184 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.upnp.jmxbridge.tab.discovery;
+import java.util.*;
+
+import org.osgi.framework.*;
+import org.osgi.service.upnp.*;
+
+/*
+* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+*/
+public class DeviceNode {
+
+ private UPnPDevice upnpDevice;
+ private boolean isRootNode;
+ private String udn ;
+ private boolean hasChild;
+ private int numberOfSons;
+ private ArrayList children;
+ private DeviceNode parent;
+
+ public DeviceNode(UPnPDevice upnpDevice){
+ this.upnpDevice = upnpDevice;
+ udn = (String) upnpDevice.getDescriptions(null).get(UPnPDevice.UDN.toLowerCase());
+ parent=null;
+ isRootNode = (upnpDevice.getDescriptions(null).get(UPnPDevice.PARENT_UDN.toLowerCase()) == null);
+ String[] sons = ((String[]) upnpDevice.getDescriptions(null).get(UPnPDevice.CHILDREN_UDN.toLowerCase()));
+ hasChild = (sons != null);
+ if (hasChild) {
+ children = new ArrayList();
+ numberOfSons = sons.length;
+ }
+ }
+
+ public UPnPDevice getDevice(){
+ return upnpDevice;
+ }
+
+ public void attach(DeviceNode node){
+ if (node == null)
+ throw new IllegalArgumentException("null is not a valid arg in DeviceNode.attach() method");
+ node.parent = this;
+ /*
+ //Operation to let DeviceNode::isComplete() O(1)
+ if((numberOfSons==children.size()-1)
+ &&(node.isComplete())){
+ this.isComplete = true;
+ }
+ */
+ children.add(node);
+ }
+
+ public DeviceNode dethatch(String name){
+ DeviceNode dn = this.search(name);
+ if(dn==null)
+ return null;
+
+ if(dn.parent!=null){
+ Iterator list = dn.parent.children.iterator();
+ while (list.hasNext()) {
+ DeviceNode x = (DeviceNode) list.next();
+ if(x.udn.equals(name)){
+ list.remove();
+ /*
+ //Operation to let DeviceNode::isComplete() O(1)
+ dn.parent.isComplete=false;
+ */
+ break;
+ }
+ }
+ }
+ dn.parent=null;
+ return dn;
+ }
+
+ public Collection getAllChildren(){
+ if((this.children==null)||(this.children.size()==0))
+ return new ArrayList();
+
+ Vector v = new Vector(this.children);
+ Iterator list = this.children.iterator();
+ while (list.hasNext()) {
+ DeviceNode x = (DeviceNode) list.next();
+ Collection c = x.getAllChildren();
+ if(c==null) continue;
+ v.addAll(c);
+ }
+ return v;
+ }
+
+ public Collection getChildren(){
+ if((this.children==null)||(this.children.size()==0))
+ return new ArrayList();
+ return this.children;
+ }
+
+ /**
+ * @param name <code>String</code> that contain the UDN to look for
+ * @return return a <code>DeviceNode</code> that have the UDN equals to name and <br>
+ * if there is any <code>DeviceNode</code> with the proper UDN value return <code>null</code>
+ */
+ public DeviceNode search(String name){
+ if (name == null)
+ throw new IllegalArgumentException("null is not a valid arg in DeviceNode.search() method");
+ if (name.equals(udn))
+ return this;
+ else if (hasChild){
+ Iterator list = children.iterator();
+ while (list.hasNext()){
+ DeviceNode child = (DeviceNode)list.next();
+ DeviceNode node = child.search(name);
+ if (node != null) return node;
+ }
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @param udn
+ * @return <code>true</code> if and only if this <code>DeviceNode</code>
+ * contains a DeviceNode with UDN equals to passed argument or if
+ * its USN is equal to passed argument
+ */
+ public boolean contains(String udn){
+ return this.search(udn)!=null;
+ }
+
+ public boolean isComplete(){
+ /*
+ //Operation to let DeviceNode::isComplete() O(1)
+ return isComplete;
+ */
+ if (! hasChild) return true;
+ if (numberOfSons != children.size())return false;
+ Iterator list = children.iterator();
+ while (list.hasNext()){
+ DeviceNode child = (DeviceNode)list.next();
+ if (! child.isComplete()) return false;
+ }
+ return true;
+ }
+
+ public DeviceNode isAttachable(DeviceNode node){
+ if (node == null)
+ throw new IllegalArgumentException("null is not a valid arg in DeviceNode.isAttachable() method");
+ String parentUDN=(String) upnpDevice.getDescriptions(null).get(UPnPDevice.PARENT_UDN.toLowerCase());
+ if(parentUDN==null) return null;
+ return search(parentUDN);
+ }
+
+ public boolean isRoot(){
+ return isRootNode;
+ }
+
+ public boolean equals(String udn){
+ return this.udn.equals(udn);
+ }
+
+ public String toString(){
+ return udn;
+ }
+ public boolean isLeaf() {
+ return !hasChild;
+ }
+
+}
Added: incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/discovery/DeviceNodeListener.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/discovery/DeviceNodeListener.java?view=auto&rev=470811
==============================================================================
--- incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/discovery/DeviceNodeListener.java (added)
+++ incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/discovery/DeviceNodeListener.java Fri Nov 3 05:44:25 2006
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.upnp.jmxbridge.tab.discovery;
+
+/*
+* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+*/
+public interface DeviceNodeListener {
+ public void deviceDetected(DeviceNode d);
+ public void rootDeviceUnplugged(String udn);
+}
Added: incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/discovery/MBeanDeviceListener.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/discovery/MBeanDeviceListener.java?view=auto&rev=470811
==============================================================================
--- incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/discovery/MBeanDeviceListener.java (added)
+++ incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/discovery/MBeanDeviceListener.java Fri Nov 3 05:44:25 2006
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.upnp.jmxbridge.tab.discovery;
+
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import javax.management.InstanceNotFoundException;
+import javax.management.ListenerNotFoundException;
+import javax.management.MBeanServerConnection;
+import javax.management.MalformedObjectNameException;
+import javax.management.Notification;
+import javax.management.NotificationListener;
+import javax.management.ObjectName;
+
+import org.apache.felix.upnp.jmxbridge.tab.RemoteUPnPDevice;
+import org.apache.felix.upnp.jmxbridge.tab.gui.LogPanel;
+import org.osgi.service.upnp.UPnPDevice;
+
+/*
+* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+*/
+public class MBeanDeviceListener implements NotificationListener {
+
+ //This list contains all partial tree of UPnP Device
+ //when a device is complete it will be removed from the list
+ private ArrayList devices;
+
+ private DeviceNodeListener listener;
+
+ private MBeanServerConnection mbsc;
+
+
+ public MBeanDeviceListener(MBeanServerConnection mbsc){
+ this.mbsc = mbsc;
+ devices = new ArrayList();
+
+ }
+
+ public void setDeviceNodeListener(DeviceNodeListener listener){
+ this.listener = listener;
+ }
+
+ public synchronized void addNewDevice(UPnPDevice upnpDevice){
+ LogPanel.log("adding device:"+upnpDevice.getDescriptions(null).get(UPnPDevice.FRIENDLY_NAME.toLowerCase()));
+ DeviceNode node = new DeviceNode(upnpDevice);
+
+ if(node.isRoot() && node.isLeaf()){
+ //Obiovsly
+ listener.deviceDetected(node);
+ return;
+ }
+
+ if(!node.isLeaf()){
+ //I look if there is some partial tree that is child
+ //of my new node. This operation may complete the tree
+ Iterator list = devices.iterator();
+ DeviceNode handle = null;
+ while(list.hasNext()){
+ DeviceNode tree = (DeviceNode) list.next();
+ if((handle = node.isAttachable(tree)) != null){
+ handle.attach(tree);
+ list.remove();
+ monitorDevices();
+ if(node.isRoot() && node.isComplete()){
+ listener.deviceDetected(node);
+ return;
+ }
+ }
+ }
+ }
+
+ if(!node.isRoot()){
+ //I look if there is some partial tree that should own
+ //my new node. This operation may complete the tree
+ Iterator list = devices.iterator();
+ DeviceNode handle = null;
+ while(list.hasNext()){
+ DeviceNode tree = (DeviceNode) list.next();
+ if((handle = tree.isAttachable(node)) != null){
+ handle.attach(node);
+ if(tree.isRoot() && tree.isComplete()){
+ list.remove();
+ monitorDevices();
+ listener.deviceDetected(tree);
+// removeChildren(tree);
+ }
+ return;
+ }
+ }
+ }
+
+ devices.add(node);
+ monitorDevices();
+ }
+
+ private void monitorDevices() {
+ LogPanel.status("Pending Devices: " + devices.size() );
+ }
+
+ public void removeDevice(ObjectName name){
+ String quotedUDN = name.getKeyProperty(UPnPDevice.UDN);
+ String UDN =quotedUDN.substring(1, quotedUDN.length()-1);
+ LogPanel.log("removing root device ..."+ UDN);
+ listener.rootDeviceUnplugged(UDN);
+ }
+
+ /**
+ * Register this object to listen to all "well registered" UPnPDevice<br>
+ * that should be Exported<br>
+ * And look for all the already registered UPnPDevice to be exported
+ *
+ */
+
+
+ public void activate() {
+ try {
+ ObjectName remoteUPnPCP = new ObjectName("TabUI:name=UPnP");
+ mbsc.addNotificationListener(remoteUPnPCP, this, null, null);
+ } catch (MalformedObjectNameException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (NullPointerException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (InstanceNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ *
+ */
+ public void deactive() {
+ try {
+ ObjectName remoteUPnPCP = new ObjectName("TabUI:name=UPnP");
+ mbsc.removeNotificationListener(remoteUPnPCP, this);
+ } catch (InstanceNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (ListenerNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (MalformedObjectNameException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (NullPointerException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ public void handleNotification(final Notification notification, Object handback) {
+ System.out.println("Notifiaction::" +notification);
+ if (notification.getType().equals("org.apache.felix.upnp.jmxbridge.mbean.registered")){
+ new Thread(new Runnable(){
+ public void run() {
+ ObjectName name = (ObjectName) notification.getSource();
+ RemoteUPnPDevice device = new RemoteUPnPDevice(mbsc,name);
+ addNewDevice(device);
+ }
+ }).start();
+ } else if (notification.getType().equals("org.apache.felix.upnp.jmxbridge.mbean.unregistered")){
+ new Thread(new Runnable(){
+ public void run() {
+ ObjectName name = (ObjectName) notification.getSource();
+ removeDevice(name);
+ }
+ }).start();
+ }
+
+ }
+
+
+}
Added: incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/gui/ActionPanel.java
URL: http://svn.apache.org/viewvc/incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/gui/ActionPanel.java?view=auto&rev=470811
==============================================================================
--- incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/gui/ActionPanel.java (added)
+++ incubator/felix/sandbox/furfari/upnp.jmxbridge.tab/src/main/java/org/apache/felix/upnp/jmxbridge/tab/gui/ActionPanel.java Fri Nov 3 05:44:25 2006
@@ -0,0 +1,365 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.upnp.jmxbridge.tab.gui;
+
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.GridBagLayout;
+import java.awt.event.ActionEvent;
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import javax.swing.AbstractAction;
+import javax.swing.AbstractCellEditor;
+import javax.swing.DefaultCellEditor;
+import javax.swing.JButton;
+import javax.swing.JComboBox;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JSlider;
+import javax.swing.JTable;
+import javax.swing.JTextField;
+import javax.swing.SwingConstants;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import javax.swing.event.TableModelEvent;
+import javax.swing.table.AbstractTableModel;
+import javax.swing.table.TableCellEditor;
+import javax.swing.table.TableModel;
+
+import org.apache.felix.upnp.jmxbridge.tab.gui.Converter;
+import org.osgi.service.upnp.UPnPException;
+import org.apache.felix.upnp.jmxbridge.tab.Mediator;
+import org.osgi.service.upnp.UPnPAction;
+import org.osgi.service.upnp.UPnPStateVariable;
+
+/*
+* @author <a href="mailto:felix-dev@incubator.apache.org">Felix Project Team</a>
+*/
+public class ActionPanel extends JPanel {
+
+ UPnPAction action;
+ ArgumentsModel argsModel;
+ MyTable table;
+ JPanel buttonPanel;
+
+ OutputArgumentsModel outArgsModel;
+ JTable outTable;
+
+ /**
+ *
+ */
+ public ActionPanel() {
+ super(new GridBagLayout());
+ buildButtonPanel();
+ buildTable();
+ add(new JScrollPane(table),Util.setConstrains(0,0,1,1,100,100));
+ add(new JScrollPane(outTable),Util.setConstrains(0,1,1,1,100,100));
+ add(buttonPanel,Util.setConstrains(1,0,1,1,1,1));
+ }
+
+ private void buildButtonPanel(){
+ buttonPanel = new JPanel();
+ JButton doAction = new JButton("Do Action");
+ doAction.addActionListener(new AbstractAction(){
+ public void actionPerformed(ActionEvent e) {
+ outArgsModel.clearData();
+
+ Dictionary params = null;
+ Dictionary result = null;
+ if (argsModel.getRowCount()!= 0){
+ if (table.isEditing()) table.getCellEditor().stopCellEditing();
+ params = new Hashtable();
+ for (int i =0;i<argsModel.getRowCount();i++){
+ String name = (String) argsModel.getValueAt(i,0);
+ String value = (String)argsModel.getValueAt(i,3);
+ try {
+ params.put(
+ name,
+ Converter.parseString(
+ value,
+ action.getStateVariable(name).getUPnPDataType()));
+ } catch (Exception ex) {
+ LogPanel.log("Error invoking action (bad parameter)");
+ return ;
+ }
+ }
+ }
+ try {result = action.invoke(params);}
+ catch (UPnPException ex){
+ String error =
+ "===== Action Failed =====" +
+ "\nUPnP Error Code::\n " +ex.getUPnPError_Code() +
+ "\nUPnP Error Description::\n " +ex.getMessage();
+ printReport(params,error);
+ JOptionPane.showMessageDialog(
+ Mediator.getPropertiesViewer(),error);
+ }
+ catch (Exception ex){
+ printReport(params,ex.getMessage());
+ JOptionPane.showMessageDialog(
+ Mediator.getPropertiesViewer(),
+ ex.getMessage()
+ );
+ }
+ if (result != null) {
+ printReport(params,result);
+ outArgsModel.setData(action,result);
+ JOptionPane.showMessageDialog(
+ Mediator.getPropertiesViewer(),
+ "Action invoked!"
+ );
+
+ }
+ }
+ private void printReport(Dictionary params,Object result) {
+ String input = "";
+ String output = "";
+ if (params != null) input = params.toString();
+ if (output != null) output = result.toString();
+ String method = action.getName();
+ String report = "\n==== Action:: " + method + " ====\n"
+ + input
+ + "\n----------- result ----------\n"
+ + output
+ + "\n-----------------------------";
+ LogPanel.log(report);
+ }
+ });
+ buttonPanel.add(doAction);
+ }
+
+ private void buildTable(){
+ argsModel = new ArgumentsModel();
+ table = new MyTable(argsModel);
+ argsModel.setTable(table);
+
+ outArgsModel = new OutputArgumentsModel();
+ outTable = new JTable(outArgsModel);
+ }
+
+ public void setArguments(UPnPAction action){
+ this.action = action;
+ argsModel.setData(action);
+ outArgsModel.clearData();
+ }
+
+}
+
+//thanks to Thomas Wagner 18/10/2005
+class OutputArgumentsModel extends ArgumentsModel {
+
+ public OutputArgumentsModel() {
+ super();
+ header = new String[]{"output arg name","related Var","Java \\ UpnP type","value"};
+ }
+
+ public void clearData() {
+ names = new String[]{""};
+ related = new String[]{""};
+ types = new String[]{""};
+ values = new String[]{""};
+ size=0;
+ this.fireTableChanged(new TableModelEvent(this));
+ }
+
+ public void setData(UPnPAction action, Object result){
+
+ Hashtable res = (Hashtable) result;
+
+ String[] names = action.getOutputArgumentNames();
+ size = 0;
+ this.names = names;
+ if (names!=null){
+ values = new String[names.length];
+ types = new String[names.length];
+ related = new String[names.length];
+ for (int i=0;i<names.length;i++) {
+ UPnPStateVariable currentStateVar = action.getStateVariable(names[i]);
+
+ Object value = res.get(names[i]);
+ values[i]=value.toString();
+ related[i] = currentStateVar.getName();
+
+ String javaType =currentStateVar.getJavaDataType().toString();
+ javaType = javaType.substring(javaType.lastIndexOf('.')+1);
+ String upnpType = currentStateVar.getUPnPDataType();
+ types[i] = javaType + " \\ " + upnpType;
+ }
+ size = names.length;
+ }
+ this.fireTableChanged(new TableModelEvent(this));
+ }
+}
+
+//thanks to Thomas Wagner 12/10/2005
+class ArgumentsModel extends AbstractTableModel {
+ int size = 0;
+ private MyTable table;
+ String[] names = new String[]{""};
+ String[] related = new String[]{""};
+ String[] types = new String[]{""};
+ String[] values = new String[]{""};
+ String[] header = new String[]{"arg name","related Var","Java \\ UpnP type","value"};
+
+ public void setTable(MyTable table) {
+ this.table = table;
+ }
+
+ public int getColumnCount() { return 4; }
+ public int getRowCount() { return size;}
+ public String getColumnName(int col) { return header[col]; }
+ public boolean isCellEditable(int rowIndex, int columnIndex) {
+ return (columnIndex ==3);
+ }
+ public Object getValueAt(int row, int col) {
+ if (col == 0) return names[row];
+ else if (col == 1) return related[row];
+ else if (col == 2) return types[row];
+ else if (col == 3) return values[row];
+ return null;
+ }
+ public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
+ values[rowIndex]= (String) aValue;
+ }
+
+ public void setData(UPnPAction action){
+
+ table.deleteMyCellEditors();
+
+
+ String[] names = action.getInputArgumentNames();
+ size = 0;
+ this.names = names;
+ if (names!=null){
+ values = new String[names.length];
+ related = new String[names.length];
+ types = new String[names.length];
+ for (int i=0;i<names.length;i++) {
+ values[i]="";
+ UPnPStateVariable currentStateVar = action.getStateVariable(names[i]);
+ related[i] = currentStateVar.getName();
+ String javaType = currentStateVar.getJavaDataType().toString();
+ javaType = javaType.substring(javaType.lastIndexOf('.')+1);
+ String upnpType = currentStateVar.getUPnPDataType();
+ types[i] = javaType + " \\ " + upnpType;
+
+ //handle allowed value list
+ if ( currentStateVar.getAllowedValues() != null) {
+ String av[] = currentStateVar.getAllowedValues();
+ JComboBox comboBox = new JComboBox();
+ for (int j = 0; j < av.length; j++) {
+ comboBox.addItem(av[j]);
+ }
+ values[i] = av[0]; //preset the first value from list
+ table.setMyCellEditor(new DefaultCellEditor(comboBox),i);
+ }
+
+ //handle default value
+ if (currentStateVar.getDefaultValue() != null) {
+ String val = currentStateVar.getDefaultValue().toString();
+ if(val.length() > 0)
+ values[i] = val;
+ }
+
+ //handle range values
+ if ((currentStateVar.getMaximum()!= null)
+ &&(currentStateVar.getMinimum()!= null)){
+ int max = currentStateVar.getMaximum().intValue();
+ int min = currentStateVar.getMinimum().intValue();
+ int value = min;
+ try { value = Integer.parseInt(values[i]);}
+ catch (NumberFormatException ignored){}
+ table.setMyCellEditor(new SliderEditor(min,max,value),i);
+ }
+
+ }
+ size = names.length;
+ }
+ this.fireTableChanged(new TableModelEvent(this));
+ this.fireTableStructureChanged();
+ }
+}
+
+// thanks to Thomas Wagner 12/10/2005
+class MyTable extends JTable {
+
+ private Hashtable cellEditors;
+
+ public MyTable(TableModel dm) {
+ super(dm);
+ cellEditors = new Hashtable();
+ }
+
+ public void setMyCellEditor(TableCellEditor editor,int col){
+ cellEditors.put(new Integer(col),editor);
+ }
+
+ public void deleteMyCellEditors(){
+ cellEditors.clear();
+ }
+
+ //overwritten JTable method
+ public TableCellEditor getCellEditor(int row,int col) {
+ TableCellEditor tce = (TableCellEditor) cellEditors.get(new Integer(row));
+ if( tce != null) {
+ return tce;
+ } else {
+ return super.getCellEditor(row,col);
+ }
+ }
+}
+
+class SliderEditor extends AbstractCellEditor implements TableCellEditor
+{
+ JPanel editor;
+ JTextField text;
+ JSlider slider;
+ public SliderEditor(int min, int max, int value){
+ editor = new JPanel(new BorderLayout());
+ //editor.setBorder(new EmptyBorder(1,0,1,0));
+ text = new JTextField(Integer.toString(max).length());
+ slider = new JSlider(SwingConstants.HORIZONTAL,min,max,value);
+ editor.add(text,BorderLayout.WEST);
+ editor.add(slider);
+ slider.addChangeListener(new ChangeListener(){
+ public void stateChanged(ChangeEvent e) {
+ //if (! replSlider.getValueIsAdjusting()){
+ text.setText(new Integer(slider.getValue()).toString());
+ //}
+ }
+ });
+
+ }
+
+ public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
+ text.setText((String) value);
+ try {
+ slider.setValue(Integer.parseInt((String)value));
+ } catch (NumberFormatException ignored) {}
+ return editor;
+ }
+
+ public Object getCellEditorValue() {
+ return text.getText();
+ }
+}
+