/// <exception cref="Kirikiri.Tjs2.VariantException"></exception> public static object VariantToJavaObject(Variant param, Type type) { if (type.IsPrimitive) { // プリミティブタイプの场合 if (type.Equals(typeof(int))) { return Sharpen.Extensions.ValueOf(param.AsInteger()); } else { if (type.Equals(typeof(double))) { return (param.AsDouble()); } else { if (type.Equals(typeof(bool))) { return Sharpen.Extensions.ValueOf(param.AsInteger() != 0 ? true : false); } else { if (type.Equals(typeof(float))) { return ((float)param.AsDouble()); } else { if (type.Equals(typeof(long))) { return Sharpen.Extensions.ValueOf(param.AsInteger()); } else { if (type.Equals(typeof(char))) { return ((char)param.AsInteger()); } else { if (type.Equals(typeof(byte))) { return (unchecked((byte)param.AsInteger())); } else { if (type.Equals(typeof(short))) { return ((short)param.AsInteger()); } else { // may be Void.TYPE return null; } } } } } } } } } else { if (type.Equals(typeof(string))) { return param.AsString(); } else { if (type.Equals(typeof(ByteBuffer))) { return param.AsOctet(); } else { if (type.Equals(typeof(Variant))) { return param; } else { if (type.Equals(typeof(VariantClosure))) { return param.AsObjectClosure(); } else { if (type.Equals(typeof(Dispatch2))) { return param.AsObject(); } else { if (type.Equals(param.ToJavaObject().GetType())) { return param.ToJavaObject(); } else { // その他 のクラス return null; } } } } } } } }
/// <exception cref="Kirikiri.Tjs2.VariantException"></exception> /// <exception cref="Kirikiri.Tjs2.TJSException"></exception> public virtual bool Callback(string name, int flags, Variant value) { if ((flags & Interface.HIDDENMEMBER) != 0) { return true; } if (value.IsObject()) { // object Dispatch2 dsp = value.AsObject(); // determin dsp's object type Variant val; if (dsp != null) { if (dsp.GetNativeInstance(DictionaryClass.ClassID) != null) { // dictionary bool objrec = false; int count = mStack.Count; for (int i = 0; i < count; i++) { Dispatch2 v = mStack[i]; if (v == dsp) { // object recursion detected objrec = true; break; } } val = new Variant(); if (objrec) { val.SetObject(null); } else { // becomes null Dispatch2 newobj = TJS.CreateDictionaryObject(); val.SetObject(newobj, newobj); DictionaryNI newni; if ((newni = (DictionaryNI)newobj.GetNativeInstance(DictionaryClass.ClassID)) != null) { newni.AssignStructure(dsp, mStack); } } } else { if (dsp.GetNativeInstance(ArrayClass.ClassID) != null) { // array bool objrec = false; int count = mStack.Count; for (int i = 0; i < count; i++) { Dispatch2 v = mStack[i]; if (v == dsp) { // object recursion detected objrec = true; break; } } val = new Variant(); if (objrec) { val.SetObject(null); } else { // becomes null Dispatch2 newobj = TJS.CreateArrayObject(); val.SetObject(newobj, newobj); ArrayNI newni; if ((newni = (ArrayNI)newobj.GetNativeInstance(ArrayClass.ClassID)) != null) { newni.AssignStructure(dsp, mStack); } } } else { val = value; } } } else { // other object types val = value; } mDest.PropSet(Interface.MEMBERENSURE | Interface.IGNOREPROP, name, val, mDest); } else { // other types mDest.PropSet(Interface.MEMBERENSURE | Interface.IGNOREPROP, name, value, mDest); } return true; }