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);
}
}
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);
}
}
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);
}
}
Aggregations