Skip to content

Metadata Cheat Sheet

Jonathan Pobst edited this page Apr 7, 2021 · 3 revisions

Quick reference for commonly used metadata constructs.

Common Paths

  • /interface EX: /interface[@name='AuthListener']
  • /class EX: /class[@name='MapView']
  • /method EX: /method[@name='setTileSource']
  • /method(with parameters) EX: /method[@name='onCreate'and count(parameter)=2 and parameter[1][@type='com.my.CustomActivity'] and parameter[2][@type='android.os.Bundle']]"
  • /parameter EX: /parameter[@name='p0']
  • /parameter(with type) EX: parameter[1][@type='com.my.CustomActivity']

Common Attribute Names

  • name="managedType" - EX: Java.Lang.Object
  • name="obfuscated" - Changes the obfuscation EX: true / false
  • name="managedName" - Changes the managed name EX: MyCSharpName
  • name="propertyName" - Changes the property name EX: MyPropertyName
  • name="managedReturn" - Changes the managed return type EX: Java.Lang.Object
  • name="argsType" - changes the argument type EX: MyCustomErrorEventArgs
  • name="sender" - Changes which parameter of a method should be the sender parameter when it's mapped to an event EX: true / false
  • name="eventName" - Changes the event name EX: MyEventName

Multiple Matches

It is important to note that if an XPath path matches multiple elements, the action is performed on *every* matching element. This can be very powerful when you want to affect multiple elements, like removing all classes that end with Builder:

<remove-node path="/api/package[@name='com.example']/class[ends-with(@name, 'Builder')]" />

However this can cause an issue if you only want to affect one element, like removing a single overload of a method named doSomething:

<remove-node path="/api/package[@name='com.example']/class[@name='MyClass']/method[@name='doSomething']" />

This will remove both of these methods:

public void doSomething () { ... }
public void doSomething (bool force) { ... }

If you only intended to remove the one with the parameter, the XPath needs to be specific to that overload:

<remove-node path="/api/package[@name='com.example']/class[@name='MyClass']/method[@name='doSomething' and count(parameter)=1]" />

Some handy XPath tutorials:

Missing Types / Obfuscated Types

Typically we will see characteristics of obfuscated types in our respective .jar/.aar libraries and we must unobfuscate them for the Bindings Generator to generate the respective C# types.

 <attr path="/api/package[@name='{package_name}']/class[@name='{name}']" name="obfuscated">false</attr>

Duplicate Names or Normalizing Names

Sometimes you'll run into duplicate managedNames or you might need to normalize your generated C# classes for sanity reasons.

<attr path="/api/package[@name='{package_name}']/class[@name='{name}']" name="managedName">NewManagedName</attr>

Class Visibility

Your class might not have the proper visibility for the Bindings Generator to traverse through as it does not generate bindings for non-public classes or derived classes. Typically switching the visibility to public fixes this.

<attr path="/api/package[@name='{package_name}']/class[@name='{name}']" name="visibility">public</attr>

Adding Types

You can use <add-node> to add just about anything to your binding which will generate in the api.xml file. Typically you may want to add a class, change a constructor, or switch a generic type.

EX: (Creates a class with a constructor and field):

  <add-node path="/api/package[@name='org.alljoyn.bus']">
    <class abstract="false" deprecated="not deprecated" final="false" name="AuthListener.AuthRequest" static="true" visibility="public" extends="java.lang.Object">
      <constructor deprecated="not deprecated" final="false" name="AuthListener.AuthRequest" static="false" type="org.alljoyn.bus.AuthListener.AuthRequest" visibility="public" />
      <field name="p0" type="org.alljoyn.bus.AuthListener.Credentials" />
    </class>
  </add-node>

Removing Types

Typically it's easiest to just remove anything in a binding that we will not use. You can look at the class that you want to use and see everything it references to get a better idea of what you will need and what you will not.

<remove-node path="/api/package[@name='{package_name}']/class[@name='{name}']" />