vendredi 22 juillet 2016

Configuration Interface to use with Framework

I'm currently developing a framework where I'll provide an Interface that the user should implement in his application for configuration purposes. The user should ne able to implement a getTargetUsername() that will be used in the framework side.

What I'm trying to achieve a is pretty much what Togglez do:

public class MyTogglzConfiguration implements TogglzConfig {

    public Class<? extends Feature> getFeatureClass() {
        return MyFeatures.class;
    }

}

My problem is that I'm struggling to find how should I lookup for the class that is implementing my configuration interface. And call the getTargetUsername() method inside the framework.


What I've tryed so far:

I'm currently trying to do the trick using Reflections, but I'm not sure this is the right approach, since I don't know if this is looking only inside my framework package or it will search inside a prject that add it as a dependency.

Reflections reflections = new Reflections();
Set<Class<? extends FrameworkConfig>> configurations = reflections.getSubTypesOf(FrameworkConfig.class);

//Getting the Class thats is implementing here
Object c = configurations.toArray()[0];

I'm being able to get the right Class with the above code but I acctually can't call getTargetUsername().





Aucun commentaire:

Enregistrer un commentaire