src/org/jruby/ext/win32ole/RubyWIN32OLE.java in jruby-win32ole-0.8.1 vs src/org/jruby/ext/win32ole/RubyWIN32OLE.java in jruby-win32ole-0.8.2
- old
+ new
@@ -3,10 +3,11 @@
import org.racob.com.Dispatch;
import org.racob.com.EnumVariant;
import org.racob.com.Variant;
import java.util.Calendar;
import java.util.Date;
+import java.util.List;
import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.RubyClass;
import org.jruby.RubyInteger;
import org.jruby.RubyObject;
@@ -14,10 +15,11 @@
import org.jruby.javasupport.JavaUtil;
import org.jruby.runtime.Block;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
+import org.racob.com.SafeArray;
import win32ole.Win32oleService;
/**
*/
public class RubyWIN32OLE extends RubyObject {
@@ -163,10 +165,11 @@
Object[] objectArgs = makeObjectArgs(argsArray);
int[] errorArgs = makeErrorArgs(objectArgs.length);
Variant returnValue = Dispatch.invoke(dispatch, dispatchId, dispatchType,
objectArgs, errorArgs);
+ System.out.println("INVOKEINTERNAL: " + returnValue);
return fromVariant(context.getRuntime(), returnValue);
}
private int[] makeErrorArgs(int size) {
return size <= 0 ? EMPTY_ERROR_ARGS : new int[size];
}
@@ -230,16 +233,43 @@
}
return runtime.newFixnum(((Number) object).intValue());
} else if (object instanceof String) {
return runtime.newString((String) object);
+ } else if (object instanceof SafeArray) {
+ return listFromSafeArray(runtime, (SafeArray) object);
}
return JavaUtil.convertJavaToUsableRubyObject(runtime, object);
}
+ private static IRubyObject listFromSafeArray(Ruby runtime, SafeArray list) {
+ RubyArray newArray = runtime.newArray();
+
+ for (int i = 0; i < list.size(); i++) {
+ Object element = list.get(i);
+ IRubyObject convertedElement = null;
+
+ if (element instanceof SafeArray) {
+ convertedElement = null; //TODO: Borked
+ } else if (element instanceof Variant) {
+ convertedElement = fromVariant(runtime, (Variant) element);
+ } else {
+ throw runtime.newArgumentError("Unknown element found in SafeArray: " +
+ element.getClass());
+ }
+ newArray.append(convertedElement);
+ }
+
+ return newArray;
+ }
+
public static IRubyObject fromVariant(Ruby runtime, Variant variant) {
if (variant == null) return runtime.getNil();
+
+ if (variant.isArray()) {
+ return listFromSafeArray(runtime, (SafeArray) variant.getArray());
+ }
switch (variant.getType()) {
case Variant.VariantBoolean:
return runtime.newBoolean(variant.getBoolean());
case Variant.VariantDispatch: