/// <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 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 override object ReadMap(AbstractHessianInput abstractHessianInput) { object objKey = abstractHessianInput.ReadObject(); var result = JsonHelper.DeserializeObject(this.m_type, (string)objKey); 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 string valued object /// </summary> /// <param name="abstractHessianInput">HessianInput Instance</param> /// <returns>Read string valued object</returns> public override object ReadMap(AbstractHessianInput abstractHessianInput) { String strInitValue = null; while (!abstractHessianInput.IsEnd()) { string strKey = abstractHessianInput.ReadString(); string strValue = abstractHessianInput.ReadString(); if (strKey.Equals("value")) { strInitValue = strValue; } } abstractHessianInput.ReadMapEnd(); if (strInitValue == null) { throw new IOException(m_type.FullName + " expects name."); } try { return(m_constructor.Invoke(new Object[] { strInitValue })); } catch (Exception e) { throw new IOException(e.ToString()); } }
/// <summary> /// Reads the array. /// </summary> /// <param name="abstractHessianInput">HessianInput</param> /// <param name="intLength">Length of data</param> /// <returns>Array data</returns> public override Object ReadList(AbstractHessianInput abstractHessianInput, int intLength) { if (intLength >= 0) { // mw bugfix //Object[] arrResult = createArray(intLength); Array arrResult = createArray(intLength); abstractHessianInput.AddRef(arrResult); if (m_componentType != null) { for (int i = 0; i < arrResult.Length; i++) { arrResult.SetValue(abstractHessianInput.ReadObject(m_componentType), i); } } else { for (int i = 0; i < arrResult.Length; i++) { arrResult.SetValue(abstractHessianInput.ReadObject(), i); } } abstractHessianInput.ReadListEnd(); return(arrResult); } else { List <Object> colList = new List <Object>(); abstractHessianInput.AddRef(colList); if (m_componentType != null) { while (!abstractHessianInput.IsEnd()) { colList.Add(abstractHessianInput.ReadObject(m_componentType)); } } else { while (!abstractHessianInput.IsEnd()) { colList.Add(abstractHessianInput.ReadObject()); } } abstractHessianInput.ReadListEnd(); //Object[] arrResult = createArray(colList.Count); Array arrResult = createArray(colList.Count); for (int i = 0; i < colList.Count; i++) { arrResult.SetValue(colList[i], i); } return(arrResult); } }
public override object ReadObject(AbstractHessianInput abstractHessianInput) { double strInitValue = abstractHessianInput.ReadDouble(); //if (strInitValue == null) // throw new IOException("No value found for decimal."); return(Convert.ToDecimal(strInitValue)); }
/// <summary> /// Reads the object as a map. (Dictionary<Object, Object>) /// </summary> /// <param name="abstractHessianInput">HessianInput instance to read from</param> /// <param name="strType">Type of the map (can be null)</param> /// <returns>Object read from stream</returns> public Object ReadMap(AbstractHessianInput abstractHessianInput, string strType) { AbstractDeserializer abstractDeserializer = GetDeserializer(strType); if (abstractDeserializer == null) { abstractDeserializer = new CMapDeserializer(typeof(Dictionary <Object, Object>)); } return(abstractDeserializer.ReadMap(abstractHessianInput)); }
/// <summary> /// Reads list. /// </summary> /// <param name="abstractHessianInput">HessianInput - Instance</param> /// <param name="intListLength">Length of the list</param> /// <returns>Return value is always an List<Object> - Instance, /// apart from StringCollection - Instances</returns> public override System.Object ReadList(AbstractHessianInput abstractHessianInput, int intListLength) { if (m_type != null && IsGenericList(m_type)) { return(ReadGenericList(abstractHessianInput)); } else { return(ReadUntypedList(abstractHessianInput)); } }
private Object ReadUntypedList(AbstractHessianInput abstractHessianInput) { IList listResult = new List <Object>(); abstractHessianInput.AddRef(listResult); while (!abstractHessianInput.IsEnd()) { listResult.Add(abstractHessianInput.ReadObject()); } abstractHessianInput.ReadEnd(); return(listResult); }
/// <summary> /// Reads map /// </summary> /// <param name="abstractHessianInput">HessianInput to read from</param> /// <returns>Read object or null</returns> public override object ReadMap(AbstractHessianInput abstractHessianInput) { #if COMPACT_FRAMEWORK object result = Activator.CreateInstance(this.m_type); #else object result = Activator.CreateInstance(this.m_type.Assembly.FullName, this.m_type.FullName).Unwrap(); // object result = Activator.CreateInstance(this.m_type); // object result = null; #endif return(ReadMap(abstractHessianInput, result)); }
/// <summary> /// Reads the array. /// </summary> /// <param name="abstractHessianInput">HessianInput</param> /// <param name="intLength">Length of data</param> /// <param name="strType">Type of the array objects</param> /// <returns>Array data</returns> public Object ReadList(AbstractHessianInput abstractHessianInput, int intLength, string strType) { AbstractDeserializer abstractDeserializer = GetDeserializer(strType); if (abstractDeserializer != null) { return(abstractDeserializer.ReadList(abstractHessianInput, intLength)); } else { return(new CCollectionDeserializer(typeof(List <Object>)).ReadList( abstractHessianInput, intLength)); } }
/// <summary> /// Reads object /// </summary> /// <param name="abstractHessianInput">Instance of AbstractHessianInput</param> /// <returns>Object that was read</returns> public override object ReadObject(AbstractHessianInput abstractHessianInput) { int intCode = abstractHessianInput.ReadListStart(); switch (intCode) { case CHessianInput.PROT_NULL: return(null); case CHessianInput.PROT_REF_TYPE: return(abstractHessianInput.ReadRef()); } int intLength = abstractHessianInput.ReadLength(); return(ReadList(abstractHessianInput, intLength)); }
public override object ReadMap(AbstractHessianInput abstractHessianInput) { string enumName = null; while (!abstractHessianInput.IsEnd()) { string key = abstractHessianInput.ReadString(); if (key.Equals("name")) enumName = abstractHessianInput.ReadString(); else abstractHessianInput.ReadObject(); // ignore } abstractHessianInput.ReadMapEnd(); object result = Enum.Parse(e_type, enumName, false); abstractHessianInput.AddRef(result); return result; }
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 from input /// </summary> /// <param name="abstractHessianInput">Input stream</param> /// <returns>Read map or null</returns> public override object ReadObject(AbstractHessianInput abstractHessianInput) { //Read map start int code = abstractHessianInput.ReadMapStart(); switch (code) { case CHessianInput.PROT_NULL: return(null); case CHessianInput.PROT_REF_TYPE: return(abstractHessianInput.ReadRef()); case 'r': throw new CHessianException("remote type is not implemented!"); } return(ReadMap(abstractHessianInput)); }
public override object ReadMap(AbstractHessianInput abstractHessianInput) { String strInitValue = null; while (!abstractHessianInput.IsEnd()) { string strKey = abstractHessianInput.ReadString(); string strValue = abstractHessianInput.ReadString(); if (strKey.Equals("value")) strInitValue = strValue; } abstractHessianInput.ReadMapEnd(); if (strInitValue == null) throw new IOException("No value found for decimal."); return Decimal.Parse(strInitValue); }
public override object ReadMap(AbstractHessianInput abstractHessianInput) { string enumName = null; while (!abstractHessianInput.IsEnd()) { string key = abstractHessianInput.ReadString(); if (key.Equals("name")) { enumName = abstractHessianInput.ReadString(); } else { abstractHessianInput.ReadObject(); // ignore } } abstractHessianInput.ReadMapEnd(); object result = Enum.Parse(e_type, enumName, false); 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 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); }
public override object ReadMap(AbstractHessianInput abstractHessianInput) { String strInitValue = null; while (!abstractHessianInput.IsEnd()) { string strKey = abstractHessianInput.ReadString(); string strValue = abstractHessianInput.ReadString(); if (strKey.Equals("value")) { strInitValue = strValue; } } abstractHessianInput.ReadMapEnd(); if (strInitValue == null) { throw new IOException("No value found for decimal."); } return(Decimal.Parse(strInitValue)); }
/// <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 object as map /// </summary> /// <param name="abstractHessianInput">HessianInput to read from</param> /// <returns>Read object or null</returns> public override object ReadObject(AbstractHessianInput abstractHessianInput) { return this.ReadMap( abstractHessianInput ); }
/// <summary> /// Reads the basic (primitive & Date ) data types /// and arrays of them /// </summary> /// <param name="abstractHessianInput">Hessian Input instance</param> /// <exception cref="CHessianException"/> /// <returns>Read object</returns> public override object ReadObject(AbstractHessianInput abstractHessianInput) { switch (m_intCode) { case BOOLEAN: return abstractHessianInput.ReadBoolean(); case BYTE: return (byte) abstractHessianInput.ReadInt(); case SBYTE: return (sbyte) abstractHessianInput.ReadInt(); case FLOAT: return (float) abstractHessianInput.ReadDouble(); case SHORT: return (short) abstractHessianInput.ReadInt(); case INTEGER: return abstractHessianInput.ReadInt(); case LONG: return abstractHessianInput.ReadLong(); case DOUBLE: return abstractHessianInput.ReadDouble(); case STRING: return abstractHessianInput.ReadString(); case CHARACTER: { //int charResult = abstractHessianInput.ReadInt(); //return (char)charResult; //Bei caucho ist hier ein Bug //TODO:Test string strResult = abstractHessianInput.ReadString(); if (strResult == null || strResult.Length==0) return null; else return strResult[0]; } case BOOLEAN_ARRAY: case SHORT_ARRAY: case INTEGER_ARRAY: case SBYTE_ARRAY: case LONG_ARRAY: case FLOAT_ARRAY: case DOUBLE_ARRAY: case STRING_ARRAY: { if (abstractHessianInput.ReadListStart() == 'N') return null; abstractHessianInput.ReadType(); int intLength = abstractHessianInput.ReadLength(); return ReadList(abstractHessianInput, intLength); } case BYTE_ARRAY: return abstractHessianInput.ReadBytes(); case CHARACTER_ARRAY: { string strResult = abstractHessianInput.ReadString(); if (strResult == null) return null; else { int intLength= strResult.Length; char [] arrChars = new char[intLength]; arrChars = strResult.ToCharArray(); return arrChars; } } case DATE: long javaTime = abstractHessianInput.ReadUTCDate(); return CDateDeserializer.MakeCSharpDate(javaTime); default: throw new CHessianException("not supperted type for deserialization"); } }
/// <summary> /// Reads object /// </summary> /// <param name="abstractHessianInput">HessianInput-Instance</param> /// <returns>Object that was read</returns> /// <exception cref="CHessianException"/> public virtual object ReadObject(AbstractHessianInput abstractHessianInput) { throw new CHessianException(this.GetType().ToString()); }
/// <summary> /// Reads date /// </summary> /// <param name="abstractHessianInput">HessianInput - Instance</param> /// <returns>DateTime - Instance</returns> public override object ReadObject(AbstractHessianInput abstractHessianInput) { long javaTime = abstractHessianInput.ReadUTCDate(); return(MakeCSharpDate(javaTime)); }
/// <summary> /// Reads the array. /// </summary> /// <param name="abstractHessianInput">HessianInput</param> /// <param name="intLength">Length of data</param> /// <returns>Array data</returns> public override Object ReadList(AbstractHessianInput abstractHessianInput, int intLength) { if (intLength >= 0) { // mw bugfix //Object[] arrResult = createArray(intLength); Array arrResult = createArray(intLength); abstractHessianInput.AddRef(arrResult); if (m_componentType != null) { for (int i = 0; i < arrResult.Length; i++) arrResult.SetValue(abstractHessianInput.ReadObject(m_componentType), i); } else { for (int i = 0; i < arrResult.Length; i++) arrResult.SetValue(abstractHessianInput.ReadObject(), i); } abstractHessianInput.ReadListEnd(); return arrResult; } else { ArrayList colList = new ArrayList(); abstractHessianInput.AddRef(colList); if (m_componentType != null) { while (!abstractHessianInput.IsEnd()) colList.Add(abstractHessianInput.ReadObject(m_componentType)); } else { while (!abstractHessianInput.IsEnd()) colList.Add(abstractHessianInput.ReadObject()); } abstractHessianInput.ReadListEnd(); //Object[] arrResult = createArray(colList.Count); Array arrResult = createArray(colList.Count); for (int i = 0; i < colList.Count; i++) arrResult.SetValue(colList[i], i); return arrResult; } }
/// <summary> /// Reads string valued object /// </summary> /// <param name="abstractHessianInput">HessianInput Instance</param> /// <returns>Read string valued object</returns> public override object ReadMap(AbstractHessianInput abstractHessianInput) { String strInitValue = null; while (!abstractHessianInput.IsEnd()) { string strKey = abstractHessianInput.ReadString(); string strValue = abstractHessianInput.ReadString(); if (strKey.Equals("value")) strInitValue = strValue; } abstractHessianInput.ReadMapEnd(); if (strInitValue == null) throw new IOException(m_type.FullName + " expects name."); try { return m_constructor.Invoke(new Object[]{strInitValue}); } catch (Exception e) { throw new IOException(e.ToString()); } }
/// <summary> /// Invoke the object with the request from the input stream. /// </summary> /// <param name="inHessian">the Hessian input stream</param> /// <param name="outHessian">the Hessian output stream</param> public void invoke(AbstractHessianInput inHessian, AbstractHessianOutput outHessian) { inHessian.StartCall(); MethodInfo methodInf = getMethodInfo(inHessian.Method); //If the method doesn't exist if (methodInf == null) { outHessian.StartReply(); outHessian.WriteFault("NoSuchMethodException", "The service has no method named: " + inHessian.Method, null); outHessian.CompleteReply(); return; } ParameterInfo[] paramInfo = methodInf.GetParameters(); Object[] valuesParam = new Object[paramInfo.Length]; for (int i = 0; i < paramInfo.Length; i++) { valuesParam[i] = inHessian.ReadObject(paramInfo[i].ParameterType); } inHessian.CompleteCall(); Object result = null; try { result = methodInf.Invoke(m_Service,valuesParam); } catch(Exception e) { //TODO: Exception besser behandeln if (e.GetType() == typeof(System.Reflection.TargetInvocationException)) { if (e.InnerException != null) { e = e.InnerException; } } outHessian.StartReply(); outHessian.WriteFault("ServiceException", e.Message, e); outHessian.CompleteReply(); return; } outHessian.StartReply(); outHessian.WriteObject(result); outHessian.CompleteReply(); }
/// <summary> /// Reads the basic (primitive & Date ) data types /// and arrays of them /// </summary> /// <param name="abstractHessianInput">Hessian Input instance</param> /// <exception cref="CHessianException"/> /// <returns>Read object</returns> public override object ReadObject(AbstractHessianInput abstractHessianInput) { switch (m_intCode) { case BOOLEAN: return(abstractHessianInput.ReadBoolean()); case BYTE: return((byte)abstractHessianInput.ReadInt()); case SBYTE: return((sbyte)abstractHessianInput.ReadInt()); case FLOAT: return((float)abstractHessianInput.ReadDouble()); case SHORT: return((short)abstractHessianInput.ReadInt()); case INTEGER: return(abstractHessianInput.ReadInt()); case LONG: return(abstractHessianInput.ReadLong()); case DOUBLE: return(abstractHessianInput.ReadDouble()); case STRING: return(abstractHessianInput.ReadString()); case CHARACTER: { //int charResult = abstractHessianInput.ReadInt(); //return (char)charResult; //Bei caucho ist hier ein Bug //TODO:Test string strResult = abstractHessianInput.ReadString(); if (strResult == null || strResult.Length == 0) { return(null); } else { return(strResult[0]); } } case BOOLEAN_ARRAY: case SHORT_ARRAY: case INTEGER_ARRAY: case SBYTE_ARRAY: case LONG_ARRAY: case FLOAT_ARRAY: case DOUBLE_ARRAY: case STRING_ARRAY: { if (abstractHessianInput.ReadListStart() == 'N') { return(null); } abstractHessianInput.ReadType(); int intLength = abstractHessianInput.ReadLength(); return(ReadList(abstractHessianInput, intLength)); } case BYTE_ARRAY: return(abstractHessianInput.ReadBytes()); case CHARACTER_ARRAY: { string strResult = abstractHessianInput.ReadString(); if (strResult == null) { return(null); } else { int intLength = strResult.Length; char [] arrChars = new char[intLength]; arrChars = strResult.ToCharArray(); return(arrChars); } } case DATE: long javaTime = abstractHessianInput.ReadUTCDate(); return(CDateDeserializer.MakeCSharpDate(javaTime)); default: throw new CHessianException("not supperted type for deserialization"); } }
/// <summary> /// Reads date /// </summary> /// <param name="abstractHessianInput">HessianInput - Instance</param> /// <returns>DateTime - Instance</returns> public override object ReadObject(AbstractHessianInput abstractHessianInput) { long javaTime = abstractHessianInput.ReadUTCDate(); return MakeCSharpDate(javaTime); //return DateTime.FromFileTimeUtc( abstractHessianInput.ReadUTCDate()); }
/// <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"); } }
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 the list /// </summary> /// <param name="abstractHessianInput">HessianInput-Instance to read from</param> /// <returns>Read list</returns> /// <exception cref="CHessianException"/> public virtual object ReadList(AbstractHessianInput abstractHessianInput, int intLength) { throw new CHessianException(this.GetType().ToString()); }
/// <summary> /// Reads the map /// </summary> /// <param name="abstractHessianInput">HessianInput-Instance to read from</param> /// <returns>Read map</returns> /// <exception cref="CHessianException"/> public virtual object ReadMap(AbstractHessianInput abstractHessianInput) { throw new CHessianException(this.GetType().ToString()); }
/// <summary> /// Reads date /// </summary> /// <param name="abstractHessianInput">HessianInput - Instance</param> /// <returns>DateTime - Instance</returns> public override object ReadObject(AbstractHessianInput abstractHessianInput) { long javaTime = abstractHessianInput.ReadUTCDate(); return MakeCSharpDate(javaTime); }
/// <summary> /// Reads the list /// </summary> /// <param name="abstractHessianInput">HessianInput-Instance to read from</param> /// <returns>Read list</returns> /// <exception cref="CHessianException"/> public virtual object ReadList(AbstractHessianInput abstractHessianInput, int intLength) { throw new CHessianException(this.GetType().ToString()); }
/// <summary> /// Reads object /// </summary> /// <param name="abstractHessianInput">Instance of AbstractHessianInput</param> /// <returns>Object that was read</returns> public override object ReadObject(AbstractHessianInput abstractHessianInput) { int intCode = abstractHessianInput.ReadListStart(); switch (intCode) { case CHessianInput.PROT_NULL: return null; case CHessianInput.PROT_REF_TYPE: return abstractHessianInput.ReadRef(); } int intLength = abstractHessianInput.ReadLength(); return ReadList(abstractHessianInput, intLength); }
/// <summary> /// Reads list. /// </summary> /// <param name="abstractHessianInput">HessianInput - Instance</param> /// <param name="intListLength">Length of the list</param> /// <returns>Return value is always an List<Object> - Instance, /// apart from StringCollection - Instances</returns> public override System.Object ReadList(AbstractHessianInput abstractHessianInput, int intListLength) { if (m_type != null && IsGenericList(m_type)) return ReadGenericList(abstractHessianInput); else return ReadUntypedList(abstractHessianInput); }
private Object ReadUntypedList(AbstractHessianInput abstractHessianInput) { IList listResult = new List<Object>(); abstractHessianInput.AddRef(listResult); while (!abstractHessianInput.IsEnd()) listResult.Add(abstractHessianInput.ReadObject()); abstractHessianInput.ReadEnd(); return listResult; }
/// <summary> /// Reads enum from input /// </summary> /// <param name="abstractHessianInput">Input stream</param> /// <returns>Read map or null</returns> public override object ReadObject(AbstractHessianInput abstractHessianInput) { //Read map start int code = abstractHessianInput.ReadMapStart(); switch (code) { case CHessianInput.PROT_NULL: return null; case CHessianInput.PROT_REF_TYPE: return abstractHessianInput.ReadRef(); case 'r': throw new CHessianException("remote type is not implemented!"); } return ReadMap(abstractHessianInput); }
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; }
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 override object ReadMap(AbstractHessianInput abstractHessianInput) { #if COMPACT_FRAMEWORK object result = Activator.CreateInstance(this.m_type); #else object result = Activator.CreateInstance(this.m_type.Assembly.FullName, this.m_type.FullName).Unwrap(); // object result = Activator.CreateInstance(this.m_type); // object result = null; #endif return ReadMap(abstractHessianInput, 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"); } }
/// <summary> /// Reads object as map /// </summary> /// <param name="abstractHessianInput">HessianInput to read from</param> /// <returns>Read object or null</returns> public override object ReadObject(AbstractHessianInput abstractHessianInput) { return(this.ReadMap(abstractHessianInput)); }