S Agung Wijaya
S Agung Wijaya

Reputation: 3

How do I get OSGi bundle state programatically as String?

As far as I know, I can get a bundle state programatically by doing bundle.getState() and that method will return the state as an int which refers to Bundle.ACTIVE or Bundle.INSTALLED or Bundle.RESOLVED or etc depending on the bundle. For some reasons, I need to get the state value as a String, like "ACTIVE", "INSTALLED", "RESOLVED", etc. How do I do that?

Upvotes: 0

Views: 704

Answers (1)

Peter Kriens
Peter Kriens

Reputation: 15372

You'll have to do your own switch ... OSGi started before Java had enums.

Something like:

    private static String toState(int state) {
        switch (state) {
        case Bundle.UNINSTALLED:
            return "UNINSTALLED";
        case Bundle.INSTALLED:
            return "INSTALLED";
        case Bundle.RESOLVED:
            return "RESOLVED";
        case Bundle.STARTING:
            return "STARTING";
        case Bundle.STOPPING:
            return "STOPPING";
        case Bundle.ACTIVE:
            return "ACTIVE";
        }
        return null;
    }

Upvotes: 1

Related Questions