summaryrefslogtreecommitdiff
path: root/org
diff options
context:
space:
mode:
authorMatthew Johnson <mjj29@adonis.trinhall.cam.ac.uk>2007-05-26 16:08:48 +0100
committerMatthew Johnson <mjj29@adonis.trinhall.cam.ac.uk>2007-05-26 16:08:48 +0100
commit28d6ab16baad2d64a50b9f29454b0666f220d430 (patch)
treed7127d9476038df491e3d84576c9799f58773981 /org
parent7a930e3223adf2438cbc0e54e8bafd02ad5abc34 (diff)
+++ b/changelog
+ * Apply recursive-path patch for DBusViewer (written by Zsombor Gegesy + <gzsombor -at- gmail -dot- com>) +
Diffstat (limited to 'org')
-rw-r--r--org/freedesktop/dbus/viewer/DBusEntry.java21
-rw-r--r--org/freedesktop/dbus/viewer/DBusTableModel.java12
-rw-r--r--org/freedesktop/dbus/viewer/DBusViewer.java151
3 files changed, 163 insertions, 21 deletions
diff --git a/org/freedesktop/dbus/viewer/DBusEntry.java b/org/freedesktop/dbus/viewer/DBusEntry.java
index 4a87722..38eee63 100644
--- a/org/freedesktop/dbus/viewer/DBusEntry.java
+++ b/org/freedesktop/dbus/viewer/DBusEntry.java
@@ -21,6 +21,8 @@ import org.freedesktop.dbus.UInt32;
public class DBusEntry
{
private String name;
+
+ private String path;
private UInt32 user;
@@ -99,4 +101,23 @@ public class DBusEntry
{
return introspectable;
}
+
+ /**
+ * retrieve the path parameter
+ *
+ * @return
+ */
+ public String getPath() {
+ return path;
+ }
+
+ /**
+ * set the path parameter
+ *
+ * @param path
+ */
+ public void setPath(String path) {
+ this.path = path;
+ }
+
}
diff --git a/org/freedesktop/dbus/viewer/DBusTableModel.java b/org/freedesktop/dbus/viewer/DBusTableModel.java
index 9793536..cd23f4b 100644
--- a/org/freedesktop/dbus/viewer/DBusTableModel.java
+++ b/org/freedesktop/dbus/viewer/DBusTableModel.java
@@ -25,8 +25,10 @@ class DBusTableModel extends AbstractTableModel
private static final String USER = "user";
private static final String NAME = "name";
+
+ private static final String PATH = "path";
- final String[] columns = { NAME, USER, OWNER, INTROSPECTABLE };
+ final String[] columns = { NAME, PATH, USER, OWNER, INTROSPECTABLE };
private List<DBusEntry> entries = new ArrayList<DBusEntry>();
@@ -75,6 +77,10 @@ class DBusTableModel extends AbstractTableModel
{
return String.class;
}
+ if (columnName.equals(PATH))
+ {
+ return String.class;
+ }
else if (columnName.equals(USER))
{
return Object.class;
@@ -99,6 +105,10 @@ class DBusTableModel extends AbstractTableModel
{
return entry.getName();
}
+ if (columnName.equals(PATH))
+ {
+ return entry.getPath();
+ }
else if (columnName.equals(USER))
{
return entry.getUser();
diff --git a/org/freedesktop/dbus/viewer/DBusViewer.java b/org/freedesktop/dbus/viewer/DBusViewer.java
index ffabb4a..1cf8f6a 100644
--- a/org/freedesktop/dbus/viewer/DBusViewer.java
+++ b/org/freedesktop/dbus/viewer/DBusViewer.java
@@ -12,6 +12,8 @@ package org.freedesktop.dbus.viewer;
import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
+import java.io.IOException;
+import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -26,6 +28,9 @@ import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.table.TableModel;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
import org.freedesktop.DBus;
import org.freedesktop.DBus.Introspectable;
@@ -33,6 +38,12 @@ import org.freedesktop.dbus.DBusConnection;
import org.freedesktop.dbus.UInt32;
import org.freedesktop.dbus.exceptions.DBusException;
import org.freedesktop.dbus.exceptions.DBusExecutionException;
+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;
/**
* A viewer for DBus
@@ -203,47 +214,147 @@ public class DBusViewer
DBus dbus = (DBus) conn.getRemoteObject("org.freedesktop.DBus",
"/org/freedesktop/DBus", DBus.class);
String[] names = dbus.ListNames();
+
+ ParsingContext p = new ParsingContext(conn);
+
for (String name : names)
{
- DBusEntry entry = new DBusEntry();
- entry.setName(name);
+ List<DBusEntry> results = new ArrayList<DBusEntry>();
try
{
//String objectpath = '/' + name.replace('.', '/');
- String objectpath = "/";
- Introspectable introspectable = (Introspectable) conn
- .getRemoteObject(name, objectpath, Introspectable.class);
- entry.setIntrospectable(introspectable);
+
+
+ p.visitNode(name,"/");
}
catch (DBusException e)
{
+ e.printStackTrace();
}
catch (DBusExecutionException e)
{
+ e.printStackTrace();
+ } catch (SAXException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
}
+ results = p.getResult();
+ p.reset();
- if (users) try
- {
- final UInt32 user = dbus.GetConnectionUnixUser(name);
- entry.setUser(user);
- }
- catch (DBusExecutionException DBEe)
- {
- }
- if (!name.startsWith(":") && owners)
- {
- try
+ if (results.size()>0) {
+ if (users) try
{
- final String owner = dbus.GetNameOwner(name);
- entry.setOwner(owner);
+ final UInt32 user = dbus.GetConnectionUnixUser(name);
+ for (DBusEntry entry : results) {
+ entry.setUser(user);
+ }
}
catch (DBusExecutionException DBEe)
{
}
+ if (!name.startsWith(":") && owners)
+ {
+ try
+ {
+ final String owner = dbus.GetNameOwner(name);
+ for (DBusEntry entry : results) {
+ entry.setOwner(owner);
+ }
+ }
+ catch (DBusExecutionException DBEe)
+ {
+ }
+ }
+ for (DBusEntry entry : results) {
+ model.add(entry);
+ }
}
- model.add(entry);
}
return model;
}
+ private final static String DOC_TYPE = "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">";
+
+ class ParsingContext {
+ private DBusConnection conn;
+ private DocumentBuilder builder;
+ private List<DBusEntry> result;
+
+ ParsingContext(DBusConnection conn) {
+ this.conn = conn;
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ try {
+ builder = factory.newDocumentBuilder();
+ } catch (ParserConfigurationException e1) {
+ // TODO Auto-generated catch block
+ throw new RuntimeException("Error during parser init:"+e1.getMessage(),e1);
+ }
+ reset();
+
+ }
+
+ DBusEntry addEntry(String name, String path) throws DBusException {
+ DBusEntry entry = new DBusEntry();
+ entry.setName(name);
+ entry.setPath(path);
+ Introspectable introspectable = (Introspectable) conn.getRemoteObject(name, path, Introspectable.class);
+ entry.setIntrospectable(introspectable);
+
+ result.add(entry);
+
+ return entry;
+ }
+
+ public void visitNode(String name, String path) throws DBusException, SAXException, IOException {
+ System.out.println("visit "+name+":"+path);
+ if ("/org/freedesktop/DBus/Local".equals(path)) {
+ // this will disconnects us.
+ return;
+ }
+ DBusEntry e = addEntry(name, path);
+ String introspectData = e.getIntrospectable().Introspect();
+
+
+ Document document = builder.parse(new InputSource(new StringReader(introspectData.replace(DOC_TYPE, ""))));
+ Element root = document.getDocumentElement();
+
+ NodeList children = root.getChildNodes();
+ for (int i=0;i<children.getLength();i++) {
+ Node node = children.item(i);
+ if (Node.ELEMENT_NODE != node.getNodeType()) {
+ continue;
+ }
+ if ("node".equals(node.getNodeName())) {
+ Node nameNode = node.getAttributes().getNamedItem("name");
+ if (nameNode!=null) {
+ try {
+ if (path.endsWith("/")) {
+ visitNode(name, path + nameNode.getNodeValue());
+ } else {
+ visitNode(name, path + '/' + nameNode.getNodeValue());
+ }
+ } catch (DBusException ex) {
+ ex.printStackTrace();
+ }
+ }
+ }
+
+ }
+
+ }
+
+ public List<DBusEntry> getResult() {
+ return result;
+ }
+
+ void reset() {
+ result = new ArrayList<DBusEntry>();
+ }
+
+
+ }
+
}