in dbus-java/src/main/java/org/freedesktop/dbus/connections/impl/DBusConnection.java [358:416]
protected DBusInterface dynamicProxy(String _source, String _path) throws DBusException {
logger.debug("Introspecting {} on {} for dynamic proxy creation", _path, _source);
try {
Introspectable intro = getRemoteObject(_source, _path, Introspectable.class);
String data = intro.Introspect();
logger.trace("Got introspection data: {}", data);
String[] tags = data.split("[<>]");
List<String> ifaces = new ArrayList<>();
for (String tag : tags) {
if (tag.startsWith("interface")) {
ifaces.add(tag.replaceAll("^interface *name *= *['\"]([^'\"]*)['\"].*$", "$1"));
}
}
List<Class<?>> ifcs = new ArrayList<>();
for (String iface : ifaces) {
// if this is a default DBus interface, look for it in our package structure
if (iface.startsWith("org.freedesktop.DBus.")) {
iface = iface.replaceAll("^.*\\.([^\\.]+)$", DBusInterface.class.getPackage().getName() + ".$1");
}
logger.debug("Trying interface {}", iface);
int j = 0;
while (j >= 0) {
try {
Class<?> ifclass = Class.forName(iface);
if (!ifcs.contains(ifclass)) {
ifcs.add(ifclass);
}
break;
} catch (Exception e) {
}
j = iface.lastIndexOf(".");
char[] cs = iface.toCharArray();
if (j >= 0) {
cs[j] = '$';
iface = String.valueOf(cs);
}
}
}
// interface could not be found, we guess that this exported object at least support DBusInterface
if (ifcs.isEmpty()) {
// throw new DBusException("Could not find an interface to cast to");
ifcs.add(DBusInterface.class);
}
RemoteObject ro = new RemoteObject(_source, _path, null, false);
DBusInterface newi = (DBusInterface) Proxy.newProxyInstance(ifcs.get(0).getClassLoader(),
ifcs.toArray(new Class[0]), new RemoteInvocationHandler(this, ro));
getImportedObjects().put(newi, ro);
return newi;
} catch (Exception e) {
logger.debug("", e);
throw new DBusException(
String.format("Failed to create proxy object for %s exported by %s. Reason: %s", _path,
_source, e.getMessage()));
}
}