Class InterfaceCodeGenerator

java.lang.Object
org.freedesktop.dbus.utils.generator.InterfaceCodeGenerator

public class InterfaceCodeGenerator extends Object
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.
Since:
v3.0.1 - 2018-12-20
  • Field Details

    • docFac

      private final DocumentBuilderFactory docFac
    • logger

      private final org.slf4j.Logger logger
    • nodeName

      private final String nodeName
    • busName

      private final String busName
    • introspectionData

      private final String introspectionData
  • Constructor Details

    • InterfaceCodeGenerator

      public InterfaceCodeGenerator(String _introspectionData, String _objectPath, String _busName)
  • Method Details

    • analyze

      public Map<File,String> analyze(boolean _ignoreDtd) throws Exception
      Analyze 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:
      Exception - on DBUS or IO errors
    • convertToElementList

      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 to convert
      Returns:
      List of Element, maybe empty
    • extractAll

      private Map<File,String> extractAll(Element _ife) throws IOException, DBusException
      Extract all methods/signals etc. from the given interface element.
      Parameters:
      _ife - interface element
      Returns:
      Map of files and their contents
      Throws:
      IOException - when reading xml fails
      DBusException - when DBus fails
    • extractSignals

      private List<ClassBuilderInfo> extractSignals(Element _signalElement, ClassBuilderInfo _clzBldr) throws IOException, DBusException
      Extract <signal> element properties.
      Parameters:
      _signalElement - signal xml element
      _clzBldr - ClassBuilderInfo object
      Returns:
      List of ClassBuilderInfo which have been created (maybe empty, never null)
      Throws:
      IOException - on IO Error
      DBusException - on DBus Error
    • extractMethods

      private List<ClassBuilderInfo> extractMethods(Element _methodElement, ClassBuilderInfo _clzBldr) throws IOException, DBusException
      Extract <method> elements properties.
      Parameters:
      _methodElement - method XML element
      _clzBldr - ClassBuilderInfo object
      Returns:
      List of ClassBuilderInfo which have been created (maybe empty, never null)
      Throws:
      IOException - on IO Error
      DBusException - on DBus Error
    • extractProperties

      private List<ClassBuilderInfo> extractProperties(Element _propertyElement, ClassBuilderInfo _clzBldr) throws DBusException
      Extract <property> elements properties.
      Parameters:
      _propertyElement - method XML element
      _clzBldr - ClassBuilderInfo object
      Returns:
      List of ClassBuilderInfo which have been created (maybe empty, never null)
      Throws:
      DBusException - on DBus Error
    • createTuple

      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 - 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 String buildStructClass(String _dbusTypeStr, String _structName, ClassBuilderInfo _packageName, List<ClassBuilderInfo> _structClasses) throws DBusException
      Creates 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 of ClassCastException, 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(String _outputDir, Map<File,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(String[] _args)
    • version

      private static void version()
    • printHelp

      private static void printHelp()