Search in sources :

Example 11 with JIException

use of org.jinterop.dcom.common.JIException 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 12 with JIException

use of org.jinterop.dcom.common.JIException 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 JIException

use of org.jinterop.dcom.common.JIException in project opennms by OpenNMS.

the class WmiClient method convertToNativeType.

/**
 * <p>convertToNativeType</p>
 *
 * @param type a {@link org.jinterop.dcom.core.JIVariant} object.
 * @return a {@link java.lang.Object} object.
 * @throws org.opennms.protocols.wmi.WmiException if any.
 */
public static Object convertToNativeType(final JIVariant type) throws WmiException {
    try {
        if (type.isArray()) {
            final ArrayList<Object> objs = new ArrayList<>();
            final Object[] array = (Object[]) type.getObjectAsArray().getArrayInstance();
            for (final Object element : array) {
                objs.add(convertToNativeType((JIVariant) element));
            }
            return objs;
        }
        switch(type.getType()) {
            case JIVariant.VT_NULL:
                return null;
            case JIVariant.VT_BSTR:
                return type.getObjectAsString().getString();
            case // sint16
            JIVariant.VT_I2:
                return type.getObjectAsShort();
            case JIVariant.VT_I4:
                return type.getObjectAsInt();
            case // uint8 (convert to Java Number)
            JIVariant.VT_UI1:
                return type.getObjectAsUnsigned().getValue();
            case JIVariant.VT_BOOL:
                return type.getObjectAsBoolean();
            case JIVariant.VT_DECIMAL:
                return type.getObjectAsFloat();
            case JIVariant.VT_DATE:
                return type.getObjectAsDate();
            default:
                throw new WmiException("Unknown type presented (" + type.getType() + "), defaulting to Object: " + type.toString());
        }
    } catch (final JIException e) {
        throw new WmiException("Failed to conver WMI type to native object: " + e.getMessage(), e);
    }
}
Also used : JIVariant(org.jinterop.dcom.core.JIVariant) ArrayList(java.util.ArrayList) IJIComObject(org.jinterop.dcom.core.IJIComObject) OnmsWbemObject(org.opennms.protocols.wmi.wbem.OnmsWbemObject) JIException(org.jinterop.dcom.common.JIException)

Example 14 with JIException

use of org.jinterop.dcom.common.JIException 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)

Example 15 with JIException

use of org.jinterop.dcom.common.JIException 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)

Aggregations

JIException (org.jinterop.dcom.common.JIException)18 IJIDispatch (org.jinterop.dcom.impls.automation.IJIDispatch)13 IJIComObject (org.jinterop.dcom.core.IJIComObject)9 JIVariant (org.jinterop.dcom.core.JIVariant)8 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)3 JIDefaultAuthInfoImpl (org.jinterop.dcom.common.JIDefaultAuthInfoImpl)2 JISession (org.jinterop.dcom.core.JISession)2 SWbemServices (org.jvnet.hudson.wmi.SWbemServices)2 Win32Service (org.jvnet.hudson.wmi.Win32Service)2 OnmsWbemObject (org.opennms.protocols.wmi.wbem.OnmsWbemObject)2 Proc (hudson.Proc)1 TaskListener (hudson.model.TaskListener)1 Channel (hudson.remoting.Channel)1 Listener (hudson.remoting.Channel.Listener)1 SocketInputStream (hudson.remoting.SocketInputStream)1