📄 dispatchptr.java
字号:
*
* @see #put(String, Object)
*/
public void put(String prop, double val) throws COMException {
put(prop, new Double(val));
}
/**
* For setting a new value for a property identified by name and
* a single index. Does not necessarely have to be a an integer -
* it depends on how the native put-method interprets the
* index.
* <br><br>
* The {@link Variant#writeObject(Object, LittleEndianOutputStream)} should be
* consulted for further information about what type of object should
* be passed as value. One of the shortcut methods for simple types could also
* be used.
*
* @param prop the name of the property.
* @param index the index to pass to the the native property
* put method.
* @param val the new value of the property.
*
* @throws COMException if no such property, or if the native
* code failed in any other way.
* @throws NullPointerException if prop is null.
*/
public void put(String prop, Object index, Object val) throws COMException {
putN(prop, new Object[] { index }, 1, val);
}
/**
* Shortcut method for setting a boolean <code>VT_BOOL</code> property
* identified by a single index.
*
* @see #put(String, Object, Object)
*/
public void put(String prop, Object index, boolean val) throws COMException {
put(prop, index, (val ? Boolean.TRUE : Boolean.FALSE));
}
/**
* Shortcut method for setting a byte <code>VT_UI1</code> property
* identified by a single index.
*
* @see #put(String, Object, Object)
*/
public void put(String prop, Object index, byte val) throws COMException {
put(prop, index, new Byte(val));
}
/**
* Shortcut method for setting a short <code>VT_I2</code> property
* identified by a single index.
*
* @see #put(String, Object, Object)
*/
public void put(String prop, Object index, short val) throws COMException {
put(prop, index, new Short(val));
}
/**
* Shortcut method for setting an integer <code>VT_I4</code> property
* identified by a single index.
*
* @see #put(String, Object, Object)
*/
public void put(String prop, Object index, int val) throws COMException {
put(prop, index, new Integer(val));
}
/**
* Shortcut method for setting a long <code>VT_I8</code> property
* identified by a single index.
*
* @see #put(String, Object, Object)
*/
public void put(String prop, Object index, long val) throws COMException {
put(prop, index, new Long(val));
}
/**
* Shortcut method for setting a float <code>VT_R4</code> property
* identified by a single index.
*
* @see #put(String, Object, Object)
*/
public void put(String prop, Object index, float val) throws COMException {
put(prop, index, new Float(val));
}
/**
* Shortcut method for setting a double <code>VT_R8</code> property
* identified by a single index.
*
* @see #put(String, Object, Object)
*/
public void put(String prop, Object index, double val) throws COMException {
put(prop, index, new Double(val));
}
/**
* For setting a new value for a property identified by the property name and
* multiple index'es. Does not necessarely have to be integers -
* it depends on how the native put-method interprets the
* indexes.
* <br><br>
* One scenario where this can be used, is eg. for setting the
* value of a single cell in a spreadsheet, where two "indexes"
* (row and column) are needed for identifying the cell.
* <br><br>
* The {@link Variant#writeObject(Object, LittleEndianOutputStream)} should be
* consulted for further information about what type of object should
* be passed as value.
*
* @param prop the name of the property.
* @param indexes the indexes to pass to the the native property
* put method.
* @param val the new value of the property.
* @throws COMException if no such property, or if the native
* code failed in any other way.
* @throws NullPointerException if prop is null.
*/
public void putN(String prop, Object[] indexes, Object val) throws COMException {
putN(prop, indexes, (indexes != null ? indexes.length : 0), val);
}
/**
* @see #putN(String, Object[], Object)
*/
public void putN(String prop, Object[] indexes, int indexesExpected, Object val) throws COMException {
if (prop == null) {
throw new NullPointerException("Property <null> not allowed.");
}
NakedByteStream nbs = new NakedByteStream();
LittleEndianOutputStream leos = new LittleEndianOutputStream(nbs);
int len = (indexes != null) ? indexes.length : 0;
// Marshal property value first
Variant.writeObject(val, leos);
// Marshal missing args
try {
for (int n = 0, extra = (indexesExpected - len); n < extra; n++) {
leos.writeShort(VarTypes.VT_ERROR);
}
} catch (IOException e) {
throw new COMException(e);
}
// Marshal specified args right to left
for (int n = (len - 1); n >= 0; n--) {
Variant.writeObject(indexes[n], leos);
}
GenericStub.dispatchInvoke(INVOKE_INST[indexesExpected + 1] + ":", indexesExpected + 1,
nbs.size(), nbs.getInternalBuffer(), prop, DispatchConstants.DISPATCH_PROPERTYPUT,
getPeer(), getUnknown());
}
/**
* For invoking a method taking no parameters.
*
* @param meth the name of the method to invoke.
* @return the return value of the method if any.
* @throws COMException if no such method, or if the native
* code failed in any other way.
* @throws NullPointerException if meth is null.
*/
public Object invoke(String meth) throws COMException {
return invokeN(meth, null);
}
/**
* Shortcut method for invoking a method taking one parameter.
*
* @see #invokeN(String, Object[])
*/
public Object invoke(String meth, Object arg1) throws COMException {
return invokeN(meth, new Object[] { arg1 });
}
/**
* Shortcut method for invoking a method taking two parameters.
*
* @see #invokeN(String, Object[])
*/
public Object invoke(String meth, Object arg1, Object arg2) throws COMException {
return invokeN(meth, new Object[] { arg1, arg2 });
}
/**
* Shortcut method for invoking a method taking three parameters.
*
* @see #invokeN(String, Object[])
*/
public Object invoke(String meth, Object arg1, Object arg2, Object arg3) throws COMException {
return invokeN(meth, new Object[] { arg1, arg2, arg3 });
}
/**
* Shortcut method for invoking a method taking four parameters.
*
* @see #invokeN(String, Object[])
*/
public Object invoke(String meth, Object arg1, Object arg2, Object arg3, Object arg4) throws COMException {
return invokeN(meth, new Object[] { arg1, arg2, arg3, arg4 });
}
/**
* For invoking a method on dispatch interface.
* <br><br>
* The {@link Variant#writeObject(Object, LittleEndianOutputStream)} should be
* consulted for further information about what type of objects should
* be passed as arguments to the method.
*
* @param meth the name of the method to invoke.
* @param args array of the arguments to pass to the method.
* @return the return value of the method if any.
* @throws COMException if no such method, or if the native
* code failed in any other way.
* @throws NullPointerException if meth is null.
*/
public Object invokeN(String meth, Object[] args) throws COMException {
return invokeN(meth, args, (args != null ? args.length : 0));
}
/**
* @see #invokeN(String, Object[])
*/
public Object invokeN(String meth, Object[] args, int argsExpected) throws COMException {
if (meth == null) {
throw new NullPointerException("<null>-methodname not allowed.");
}
try {
NakedByteStream nbs = new NakedByteStream();
LittleEndianOutputStream leos = new LittleEndianOutputStream(nbs);
StringBuffer outInst = new StringBuffer();
int len = (args != null) ? args.length : 0;
//arguments marshal from right to left. First, missing args:
for (int n = 0, extra = (argsExpected - len); n < extra; n++) {
leos.writeShort(VarTypes.VT_ERROR);
outInst.append(INVOKE_INST_OUT_SKIP); // skip the size of a variant.
}
//Second: specified args
for (int n = (len - 1); n >= 0; n--) {
Variant.writeObject(args[n], leos);
if (args[n] instanceof Variant.ByrefHolder) {
outInst.append(INVOKE_INST_OUT);
} else {
outInst.append(INVOKE_INST_OUT_SKIP); // skip the size of a variant.
}
}
byte[] result = GenericStub.dispatchInvoke(INVOKE_INST[argsExpected] + "V:" + outInst.toString(),
argsExpected, nbs.size(), nbs.getInternalBuffer(), meth, DispatchConstants.DISPATCH_METHOD,
getPeer(), getUnknown());
LittleEndianInputStream leis = new LittleEndianInputStream(new ByteArrayInputStream(result));
Object resultObj = Variant.readObject(leis);
// handle any byref/[out] values
for (int n = (len - 1); n >= 0; n--) {
if (args[n] instanceof Variant.ByrefHolder) {
((Variant.ByrefHolder)args[n]).setRef(Variant.readObject(leis));
}
}
return resultObj;
} catch (IOException ioe) {
throw new COMException(ioe);
}
}
/**
* used too lookup the input part of the marshalling instructions.
*/
private static final String INVOKE_INST[] = {
":",
"v:",
"vv:",
"vvv:",
"vvvv:",
"vvvvv:",
"vvvvvv:",
"vvvvvvv:",
"vvvvvvvv:",
"vvvvvvvvv:",
"vvvvvvvvvv:",
"vvvvvvvvvvv:",
"vvvvvvvvvvvv:",
"vvvvvvvvvvvvv:",
"vvvvvvvvvvvvvv:",
"vvvvvvvvvvvvvvv:",
"vvvvvvvvvvvvvvvv:",
"vvvvvvvvvvvvvvvvv:",
"vvvvvvvvvvvvvvvvvv:",
"vvvvvvvvvvvvvvvvvvv:",
"vvvvvvvvvvvvvvvvvvvv:",
"vvvvvvvvvvvvvvvvvvvvv:",
"vvvvvvvvvvvvvvvvvvvvvv:",
"vvvvvvvvvvvvvvvvvvvvvvv:",
"vvvvvvvvvvvvvvvvvvvvvvvv:",
"vvvvvvvvvvvvvvvvvvvvvvvvv:",
"vvvvvvvvvvvvvvvvvvvvvvvvvv:",
"vvvvvvvvvvvvvvvvvvvvvvvvvvv:",
"vvvvvvvvvvvvvvvvvvvvvvvvvvvv:",
"vvvvvvvvvvvvvvvvvvvvvvvvvvvvv:",
"vvvvvvvvvvvvvvvvvvvvvvvvvvvvvv:",
"vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv:",
"vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv:",
"vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv:",
"vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv:",
};
/**
* for specifying any [out] variants in the return part of the
* marshalling instructions.
*/
private static final char INVOKE_INST_OUT = 'V';
/**
* for specifying any variants that should be skipped in the return part
* of the marshalling instructions. Skip 16 bytes.
*/
private static final String INVOKE_INST_OUT_SKIP = "L" + Variant.SIZEOF;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -