Top Description Inners Fields Constructors Methods
org.freedesktop.dbus.utils.generator

public Class InterfaceCodeGenerator

extends Object
Class Inheritance
Imports
org.freedesktop.dbus.Tuple, .TypeRef, org.freedesktop.dbus.annotations.DBusBoundProperty, .DBusInterfaceName, .DBusProperty, .Position, org.freedesktop.dbus.connections.impl.DBusConnection, .DBusConnection.DBusBusType, .DBusConnectionBuilder, org.freedesktop.dbus.exceptions.DBusException, .DBusExecutionException, org.freedesktop.dbus.interfaces.DBusInterface, .Introspectable, org.freedesktop.dbus.messages.DBusSignal, org.freedesktop.dbus.types.Variant, org.freedesktop.dbus.utils.Util, .XmlUtil, org.freedesktop.dbus.utils.generator.ClassBuilderInfo.*, org.slf4j.Logger, .LoggerFactory, org.w3c.dom.Document, .Element, .NodeList, org.xml.sax.InputSource, java.io.File, .IOException, .InputStream, .StringReader, java.nio.charset.Charset, java.util.*, .Map.Entry, javax.xml.parsers.DocumentBuilder, .DocumentBuilderFactory

Replacement for the old CreateInterface tool. This utility class will read introspection data from a given DBus interface and tries to generate proper Java interfaces.
Author
hypfvieh
Since
v3.0.1 - 2018-12-20

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static enum

Field Summary

Modifier and TypeField and Description
private final String
private final String
private final boolean
private final DocumentBuilderFactory
private final String
private final Set<String>
private final String
private final Logger
private final String
private final boolean

Constructor Summary

AccessConstructor and Description
public
InterfaceCodeGenerator(boolean _disableFilter, String _introspectionData, String _objectPath, String _busName, String _packageName, boolean _propertyMethods, String _argumentPrefix)

Method Summary

Modifier and TypeMethod and Description
public Map<File, String>

Returns:

List of Filenames and contents for the files
analyze
(boolean
true to disable dtd-validation, false otherwise
_ignoreDtd
)

Analyze the DBus interface given in constructor by parsing the introspection data.

private String

Returns:

FQCN of the created struct class
buildStructClass
(String
Dbus Type definition string
_dbusTypeStr
,
String
name of the struct to create
_structName
,
ClassBuilderInfo
package name for the struct class
_packageName
,
List<ClassBuilderInfo>
list of ClassCastException, other struct classes which may be created during struct creation will be added here
_structClasses
)

Creates a class for a DBus Struct-Object.

pack-priv static List<Element>

Returns:

List of Element, maybe empty
convertToElementList
(NodeList
NodeList to convert
_nodeList
)

Converts a NodeList to List<Element>.

private String

Returns:

FQCN of the newly created tuple based class
createTuple
(List<ClassBuilderInfo.MemberOrArgument>
Map with return arguments (key) and their types (value)
_outputArgs
,
String
name the tuple class should get
_className
,
ClassBuilderInfo
parent class where the tuple was required in
_parentClzBldr
,
List<ClassBuilderInfo>
list where the new created tuple class will be added to
_additionalClasses
,
List<String>
Dbus argument names and data types
_dbusOutputArgTypes
)

Creates a Tuple extending class to encapsulate a multi-value return (which is not supported by Java natively).

private Map<File, String>

Returns:

Map of files and their contents
extractAll
(Element
interface element
_ife
)

Extract all methods/signals etc. from the given interface element.

private List<ClassBuilderInfo>

Returns:

List of ClassBuilderInfo which have been created (maybe empty, never null)
extractMethods
(Element
method XML element
_methodElement
,
ClassBuilderInfo _clzBldr)

Extract <method> elements properties.

private List<ClassBuilderInfo>

Returns:

List of ClassBuilderInfo which have been created (maybe empty, never null)
extractProperties
(Element
method XML element
_propertyElement
,
ClassBuilderInfo _clzBldr)

Extract <property> elements properties.

private List<ClassBuilderInfo>

Returns:

List of ClassBuilderInfo which have been created (maybe empty, never null)
extractSignals
(Element
signal xml element
_signalElement
,
ClassBuilderInfo _clzBldr)

Extract <signal> element properties.

public static void
main(String[] _args)

private static void
private static void
pack-priv static void
writeToFile(String
directory to put output files to
_outputDir
,
Map<File, String>
map of files and contents which should be created
_filesToGenerate
)

Creates all files in the given map with the given content in the given directory.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

argumentPrefixback to summary
private final String argumentPrefix
busNameback to summary
private final String busName
disableFilterback to summary
private final boolean disableFilter
docFacback to summary
private final DocumentBuilderFactory docFac
forcePackageNameback to summary
private final String forcePackageName
generatedStructClassNamesback to summary
private final Set<String> generatedStructClassNames
introspectionDataback to summary
private final String introspectionData
loggerback to summary
private final Logger logger
nodeNameback to summary
private final String nodeName
propertyMethodsback to summary
private final boolean propertyMethods

Constructor Detail

InterfaceCodeGeneratorback to summary
public InterfaceCodeGenerator(boolean _disableFilter, String _introspectionData, String _objectPath, String _busName, String _packageName, boolean _propertyMethods, String _argumentPrefix)

Method Detail

analyzeback to summary
public Map<File, String> analyze(boolean _ignoreDtd) throws Exception

Analyze the DBus interface given in constructor by parsing the introspection data.

Parameters
_ignoreDtd:boolean

true to disable dtd-validation, false otherwise

Returns:Map<File, String>

List of Filenames and contents for the files

Exceptions
Exception:
on DBUS or IO errors
buildStructClassback to summary
private String buildStructClass(String _dbusTypeStr, String _structName, ClassBuilderInfo _packageName, List<ClassBuilderInfo> _structClasses) throws DBusException

Creates a class for a DBus Struct-Object.

Parameters
_dbusTypeStr:String

Dbus Type definition string

_structName:String

name of the struct to create

_packageName:ClassBuilderInfo

package name for the struct class

_structClasses:List<ClassBuilderInfo>

list of ClassCastException, other struct classes which may be created during struct creation will be added here

Returns:String

FQCN of the created struct class

Exceptions
DBusException:
on Error
convertToElementListback to summary
pack-priv static List<Element> convertToElementList(NodeList _nodeList)

Converts a NodeList to List<Element>. Will skip all NodeList entries not compatible with Element type.

Parameters
_nodeList:NodeList

NodeList to convert

Returns:List<Element>

List of Element, maybe empty

createTupleback to summary
private String createTuple(List<ClassBuilderInfo.MemberOrArgument> _outputArgs, String _className, ClassBuilderInfo _parentClzBldr, List<ClassBuilderInfo> _additionalClasses, List<String> _dbusOutputArgTypes)

Creates a Tuple extending class to encapsulate a multi-value return (which is not supported by Java natively).

Parameters
_outputArgs:List<ClassBuilderInfo.MemberOrArgument>

Map with return arguments (key) and their types (value)

_className:String

name the tuple class should get

_parentClzBldr:ClassBuilderInfo

parent class where the tuple was required in

_additionalClasses:List<ClassBuilderInfo>

list where the new created tuple class will be added to

_dbusOutputArgTypes:List<String>

Dbus argument names and data types

Returns:String

FQCN of the newly created tuple based class

extractAllback to summary
private Map<File, String> extractAll(Element _ife) throws IOException, DBusException

Extract all methods/signals etc. from the given interface element.

Parameters
_ife:Element

interface element

Returns:Map<File, String>

Map of files and their contents

Exceptions
IOException:
when reading xml fails
DBusException:
when DBus fails
extractMethodsback to summary
private List<ClassBuilderInfo> extractMethods(Element _methodElement, ClassBuilderInfo _clzBldr) throws IOException, DBusException

Extract <method> elements properties.

Parameters
_methodElement:Element

method XML element

_clzBldr:ClassBuilderInfo

ClassBuilderInfo object

Returns:List<ClassBuilderInfo>

List of ClassBuilderInfo which have been created (maybe empty, never null)

Exceptions
IOException:
on IO Error
DBusException:
on DBus Error
extractPropertiesback to summary
private List<ClassBuilderInfo> extractProperties(Element _propertyElement, ClassBuilderInfo _clzBldr) throws DBusException

Extract <property> elements properties.

Parameters
_propertyElement:Element

method XML element

_clzBldr:ClassBuilderInfo

ClassBuilderInfo object

Returns:List<ClassBuilderInfo>

List of ClassBuilderInfo which have been created (maybe empty, never null)

Exceptions
DBusException:
on DBus Error
extractSignalsback to summary
private List<ClassBuilderInfo> extractSignals(Element _signalElement, ClassBuilderInfo _clzBldr) throws IOException, DBusException

Extract <signal> element properties.

Parameters
_signalElement:Element

signal xml element

_clzBldr:ClassBuilderInfo

ClassBuilderInfo object

Returns:List<ClassBuilderInfo>

List of ClassBuilderInfo which have been created (maybe empty, never null)

Exceptions
IOException:
on IO Error
DBusException:
on DBus Error
mainback to summary
public static void main(String[] _args)
printHelpback to summary
private static void printHelp()
versionback to summary
private static void version()
writeToFileback to summary
pack-priv static void writeToFile(String _outputDir, Map<File, String> _filesToGenerate)

Creates all files in the given map with the given content in the given directory.

Parameters
_outputDir:String

directory to put output files to

_filesToGenerate:Map<File, String>

map of files and contents which should be created

org.freedesktop.dbus.utils.generator back to summary

pack-priv final Enum InterfaceCodeGenerator.DbusInterfaceToFqcn

extends Enum<InterfaceCodeGenerator.DbusInterfaceToFqcn>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final InterfaceCodeGenerator.DbusInterfaceToFqcn
public static final InterfaceCodeGenerator.DbusInterfaceToFqcn
public static final InterfaceCodeGenerator.DbusInterfaceToFqcn
public static final InterfaceCodeGenerator.DbusInterfaceToFqcn

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Map<InterfaceCodeGenerator.DbusInterfaceToFqcn, String>
toFqcn(String _interfaceName)

public static InterfaceCodeGenerator.DbusInterfaceToFqcn
public static InterfaceCodeGenerator.DbusInterfaceToFqcn[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

CLASSNAMEback to summary
public static final InterfaceCodeGenerator.DbusInterfaceToFqcn CLASSNAME
DBUS_INTERFACE_NAMEback to summary
public static final InterfaceCodeGenerator.DbusInterfaceToFqcn DBUS_INTERFACE_NAME
ORIG_PKGNAMEback to summary
public static final InterfaceCodeGenerator.DbusInterfaceToFqcn ORIG_PKGNAME
PACKAGENAMEback to summary
public static final InterfaceCodeGenerator.DbusInterfaceToFqcn PACKAGENAME

Constructor Detail

DbusInterfaceToFqcnback to summary
private DbusInterfaceToFqcn()

Method Detail

toFqcnback to summary
public static Map<InterfaceCodeGenerator.DbusInterfaceToFqcn, String> toFqcn(String _interfaceName)
valueOfback to summary
public static InterfaceCodeGenerator.DbusInterfaceToFqcn valueOf(String name)
valuesback to summary
public static InterfaceCodeGenerator.DbusInterfaceToFqcn[] values()