Search in sources :

Example 11 with IJIDispatch

use of org.jinterop.dcom.impls.automation.IJIDispatch 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)

Example 12 with IJIDispatch

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

the class WmiClient method performInstanceOf.

/** {@inheritDoc} */
@Override
public OnmsWbemObjectSet performInstanceOf(final String wmiClass) throws WmiException {
    try {
        // Execute the InstancesOf method on the remote SWbemServices object.
        final JIVariant[] results = m_WbemServices.callMethodA("InstancesOf", new Object[] { new JIString(wmiClass), 0, JIVariant.OPTIONAL_PARAM() });
        final IJIDispatch wOSd = (IJIDispatch) JIObjectFactory.narrowObject((results[0]).getObjectAsComObject());
        return new OnmsWbemObjectSetImpl(wOSd);
    } catch (final JIException e) {
        throw new WmiException("Failed to perform WMI operation (\\\\" + wmiClass + ") : " + e.getMessage(), e);
    }
}
Also used : JIVariant(org.jinterop.dcom.core.JIVariant) JIString(org.jinterop.dcom.core.JIString) OnmsWbemObjectSetImpl(org.opennms.protocols.wmi.wbem.jinterop.OnmsWbemObjectSetImpl) IJIDispatch(org.jinterop.dcom.impls.automation.IJIDispatch) JIException(org.jinterop.dcom.common.JIException)

Example 13 with IJIDispatch

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

the class WmiClient method performExecQuery.

/** {@inheritDoc} */
@Override
public OnmsWbemObjectSet performExecQuery(final String strQuery, final String strQueryLanguage, final Integer flags) throws WmiException {
    try {
        final JIVariant[] results = m_WbemServices.callMethodA("ExecQuery", new Object[] { new JIString(strQuery), JIVariant.OPTIONAL_PARAM(), JIVariant.OPTIONAL_PARAM(), JIVariant.OPTIONAL_PARAM() });
        final IJIDispatch wOSd = (IJIDispatch) JIObjectFactory.narrowObject((results[0]).getObjectAsComObject());
        return new OnmsWbemObjectSetImpl(wOSd);
    } catch (final JIException e) {
        throw new WmiException("Failed to execute query '" + strQuery + "': " + e.getMessage(), e);
    }
}
Also used : JIVariant(org.jinterop.dcom.core.JIVariant) JIString(org.jinterop.dcom.core.JIString) OnmsWbemObjectSetImpl(org.opennms.protocols.wmi.wbem.jinterop.OnmsWbemObjectSetImpl) IJIDispatch(org.jinterop.dcom.impls.automation.IJIDispatch) JIException(org.jinterop.dcom.common.JIException)

Aggregations

JIException (org.jinterop.dcom.common.JIException)13 IJIDispatch (org.jinterop.dcom.impls.automation.IJIDispatch)13 IJIComObject (org.jinterop.dcom.core.IJIComObject)8 JIVariant (org.jinterop.dcom.core.JIVariant)7 WmiException (org.opennms.protocols.wmi.WmiException)7 JIString (org.jinterop.dcom.core.JIString)5 JIArray (org.jinterop.dcom.core.JIArray)4 IJIEnumVariant (org.jinterop.dcom.impls.automation.IJIEnumVariant)4 OnmsWbemObjectSetImpl (org.opennms.protocols.wmi.wbem.jinterop.OnmsWbemObjectSetImpl)4 UnknownHostException (java.net.UnknownHostException)1 JIComServer (org.jinterop.dcom.core.JIComServer)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 OnmsWbemObjectImpl (org.opennms.protocols.wmi.wbem.jinterop.OnmsWbemObjectImpl)1