Class StructTreeBuilder

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

public class StructTreeBuilder extends Object
Helper to create a DBus struct class. As Structs are regular classes (POJOs) in Java, this helper also takes care about recursion (Struct in Struct/Map/List).
Since:
v3.0.1 - 2018-12-21
  • Constructor Details

    • StructTreeBuilder

      public StructTreeBuilder()
  • Method Details

    • buildStructClasses

      public String buildStructClasses(String _dbusSig, String _structName, ClassBuilderInfo _clzBldr, List<ClassBuilderInfo> _generatedClasses) throws DBusException
      Builds the struct(s) found in _dbusSig. If the struct is wrapped in a Collection, it will be unwrapped.

      The resulting String will return the parent class name. This can be the Structs classname or e.g. List/Set class if the struct was wrapped in a Collection.

      Structs which are inside of another struct will get the appendix 'Struct' for each iteration. This may lead to classes with names like FooStructStructStruct (FooStruct->(InnerStruct->InnerInnerStruct)).
      Parameters:
      _dbusSig - dbus Type string
      _structName - name the struct should have
      _clzBldr - class builder with the class where the struct was first seen
      _generatedClasses - a list, this will contain additional struct classes created, if any. Should never be null!
      Returns:
      Struct class name or Collection type name
      Throws:
      DBusException - on DBus Error
    • createNested

      private ClassBuilderInfo createNested(List<StructTreeBuilder.StructTree> _list, ClassBuilderInfo _root, List<ClassBuilderInfo> _classes)
      Create nested Struct class.
      Parameters:
      _list - List of struct tree elements
      _root - root class of this struct (maybe other struct)
      _classes - a list, this will contain additional struct classes created, if any. Should never be null!
      Returns:
      last created struct or null
    • printTree

      static void printTree(List<StructTreeBuilder.StructTree> _buildTree, int _indent)
      Helper to print a StructTree to STDOUT (for debugging purposes).
      Parameters:
      _buildTree - tree to print
      _indent - indention level (usually 0)
    • buildTree

      private List<StructTreeBuilder.StructTree> buildTree(String _dbusTypeStr) throws DBusException
      Builds a tree of types based on the given DBus type definition string.
      Parameters:
      _dbusTypeStr - DBus type string
      Returns:
      List with tree structure, maybe empty - never null
      Throws:
      DBusException - on Error
    • buildTree

      Create tree from ParameterizedType.
      Parameters:
      _pType - ParameterizedType object
      Returns:
      List of tree elements, maybe empty, never null
      Throws:
      DBusException - on error