Class InterfaceCodeGenerator
- java.lang.Object
-
- org.freedesktop.dbus.utils.generator.InterfaceCodeGenerator
-
public class InterfaceCodeGenerator extends java.lang.ObjectReplacement for the old CreateInterface tool. This utility class will read introspection data from a given DBus interface and tries to generate proper Java interfaces.- Since:
- v3.0.1 - 2018-12-20
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classInterfaceCodeGenerator.DbusInterfaceToFqcn
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringbusNameprivate javax.xml.parsers.DocumentBuilderFactorydocFacprivate java.lang.StringintrospectionDataprivate org.slf4j.Loggerloggerprivate java.lang.StringnodeName
-
Constructor Summary
Constructors Constructor Description InterfaceCodeGenerator(java.lang.String _introspectionData, java.lang.String _objectPath, java.lang.String _busName)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Map<java.io.File,java.lang.String>analyze(boolean _ignoreDtd)Analyze the DBus interface given in constructor by parsing the introspection data.private java.lang.StringbuildStructClass(java.lang.String _dbusTypeStr, java.lang.String _structName, ClassBuilderInfo _packageName, java.util.List<ClassBuilderInfo> _structClasses)Creates a class for a DBus Struct-Object.(package private) static java.util.List<org.w3c.dom.Element>convertToElementList(org.w3c.dom.NodeList _nodeList)Converts a NodeList to List<Element>.private java.lang.StringcreateTuple(java.util.List<ClassBuilderInfo.MemberOrArgument> _outputArgs, java.lang.String _className, ClassBuilderInfo _parentClzBldr, java.util.List<ClassBuilderInfo> _additionalClasses, java.util.List<java.lang.String> _dbusOutputArgTypes)Creates a Tuple extending class to encapsulate a multi-value return (which is not supported by Java natively).private java.util.Map<java.io.File,java.lang.String>extractAll(org.w3c.dom.Element _ife)Extract all methods/signals etc.private java.util.List<ClassBuilderInfo>extractMethods(org.w3c.dom.Element _methodElement, ClassBuilderInfo _clzBldr)Extract <method> elements properties.private java.util.List<ClassBuilderInfo>extractProperties(org.w3c.dom.Element _propertyElement, ClassBuilderInfo _clzBldr)Extract <property> elements properties.private java.util.List<ClassBuilderInfo>extractSignals(org.w3c.dom.Element _signalElement, ClassBuilderInfo _clzBldr)Extract <signal> element properties.static voidmain(java.lang.String[] _args)private static voidprintHelp()private static voidversion()(package private) static voidwriteToFile(java.lang.String _outputDir, java.util.Map<java.io.File,java.lang.String> _filesToGenerate)Creates all files in the given map with the given content in the given directory.
-
-
-
Method Detail
-
analyze
public java.util.Map<java.io.File,java.lang.String> analyze(boolean _ignoreDtd) throws java.lang.ExceptionAnalyze the DBus interface given in constructor by parsing the introspection data.- Parameters:
_ignoreDtd- true to disable dtd-validation, false otherwise- Returns:
- List of Filenames and contents for the files
- Throws:
java.lang.Exception- on DBUS or IO errors
-
convertToElementList
static java.util.List<org.w3c.dom.Element> convertToElementList(org.w3c.dom.NodeList _nodeList)
Converts a NodeList to List<Element>. Will skip all NodeList entries not compatible with Element type.- Parameters:
_nodeList- NodeList to convert- Returns:
- List of Element, maybe empty
-
extractAll
private java.util.Map<java.io.File,java.lang.String> extractAll(org.w3c.dom.Element _ife) throws java.io.IOException, DBusExceptionExtract all methods/signals etc. from the given interface element.- Parameters:
_ife- interface element- Returns:
- Map of files and their contents
- Throws:
java.io.IOException- when reading xml failsDBusException- when DBus fails
-
extractSignals
private java.util.List<ClassBuilderInfo> extractSignals(org.w3c.dom.Element _signalElement, ClassBuilderInfo _clzBldr) throws java.io.IOException, DBusException
Extract <signal> element properties.- Parameters:
_signalElement- signal xml element_clzBldr-ClassBuilderInfoobject- Returns:
- List of
ClassBuilderInfowhich have been created (maybe empty, never null) - Throws:
java.io.IOException- on IO ErrorDBusException- on DBus Error
-
extractMethods
private java.util.List<ClassBuilderInfo> extractMethods(org.w3c.dom.Element _methodElement, ClassBuilderInfo _clzBldr) throws java.io.IOException, DBusException
Extract <method> elements properties.- Parameters:
_methodElement- method XML element_clzBldr-ClassBuilderInfoobject- Returns:
- List of
ClassBuilderInfowhich have been created (maybe empty, never null) - Throws:
java.io.IOException- on IO ErrorDBusException- on DBus Error
-
extractProperties
private java.util.List<ClassBuilderInfo> extractProperties(org.w3c.dom.Element _propertyElement, ClassBuilderInfo _clzBldr) throws DBusException
Extract <property> elements properties.- Parameters:
_propertyElement- method XML element_clzBldr-ClassBuilderInfoobject- Returns:
- List of
ClassBuilderInfowhich have been created (maybe empty, never null) - Throws:
DBusException- on DBus Error
-
createTuple
private java.lang.String createTuple(java.util.List<ClassBuilderInfo.MemberOrArgument> _outputArgs, java.lang.String _className, ClassBuilderInfo _parentClzBldr, java.util.List<ClassBuilderInfo> _additionalClasses, java.util.List<java.lang.String> _dbusOutputArgTypes)
Creates a Tuple extending class to encapsulate a multi-value return (which is not supported by Java natively).- Parameters:
_outputArgs- Map with return arguments (key) and their types (value)_className- name the tuple class should get_parentClzBldr- parent class where the tuple was required in_additionalClasses- list where the new created tuple class will be added to_dbusOutputArgTypes- Dbus argument names and data types- Returns:
- FQCN of the newly created tuple based class
-
buildStructClass
private java.lang.String buildStructClass(java.lang.String _dbusTypeStr, java.lang.String _structName, ClassBuilderInfo _packageName, java.util.List<ClassBuilderInfo> _structClasses) throws DBusExceptionCreates a class for a DBus Struct-Object.- Parameters:
_dbusTypeStr- Dbus Type definition string_structName- name of the struct to create_packageName- package name for the struct class_structClasses- list ofClassCastException, other struct classes which may be created during struct creation will be added here- Returns:
- FQCN of the created struct class
- Throws:
DBusException- on Error
-
writeToFile
static void writeToFile(java.lang.String _outputDir, java.util.Map<java.io.File,java.lang.String> _filesToGenerate)Creates all files in the given map with the given content in the given directory.- Parameters:
_outputDir- directory to put output files to_filesToGenerate- map of files and contents which should be created
-
main
public static void main(java.lang.String[] _args)
-
version
private static void version()
-
printHelp
private static void printHelp()
-
-