in dbus-java-utils/src/main/java/org/freedesktop/dbus/utils/generator/InterfaceCodeGenerator.java [396:498]
public static void main(String[] args) {
String busName = null;
String outputDir = null;
DBusBusType busType = null;
boolean ignoreDtd = true;
String objectPath = null;
String inputFile = null;
for (int i = 0; i < args.length; i++) {
String p = args[i];
if ("--system".equals(p) || "-y".equals(p)) {
busType = DBusBusType.SYSTEM;
} else if ("--session".equals(p) || "-s".equals(p)) {
busType = DBusBusType.SESSION;
} else if ("--enable-dtd-validation".equals(p)) {
ignoreDtd = false;
} else if ("--help".equals(p) || "-h".equals(p)) {
printHelp();
System.exit(0);
} else if ("--version".equals(p) || "-v".equals(p)) {
version();
System.exit(0);
} else if ("--outputDir".equals(p) || "-o".equals(p)) {
if (args.length > i) {
outputDir = args[++i];
} else {
printHelp();
System.exit(0);
}
} else if ("--inputFile".equals(p) || "-i".equals(p)) {
if (args.length > i) {
inputFile = args[++i];
} else {
printHelp();
System.exit(0);
}
} else {
if (null == busName) {
busName = p;
} else if (null == objectPath) {
objectPath = p;
} else {
printHelp();
System.exit(1);
}
}
}
if (objectPath == null) {
objectPath = "/";
}
if (outputDir == null) {
throw new RuntimeException("No output directory (--outputDir) given!");
}
Logger logger = LoggerFactory.getLogger(InterfaceCodeGenerator.class);
String introspectionData = null;
if (!StringUtil.isBlank(busName)) {
if (!StringUtil.isBlank(inputFile)) {
File file = new File(inputFile);
if (!file.exists()) {
logger.error("Given input file {} does not exist", file);
System.exit(1);
}
introspectionData = FileIoUtil.readFileToString(file);
} else {
try {
logger.info("Introspecting: { Interface: {}, Busname: {} }", objectPath, busName);
DBusConnection conn = DBusConnection.getConnection(busType);
Introspectable in = conn.getRemoteObject(busName, objectPath, Introspectable.class);
introspectionData = in.Introspect();
if (StringUtil.isBlank(introspectionData)) {
logger.error("Failed to get introspection data");
System.exit(1);
}
conn.disconnect();
} catch (DBusExecutionException | DBusException _ex) {
logger.error("Failure in DBus Communications. ", _ex);
System.exit(1);
}
}
InterfaceCodeGenerator ci2 = new InterfaceCodeGenerator(introspectionData, objectPath, busName);
try {
Map<File, String> analyze = ci2.analyze(ignoreDtd);
writeToFile(outputDir, analyze);
logger.info("Interface creation finished");
} catch (Exception _ex) {
logger.error("Error while analyzing introspection data", _ex);
}
} else {
logger.error("Busname missing!");
System.exit(1);
}
}