Search in sources :

Example 1 with IJIEnumVariant

use of org.jinterop.dcom.impls.automation.IJIEnumVariant in project opennms by OpenNMS.

the class OnmsWbemMethodSetImpl method get.

/**
 * {@inheritDoc}
 */
@Override
public OnmsWbemMethod get(final Integer idx) throws WmiException {
    try {
        final IJIComObject enumComObject = wbemMethodSetDispatch.get("_NewEnum").getObjectAsComObject();
        final IJIEnumVariant enumVariant = (IJIEnumVariant) JIObjectFactory.narrowObject(enumComObject.queryInterface(IJIEnumVariant.IID));
        OnmsWbemMethod wbemMethod;
        IJIDispatch wbemMethod_dispatch = null;
        for (int i = 0; i < (idx + 1); i++) {
            final Object[] values = enumVariant.next(1);
            final JIArray array = (JIArray) values[0];
            final Object[] arrayObj = (Object[]) array.getArrayInstance();
            for (int j = 0; j < arrayObj.length; j++) {
                wbemMethod_dispatch = (IJIDispatch) JIObjectFactory.narrowObject(((JIVariant) arrayObj[j]).getObjectAsComObject());
            }
        }
        wbemMethod = new OnmsWbemMethodImpl(wbemMethod_dispatch);
        return wbemMethod;
    } catch (final JIException e) {
        throw new WmiException("Failed to enumerate WbemObject variant: " + e.getMessage(), e);
    }
}
Also used : JIArray(org.jinterop.dcom.core.JIArray) IJIComObject(org.jinterop.dcom.core.IJIComObject) OnmsWbemMethod(org.opennms.protocols.wmi.wbem.OnmsWbemMethod) IJIEnumVariant(org.jinterop.dcom.impls.automation.IJIEnumVariant) IJIDispatch(org.jinterop.dcom.impls.automation.IJIDispatch) IJIComObject(org.jinterop.dcom.core.IJIComObject) WmiException(org.opennms.protocols.wmi.WmiException) JIException(org.jinterop.dcom.common.JIException)

Example 2 with IJIEnumVariant

use of org.jinterop.dcom.impls.automation.IJIEnumVariant in project opennms by OpenNMS.

the class OnmsWbemPropertySetImpl method get.

/**
 * {@inheritDoc}
 */
@Override
public OnmsWbemProperty get(final Integer idx) throws WmiException {
    try {
        final IJIComObject enumComObject = wbemPropertySetDispatch.get("_NewEnum").getObjectAsComObject();
        final IJIEnumVariant enumVariant = (IJIEnumVariant) JIObjectFactory.narrowObject(enumComObject.queryInterface(IJIEnumVariant.IID));
        OnmsWbemProperty wbemObj;
        IJIDispatch wbemProperty_dispatch = null;
        for (int i = 0; i < (idx + 1); i++) {
            final Object[] values = enumVariant.next(1);
            final JIArray array = (JIArray) values[0];
            final Object[] arrayObj = (Object[]) array.getArrayInstance();
            for (int j = 0; j < arrayObj.length; j++) {
                wbemProperty_dispatch = (IJIDispatch) JIObjectFactory.narrowObject(((JIVariant) arrayObj[j]).getObjectAsComObject());
            }
        }
        wbemObj = new OnmsWbemPropertyImpl(wbemProperty_dispatch);
        return wbemObj;
    } catch (final JIException e) {
        throw new WmiException("Failed to enumerate WbemProperty variant: " + e.getMessage(), e);
    }
}
Also used : JIArray(org.jinterop.dcom.core.JIArray) IJIComObject(org.jinterop.dcom.core.IJIComObject) IJIEnumVariant(org.jinterop.dcom.impls.automation.IJIEnumVariant) IJIDispatch(org.jinterop.dcom.impls.automation.IJIDispatch) IJIComObject(org.jinterop.dcom.core.IJIComObject) OnmsWbemProperty(org.opennms.protocols.wmi.wbem.OnmsWbemProperty) WmiException(org.opennms.protocols.wmi.WmiException) JIException(org.jinterop.dcom.common.JIException)

Example 3 with IJIEnumVariant

use of org.jinterop.dcom.impls.automation.IJIEnumVariant in project Payara by payara.

the class WindowsWmi method setInfo.

/**
 * not strictly necessary but it was so difficult to write the code that I can't
 * bear to throw it away!
 * @throws WindowsException
 */
private void setInfo() throws WindowsException {
    try {
        processInfo = new String[count];
        IJIComObject comObj = variant.getObjectAsComObject();
        // todo is this needed?
        comObj.registerUnreferencedHandler(new IJIUnreferenced() {

            public void unReferenced() {
            }
        });
        IJIEnumVariant enumVARIANT = (IJIEnumVariant) JIObjectFactory.narrowObject(comObj.queryInterface(IJIEnumVariant.IID));
        for (int i = 0; i < count; i++) {
            Object[] values = enumVARIANT.next(1);
            JIArray array = (JIArray) values[0];
            Object[] arrayObj = (Object[]) array.getArrayInstance();
            for (int j = 0; j < arrayObj.length; j++) {
                IJIDispatch wbemObject_dispatch = (IJIDispatch) JIObjectFactory.narrowObject(((JIVariant) arrayObj[j]).getObjectAsComObject());
                JIVariant variant2 = (JIVariant) (wbemObject_dispatch.callMethodA("GetObjectText_", new Object[] { Integer.valueOf(1) }))[0];
                // normally arrayObj.length is 1
                if (j == 0)
                    processInfo[i] = variant2.getObjectAsString().getString();
            }
        }
    } catch (Exception e) {
        throw new WindowsException(e);
    }
}
Also used : JIArray(org.jinterop.dcom.core.JIArray) IJIComObject(org.jinterop.dcom.core.IJIComObject) JIVariant(org.jinterop.dcom.core.JIVariant) IJIEnumVariant(org.jinterop.dcom.impls.automation.IJIEnumVariant) IJIComObject(org.jinterop.dcom.core.IJIComObject) IJIDispatch(org.jinterop.dcom.impls.automation.IJIDispatch) IJIUnreferenced(org.jinterop.dcom.common.IJIUnreferenced) JIException(org.jinterop.dcom.common.JIException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 4 with IJIEnumVariant

use of org.jinterop.dcom.impls.automation.IJIEnumVariant in project opennms by OpenNMS.

the class OnmsWbemObjectSetImpl method get.

/**
 * {@inheritDoc}
 */
@Override
public OnmsWbemObject get(final Integer idx) throws WmiException {
    try {
        final IJIComObject enumComObject = wbemObjectSet.get("_NewEnum").getObjectAsComObject();
        final IJIEnumVariant enumVariant = (IJIEnumVariant) JIObjectFactory.narrowObject(enumComObject.queryInterface(IJIEnumVariant.IID));
        OnmsWbemObject wbemObj = null;
        IJIDispatch wbemObject_dispatch = null;
        for (int i = 0; i < (idx + 1); i++) {
            final Object[] values = enumVariant.next(1);
            final JIArray array = (JIArray) values[0];
            final Object[] arrayObj = (Object[]) array.getArrayInstance();
            for (int j = 0; j < arrayObj.length; j++) {
                wbemObject_dispatch = (IJIDispatch) JIObjectFactory.narrowObject(((JIVariant) arrayObj[j]).getObjectAsComObject());
            }
        }
        wbemObj = new OnmsWbemObjectImpl(wbemObject_dispatch);
        return wbemObj;
    } catch (final JIException e) {
        throw new WmiException("Failed to enumerate WbemObject variant: " + e.getMessage(), e);
    }
}
Also used : JIArray(org.jinterop.dcom.core.JIArray) IJIComObject(org.jinterop.dcom.core.IJIComObject) IJIEnumVariant(org.jinterop.dcom.impls.automation.IJIEnumVariant) IJIDispatch(org.jinterop.dcom.impls.automation.IJIDispatch) IJIComObject(org.jinterop.dcom.core.IJIComObject) OnmsWbemObject(org.opennms.protocols.wmi.wbem.OnmsWbemObject) WmiException(org.opennms.protocols.wmi.WmiException) OnmsWbemObject(org.opennms.protocols.wmi.wbem.OnmsWbemObject) JIException(org.jinterop.dcom.common.JIException)

Example 5 with IJIEnumVariant

use of org.jinterop.dcom.impls.automation.IJIEnumVariant in project opennms by OpenNMS.

the class OnmsWbemPropertySetImpl method getByName.

/**
 * {@inheritDoc}
 */
@Override
public OnmsWbemProperty getByName(final String name) throws WmiException {
    try {
        final IJIComObject enumComObject = wbemPropertySetDispatch.get("_NewEnum").getObjectAsComObject();
        final IJIEnumVariant enumVariant = (IJIEnumVariant) JIObjectFactory.narrowObject(enumComObject.queryInterface(IJIEnumVariant.IID));
        IJIDispatch wbemProperty_dispatch = null;
        for (int i = 0; i < count(); i++) {
            final Object[] values = enumVariant.next(1);
            final JIArray array = (JIArray) values[0];
            final Object[] arrayObj = (Object[]) array.getArrayInstance();
            for (int j = 0; j < arrayObj.length; j++) {
                wbemProperty_dispatch = (IJIDispatch) JIObjectFactory.narrowObject(((JIVariant) arrayObj[j]).getObjectAsComObject());
                // Check the name
                final JIVariant variant = wbemProperty_dispatch.get("Name");
                if (variant.getObjectAsString2().equalsIgnoreCase(name)) {
                    return new OnmsWbemPropertyImpl(wbemProperty_dispatch);
                }
            }
        }
        throw new WmiException("Property Name '" + name + "' not found.");
    } catch (final JIException e) {
        throw new WmiException("Failed to enumerate WbemProperty variant: " + e.getMessage(), e);
    }
}
Also used : JIArray(org.jinterop.dcom.core.JIArray) IJIComObject(org.jinterop.dcom.core.IJIComObject) JIVariant(org.jinterop.dcom.core.JIVariant) IJIEnumVariant(org.jinterop.dcom.impls.automation.IJIEnumVariant) IJIDispatch(org.jinterop.dcom.impls.automation.IJIDispatch) IJIComObject(org.jinterop.dcom.core.IJIComObject) WmiException(org.opennms.protocols.wmi.WmiException) JIException(org.jinterop.dcom.common.JIException)

Aggregations

JIException (org.jinterop.dcom.common.JIException)5 IJIComObject (org.jinterop.dcom.core.IJIComObject)5 JIArray (org.jinterop.dcom.core.JIArray)5 IJIDispatch (org.jinterop.dcom.impls.automation.IJIDispatch)5 IJIEnumVariant (org.jinterop.dcom.impls.automation.IJIEnumVariant)5 WmiException (org.opennms.protocols.wmi.WmiException)4 JIVariant (org.jinterop.dcom.core.JIVariant)2 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 IJIUnreferenced (org.jinterop.dcom.common.IJIUnreferenced)1 OnmsWbemMethod (org.opennms.protocols.wmi.wbem.OnmsWbemMethod)1 OnmsWbemObject (org.opennms.protocols.wmi.wbem.OnmsWbemObject)1 OnmsWbemProperty (org.opennms.protocols.wmi.wbem.OnmsWbemProperty)1