Search in sources :

Example 16 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 17 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<Object>();
            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 18 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)

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