Problem with IExtensionConf method getState (is Extension checked)

502
1
09-25-2012 02:24 AM
PetraZieger
New Contributor II
Hello,
I want to check, wether FME is installed (works) and wether the FME-Licence is checked or not (does not work).

I did noh find an example in Java, but all other examples manage the problem
by casting IExtension to IExtensionConfig and using the method getState(UID).
In the ArcObjects Java SDK is also said "use QI from IExtension to IExtensionConfig".
QI means "casting" or am I wrong?

I allways get the error "IExtensionProxy can not be cast to IExtensionConfig".
Why do I have a proxy-object?! Causes the proxy the problem?
How can I avoid to have a proxy-object?
Has anybody an idea?

Greeetings,
Petra

      private boolean FMELicense() {
            boolean isActivated = false;
            try {

                  IUID fmeUID = new UID();
                  fmeUID.setValue("{D5E016E9-171B-45CA-B4A2-6361DBC1E255}");
                   
                  IExtensionManager extensionMgr = new ExtensionManager();
                  extensionMgr = (IExtensionManager) app;
                  IExtension fmeExtension = extensionMgr.findExtension(fmeUID);
                   
                  if (fmeExtension == null) {
                        isActivated = false;
                        Util.addToLog("Fehler: FME-Lizenz ist nicht vorhanden...");
                  } else {
Util.addToLog("fmeExtension.getClass() = " + fmeExtension.getClass().getName());
                             Util.addToLog("FME-Lizenz vorhanden...");
                             Util.addToLog("vor extensionConf = ...");
                             IExtensionConfig extensionConf = (IExtensionConfig) app.findExtensionByCLSID(fmeUID); // does not work..
                             Util.addToLog("nach extensionConf = ...");
                             if (extensionConf.getState() == esriExtensionState.esriESEnabled) {
                                   isActivated = true;
                             }
                             else {
                                   isActivated = false;
                                   Util.addToLog("Fehler: FME-Lizenz ist nicht aktiviert...");
                             }
                  }
                 
            } catch (IOException e) {
                  Util.printStackTraceToLog(e);
            }
            return isActivated;
      }
0 Kudos
1 Reply
PetraZieger
New Contributor II
Hello again,
here is the solution:

A member of the ESRI professional team gave me the hint: You have to create a new proxy-object!
=> Object-creation with "new" is necessary before casting in case of working with proxy-objects!

IExtensionConfig extensionConf = new IExtensionConfigProxy(app.findExtensionByCLSID(fmeUID));

Greetings from Wachtberg,
Petra Zieger

You find the source-code to check the usability of the FME-Extension with JAVA-ArcObject in the attachment.
0 Kudos