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