Query Java classes in Xojo
We have an integration to use Java classes in Xojo projects. Our clients like to load a jar file with some code and call methods in Java. We can do that and we have new functions for version 25.3 of MBS Xojo Java Plugin:
LoadedClasses
You can now query the list of loaded classes:
function JavaVMMBS.LoadedClasses as JavaClassMBS()
This is great to know what classes the loaded jar files provide when you initialize the JavaVMMBS object.
Let's say you have graphics filters defined in jar files. You would load the jar file, check what classes are available. Then you filter the list of classes to only the ones subclassing the base filter class. Then you list all matching classes in a filter list, so the user can pick one.
Here is an example code to query the list of classes and then call the getName function on each to ask for the name of the class:
Fields
Next we have a function to query the fields on a given class. This provides JavaFieldMBS objects, which you can inspect at runtime and use to get or set fields dynamically.
Once the user picked a filter class from our example above, you could inspect it and have some GUI to set properties, maybe like the Xojo inspector. Depending on the data type, you could show picker for color properties or a text field for a string field.
Here is an example code to query the list of fields and show it:
Methods
Last, but not least we have a function to query the methods on a given class. This provides JavaMethodMBS objects, which you can inspect at runtime and use to call methods dynamically.
For our filter example, we could have multiple filter* methods, so we could list them and have the user pick the right one.
Here is an example code to query the list of methods and show it:
Please try the new methods and let us know whether they help you. While Java has not directly the introspection like Xojo, we hope to help a little here.