/// <summary> /// Reads map from input /// </summary> /// <param name="abstractHessianInput">Input stream</param> /// <returns>Read map or null</returns> public override object ReadMap(AbstractHessianInput abstractHessianInput) { IDictionary dictionary = null; if ((m_type == null) || (m_type.IsInterface && typeof(IDictionary).IsAssignableFrom(m_type))) { dictionary = new Dictionary <Object, Object>(); } else if (m_type.Equals(typeof(Dictionary <Object, Object>))) { dictionary = new Dictionary <Object, Object>(); } else { //dictionary = (IDictionary)Activator.CreateInstance(m_type); dictionary = new Dictionary <Object, Object>(); } abstractHessianInput.AddRef(dictionary); while (!abstractHessianInput.IsEnd()) { Object key = abstractHessianInput.ReadObject(); Object value = abstractHessianInput.ReadObject(); if (!dictionary.Contains(key)) { dictionary.Add(key, value); } } abstractHessianInput.ReadEnd(); return(dictionary); }
/// <summary> /// Reads map /// </summary> /// <param name="abstractHessianInput">HessianInput to read from</param> /// <returns>Read object or null</returns> public object ReadMap(AbstractHessianInput abstractHessianInput, Object result) { int refer = abstractHessianInput.AddRef(result); while (!abstractHessianInput.IsEnd()) { object objKey = abstractHessianInput.ReadObject(); IDictionary deserFields = GetDeserializableFields(); FieldInfo field = null; field = (FieldInfo)deserFields[objKey]; if (field != null) { object objFieldValue = abstractHessianInput.ReadObject(field.FieldType); field.SetValue(result, objFieldValue); } else { // mw BUGFIX!!! object ignoreme = abstractHessianInput.ReadObject(); } } abstractHessianInput.ReadEnd(); return(result); }
private Object ReadUntypedList(AbstractHessianInput abstractHessianInput) { IList listResult = new List <Object>(); abstractHessianInput.AddRef(listResult); while (!abstractHessianInput.IsEnd()) { listResult.Add(abstractHessianInput.ReadObject()); } abstractHessianInput.ReadEnd(); return(listResult); }
private Object ReadGenericList(AbstractHessianInput abstractHessianInput) { Type[] args = m_type.GetGenericArguments(); Type itemType = args[0]; Type listType = typeof(System.Collections.Generic.List <>).MakeGenericType(itemType); object list = Activator.CreateInstance(listType); abstractHessianInput.AddRef(list); while (!abstractHessianInput.IsEnd()) { object item = abstractHessianInput.ReadObject(itemType); listType.InvokeMember("Add", BindingFlags.InvokeMethod, null, list, new object[] { item }); } abstractHessianInput.ReadEnd(); return(list); }
/// <summary> /// Reads map /// </summary> /// <param name="abstractHessianInput">HessianInput to read from</param> /// <returns>Read object or null</returns> public object ReadMap(AbstractHessianInput abstractHessianInput, Object result) { int refer = abstractHessianInput.AddRef(result); while (!abstractHessianInput.IsEnd()) { object objKey = abstractHessianInput.ReadObject(); IDictionary deserPropertys = GetDeserializablePropertys(); PropertyInfo property = null; property = (PropertyInfo)deserPropertys[objKey]; if (property != null) { if (property.PropertyType == typeof(System.Decimal)) { int a = 10; } object objPropertyValue = abstractHessianInput.ReadObject(property.PropertyType); try { property.SetValue(result, objPropertyValue, null); } catch (Exception e) { } } else { // mw BUGFIX!!! object ignoreme = abstractHessianInput.ReadObject(); } } abstractHessianInput.ReadEnd(); return(result); }
/// <summary> /// Reads arrays /// </summary> /// <param name="abstractHessianInput">Hessian Input instance</param> /// <param name="intLength">Array length</param> /// <exception cref="CHessianException"/> /// <returns>Read object</returns> public override Object ReadList(AbstractHessianInput abstractHessianInput, int intLength) { switch (m_intCode) { case INTEGER_ARRAY: { if (intLength >= 0) { int []arrData = new int[intLength]; abstractHessianInput.AddRef(arrData); for (int i = 0; i < arrData.Length; i++) arrData[i] = abstractHessianInput.ReadInt(); abstractHessianInput.ReadEnd(); return arrData; } else { ArrayList arrayList = new ArrayList(); while (! abstractHessianInput.IsEnd()) arrayList.Add(abstractHessianInput.ReadInt()); abstractHessianInput.ReadEnd(); int []arrData = new int[arrayList.Count]; for (int i = 0; i < arrData.Length; i++) arrData[i] = (int) arrayList[i]; abstractHessianInput.AddRef(arrData); return arrData; } } case SBYTE_ARRAY: { if (intLength >= 0) { sbyte[] arrData = new sbyte[intLength]; abstractHessianInput.AddRef(arrData); for (int i = 0; i < arrData.Length; i++) arrData[i] = (sbyte)abstractHessianInput.ReadInt(); abstractHessianInput.ReadEnd(); return arrData; } else { ArrayList arrayList = new ArrayList(); while (!abstractHessianInput.IsEnd()) arrayList.Add(abstractHessianInput.ReadInt()); abstractHessianInput.ReadEnd(); sbyte[] arrData = new sbyte[arrayList.Count]; for (int i = 0; i < arrData.Length; i++) arrData[i] = (sbyte)arrayList[i]; abstractHessianInput.AddRef(arrData); return arrData; } } case STRING_ARRAY: { if (intLength >= 0) { string []arrData = new String[intLength]; abstractHessianInput.AddRef(arrData); for (int i = 0; i < arrData.Length; i++) arrData[i] = abstractHessianInput.ReadString(); abstractHessianInput.ReadEnd(); return arrData; } else { ArrayList arrayList = new ArrayList(); while (! abstractHessianInput.IsEnd()) arrayList.Add(abstractHessianInput.ReadString()); abstractHessianInput.ReadEnd(); string []arrData = new String[arrayList.Count]; abstractHessianInput.AddRef(arrData); for (int i = 0; i < arrData.Length; i++) arrData[i] = (string) arrayList[i]; return arrData; } } case BOOLEAN_ARRAY: { if (intLength >= 0) { bool []arrData = new bool[intLength]; abstractHessianInput.AddRef(arrData); for (int i = 0; i < arrData.Length; i++) arrData[i] = abstractHessianInput.ReadBoolean(); abstractHessianInput.ReadEnd(); return arrData; } else { ArrayList arrayList = new ArrayList(); while (! abstractHessianInput.IsEnd()) arrayList.Add(abstractHessianInput.ReadBoolean()); abstractHessianInput.ReadEnd(); bool []arrData = new bool[arrayList.Count]; abstractHessianInput.AddRef(arrData); for (int i = 0; i < arrData.Length; i++) arrData[i] = (bool) arrayList[i]; return arrData; } } case SHORT_ARRAY: { if (intLength >= 0) { short []arrData = new short[intLength]; abstractHessianInput.AddRef(arrData); for (int i = 0; i < arrData.Length; i++) arrData[i] = (short) abstractHessianInput.ReadInt(); abstractHessianInput.ReadEnd(); return arrData; } else { ArrayList arrayList = new ArrayList(); while (! abstractHessianInput.IsEnd()) arrayList.Add((short) abstractHessianInput.ReadInt()); abstractHessianInput.ReadEnd(); short []arrData = new short[arrayList.Count]; for (int i = 0; i < arrData.Length; i++) arrData[i] = (short) arrayList[i]; abstractHessianInput.AddRef(arrData); return arrData; } } case LONG_ARRAY: { if (intLength >= 0) { long []arrData = new long[intLength]; abstractHessianInput.AddRef(arrData); for (int i = 0; i < arrData.Length; i++) arrData[i] = abstractHessianInput.ReadLong(); abstractHessianInput.ReadEnd(); return arrData; } else { ArrayList arrayList = new ArrayList(); while (! abstractHessianInput.IsEnd()) arrayList.Add(abstractHessianInput.ReadLong()); abstractHessianInput.ReadEnd(); long []arrData = new long[arrayList.Count]; for (int i = 0; i < arrData.Length; i++) arrData[i] = (long) arrayList[i]; abstractHessianInput.AddRef(arrData); return arrData; } } case FLOAT_ARRAY: { if (intLength >= 0) { float []arrData = new float[intLength]; abstractHessianInput.AddRef(arrData); for (int i = 0; i < arrData.Length; i++) arrData[i] = (float)(abstractHessianInput.ReadDouble()); abstractHessianInput.ReadEnd(); return arrData; } else { ArrayList arrayList = new ArrayList(); while (! abstractHessianInput.IsEnd()) arrayList.Add(abstractHessianInput.ReadDouble()); abstractHessianInput.ReadEnd(); float []arrData = new float[arrayList.Count]; for (int i = 0; i < arrData.Length; i++) arrData[i] = (float) arrayList[i]; abstractHessianInput.AddRef(arrData); return arrData; } } case DOUBLE_ARRAY: { if (intLength >= 0) { double []arrData = new double[intLength]; abstractHessianInput.AddRef(arrData); for (int i = 0; i < arrData.Length; i++) arrData[i] = abstractHessianInput.ReadDouble(); abstractHessianInput.ReadEnd(); return arrData; } else { ArrayList arrayList = new ArrayList(); while (! abstractHessianInput.IsEnd()) arrayList.Add(abstractHessianInput.ReadDouble()); abstractHessianInput.ReadEnd(); double []data = new double[arrayList.Count]; abstractHessianInput.AddRef(data); for (int i = 0; i < data.Length; i++) data[i] = (double) arrayList[i]; return data; } } case OBJECT_ARRAY: { if (intLength >= 0) { object []arrData = new Object[intLength]; abstractHessianInput.AddRef(arrData); for (int i = 0; i < arrData.Length; i++) arrData[i] = abstractHessianInput.ReadObject(); abstractHessianInput.ReadEnd(); return arrData; } else { ArrayList arrayList = new ArrayList(); abstractHessianInput.AddRef(arrayList); // XXX: potential issues here while (! abstractHessianInput.IsEnd()) arrayList.Add(abstractHessianInput.ReadObject()); abstractHessianInput.ReadEnd(); object []arrData = new Object[arrayList.Count]; for (int i = 0; i < arrData.Length; i++) arrData[i] = arrayList[i]; return arrData; } } default: throw new CHessianException("not supperted type for deserialization"); } }
public override object ReadMap(AbstractHessianInput abstractHessianInput) { Dictionary <Object, Object> fieldValueMap = new Dictionary <Object, Object>(); string _message = null; Exception _innerException = null; while (!abstractHessianInput.IsEnd()) { object objKey = abstractHessianInput.ReadObject(); if (objKey != null) { IDictionary deserFields = GetDeserializableFields(); FieldInfo field = (FieldInfo)deserFields[objKey]; // try to convert a Java Exception in a .NET exception if (objKey.ToString() == "_message" || objKey.ToString() == "detailMessage") { if (field != null) { _message = abstractHessianInput.ReadObject(field.FieldType) as string; } else { _message = abstractHessianInput.ReadObject().ToString(); } } else if (objKey.ToString() == "_innerException" || objKey.ToString() == "cause") { try { if (field != null) { _innerException = abstractHessianInput.ReadObject(field.FieldType) as Exception; } else { _innerException = abstractHessianInput.ReadObject(typeof(Exception)) as Exception; } } catch (Exception) { // als Cause ist bei Java gerne mal eine zirkuläre Referenz auf die Exception selbst // angegeben. Das klappt nicht, weil die Referenz noch nicht registriert ist, // weil der Typ noch nicht klar ist (s.u.) } } else { if (field != null) { object objFieldValue = abstractHessianInput.ReadObject(field.FieldType); fieldValueMap.Add(field, objFieldValue); } else { // ignore (z. B. Exception Stacktrace "stackTrace" von Java) abstractHessianInput.ReadObject(); } //field.SetValue(result, objFieldValue); } } } abstractHessianInput.ReadEnd(); object result = null; try { #if COMPACT_FRAMEWORK //CF TODO: tbd #else try { result = Activator.CreateInstance(this.m_type, new object[2] { _message, _innerException }); } catch (Exception) { try { result = Activator.CreateInstance(this.m_type, new object[1] { _innerException }); } catch (Exception) { try { result = Activator.CreateInstance(this.m_type, new object[1] { _message }); } catch (Exception) { result = Activator.CreateInstance(this.m_type); } } } #endif } catch (Exception) { result = new Exception(_message, _innerException); } foreach (KeyValuePair <object, object> entry in fieldValueMap) { FieldInfo fieldInfo = (FieldInfo)entry.Key; object value = entry.Value; try { fieldInfo.SetValue(result, value); } catch (Exception) {} } // besser spät als gar nicht. int refer = abstractHessianInput.AddRef(result); return(result); }
/// <summary> /// Reads map /// </summary> /// <param name="abstractHessianInput">HessianInput to read from</param> /// <returns>Read object or null</returns> public object ReadMap(AbstractHessianInput abstractHessianInput, Object result) { int refer = abstractHessianInput.AddRef(result); while (! abstractHessianInput.IsEnd()) { object objKey = abstractHessianInput.ReadObject(); IDictionary deserFields = GetDeserializableFields(); FieldInfo field = null; field = (FieldInfo)deserFields[objKey]; if (field != null) { object objFieldValue = abstractHessianInput.ReadObject(field.FieldType); field.SetValue(result, objFieldValue); } else { // mw BUGFIX!!! object ignoreme = abstractHessianInput.ReadObject(); } } abstractHessianInput.ReadEnd(); return result; }
/// <summary> /// Reads arrays /// </summary> /// <param name="abstractHessianInput">Hessian Input instance</param> /// <param name="intLength">Array length</param> /// <exception cref="CHessianException"/> /// <returns>Read object</returns> public override Object ReadList(AbstractHessianInput abstractHessianInput, int intLength) { switch (m_intCode) { case INTEGER_ARRAY: { if (intLength >= 0) { int [] arrData = new int[intLength]; abstractHessianInput.AddRef(arrData); for (int i = 0; i < arrData.Length; i++) { arrData[i] = abstractHessianInput.ReadInt(); } abstractHessianInput.ReadEnd(); return(arrData); } else { List <Object> list = new List <Object>(); while (!abstractHessianInput.IsEnd()) { list.Add(abstractHessianInput.ReadInt()); } abstractHessianInput.ReadEnd(); int [] arrData = new int[list.Count]; for (int i = 0; i < arrData.Length; i++) { arrData[i] = (int)list[i]; } abstractHessianInput.AddRef(arrData); return(arrData); } } case SBYTE_ARRAY: { if (intLength >= 0) { sbyte[] arrData = new sbyte[intLength]; abstractHessianInput.AddRef(arrData); for (int i = 0; i < arrData.Length; i++) { arrData[i] = (sbyte)abstractHessianInput.ReadInt(); } abstractHessianInput.ReadEnd(); return(arrData); } else { List <Object> list = new List <Object>(); while (!abstractHessianInput.IsEnd()) { list.Add(abstractHessianInput.ReadInt()); } abstractHessianInput.ReadEnd(); sbyte[] arrData = new sbyte[list.Count]; for (int i = 0; i < arrData.Length; i++) { arrData[i] = (sbyte)list[i]; } abstractHessianInput.AddRef(arrData); return(arrData); } } case STRING_ARRAY: { if (intLength >= 0) { string [] arrData = new String[intLength]; abstractHessianInput.AddRef(arrData); for (int i = 0; i < arrData.Length; i++) { arrData[i] = abstractHessianInput.ReadString(); } abstractHessianInput.ReadEnd(); return(arrData); } else { List <Object> list = new List <Object>(); while (!abstractHessianInput.IsEnd()) { list.Add(abstractHessianInput.ReadString()); } abstractHessianInput.ReadEnd(); string [] arrData = new String[list.Count]; abstractHessianInput.AddRef(arrData); for (int i = 0; i < arrData.Length; i++) { arrData[i] = (string)list[i]; } return(arrData); } } case BOOLEAN_ARRAY: { if (intLength >= 0) { bool [] arrData = new bool[intLength]; abstractHessianInput.AddRef(arrData); for (int i = 0; i < arrData.Length; i++) { arrData[i] = abstractHessianInput.ReadBoolean(); } abstractHessianInput.ReadEnd(); return(arrData); } else { List <Object> list = new List <Object>(); while (!abstractHessianInput.IsEnd()) { list.Add(abstractHessianInput.ReadBoolean()); } abstractHessianInput.ReadEnd(); bool [] arrData = new bool[list.Count]; abstractHessianInput.AddRef(arrData); for (int i = 0; i < arrData.Length; i++) { arrData[i] = (bool)list[i]; } return(arrData); } } case SHORT_ARRAY: { if (intLength >= 0) { short [] arrData = new short[intLength]; abstractHessianInput.AddRef(arrData); for (int i = 0; i < arrData.Length; i++) { arrData[i] = (short)abstractHessianInput.ReadInt(); } abstractHessianInput.ReadEnd(); return(arrData); } else { List <Object> list = new List <Object>(); while (!abstractHessianInput.IsEnd()) { list.Add((short)abstractHessianInput.ReadInt()); } abstractHessianInput.ReadEnd(); short [] arrData = new short[list.Count]; for (int i = 0; i < arrData.Length; i++) { arrData[i] = (short)list[i]; } abstractHessianInput.AddRef(arrData); return(arrData); } } case LONG_ARRAY: { if (intLength >= 0) { long [] arrData = new long[intLength]; abstractHessianInput.AddRef(arrData); for (int i = 0; i < arrData.Length; i++) { arrData[i] = abstractHessianInput.ReadLong(); } abstractHessianInput.ReadEnd(); return(arrData); } else { List <Object> list = new List <Object>(); while (!abstractHessianInput.IsEnd()) { list.Add(abstractHessianInput.ReadLong()); } abstractHessianInput.ReadEnd(); long [] arrData = new long[list.Count]; for (int i = 0; i < arrData.Length; i++) { arrData[i] = (long)list[i]; } abstractHessianInput.AddRef(arrData); return(arrData); } } case FLOAT_ARRAY: { if (intLength >= 0) { float [] arrData = new float[intLength]; abstractHessianInput.AddRef(arrData); for (int i = 0; i < arrData.Length; i++) { arrData[i] = (float)(abstractHessianInput.ReadDouble()); } abstractHessianInput.ReadEnd(); return(arrData); } else { List <Object> list = new List <Object>(); while (!abstractHessianInput.IsEnd()) { list.Add(abstractHessianInput.ReadDouble()); } abstractHessianInput.ReadEnd(); float [] arrData = new float[list.Count]; for (int i = 0; i < arrData.Length; i++) { arrData[i] = (float)list[i]; } abstractHessianInput.AddRef(arrData); return(arrData); } } case DOUBLE_ARRAY: { if (intLength >= 0) { double [] arrData = new double[intLength]; abstractHessianInput.AddRef(arrData); for (int i = 0; i < arrData.Length; i++) { arrData[i] = abstractHessianInput.ReadDouble(); } abstractHessianInput.ReadEnd(); return(arrData); } else { List <Object> list = new List <Object>(); while (!abstractHessianInput.IsEnd()) { list.Add(abstractHessianInput.ReadDouble()); } abstractHessianInput.ReadEnd(); double [] data = new double[list.Count]; abstractHessianInput.AddRef(data); for (int i = 0; i < data.Length; i++) { data[i] = (double)list[i]; } return(data); } } case OBJECT_ARRAY: { if (intLength >= 0) { object [] arrData = new Object[intLength]; abstractHessianInput.AddRef(arrData); for (int i = 0; i < arrData.Length; i++) { arrData[i] = abstractHessianInput.ReadObject(); } abstractHessianInput.ReadEnd(); return(arrData); } else { List <Object> list = new List <Object>(); abstractHessianInput.AddRef(list); // XXX: potential issues here while (!abstractHessianInput.IsEnd()) { list.Add(abstractHessianInput.ReadObject()); } abstractHessianInput.ReadEnd(); object [] arrData = new Object[list.Count]; for (int i = 0; i < arrData.Length; i++) { arrData[i] = list[i]; } return(arrData); } } default: throw new CHessianException("not supperted type for deserialization"); } }
/// <summary> /// Reads map from input /// </summary> /// <param name="abstractHessianInput">Input stream</param> /// <returns>Read map or null</returns> public override object ReadMap(AbstractHessianInput abstractHessianInput) { IDictionary dictionary = null; if ((m_type == null) || (m_type.IsInterface && typeof(IDictionary).IsAssignableFrom(m_type))) dictionary = new Dictionary<Object, Object>(); else if (m_type.Equals(typeof(Dictionary<Object, Object>))) dictionary = new Dictionary<Object, Object>(); else { //dictionary = (IDictionary)Activator.CreateInstance(m_type); dictionary = new Dictionary<Object, Object>(); } abstractHessianInput.AddRef(dictionary); while (! abstractHessianInput.IsEnd()) { Object key = abstractHessianInput.ReadObject(); Object value = abstractHessianInput.ReadObject(); if (!dictionary.Contains(key)) { dictionary.Add(key, value); } } abstractHessianInput.ReadEnd(); return dictionary; }
public override object ReadMap(AbstractHessianInput abstractHessianInput) { Dictionary<Object, Object> fieldValueMap = new Dictionary<Object, Object>(); string _message = null; Exception _innerException = null; while (! abstractHessianInput.IsEnd()) { object objKey = abstractHessianInput.ReadObject(); if(objKey != null) { IDictionary deserFields = GetDeserializableFields(); FieldInfo field = (FieldInfo) deserFields[objKey]; // try to convert a Java Exception in a .NET exception if(objKey.ToString() == "_message" || objKey.ToString() == "detailMessage") { if (field != null) _message = abstractHessianInput.ReadObject(field.FieldType) as string; else _message = abstractHessianInput.ReadObject().ToString(); } else if(objKey.ToString() == "_innerException" || objKey.ToString() == "cause") { try { if (field != null) _innerException = abstractHessianInput.ReadObject(field.FieldType) as Exception; else _innerException = abstractHessianInput.ReadObject(typeof(Exception)) as Exception; } catch (Exception) { // als Cause ist bei Java gerne mal eine zirkuläre Referenz auf die Exception selbst // angegeben. Das klappt nicht, weil die Referenz noch nicht registriert ist, // weil der Typ noch nicht klar ist (s.u.) } } else { if (field != null) { object objFieldValue = abstractHessianInput.ReadObject(field.FieldType); fieldValueMap.Add(field, objFieldValue); } else // ignore (z. B. Exception Stacktrace "stackTrace" von Java) abstractHessianInput.ReadObject(); //field.SetValue(result, objFieldValue); } } } abstractHessianInput.ReadEnd(); object result = null; try { #if COMPACT_FRAMEWORK //CF TODO: tbd #else try { result = Activator.CreateInstance(this.m_type, new object[2]{_message, _innerException}); } catch(Exception) { try { result = Activator.CreateInstance(this.m_type, new object[1]{_innerException}); } catch(Exception) { try { result = Activator.CreateInstance(this.m_type, new object[1]{_message}); } catch(Exception) { result = Activator.CreateInstance(this.m_type); } } } #endif } catch(Exception) { result = new Exception(_message, _innerException); } foreach (KeyValuePair<object, object> entry in fieldValueMap) { FieldInfo fieldInfo = (FieldInfo) entry.Key; object value = entry.Value; try {fieldInfo.SetValue(result, value);} catch(Exception){} } // besser spät als gar nicht. int refer = abstractHessianInput.AddRef(result); return result; }
private Object ReadUntypedList(AbstractHessianInput abstractHessianInput) { IList listResult = new List<Object>(); abstractHessianInput.AddRef(listResult); while (!abstractHessianInput.IsEnd()) listResult.Add(abstractHessianInput.ReadObject()); abstractHessianInput.ReadEnd(); return listResult; }
private Object ReadGenericList(AbstractHessianInput abstractHessianInput) { Type[] args = m_type.GetGenericArguments(); Type itemType = args[0]; Type listType = typeof(System.Collections.Generic.List<>).MakeGenericType(itemType); object list = Activator.CreateInstance(listType); abstractHessianInput.AddRef(list); while (!abstractHessianInput.IsEnd()) { object item = abstractHessianInput.ReadObject(itemType); listType.InvokeMember("Add", BindingFlags.InvokeMethod, null, list, new object[] { item }); } abstractHessianInput.ReadEnd(); return list; }