ReadObject() public abstract method

Reads an arbitrary object from the input stream.
public abstract ReadObject ( ) : object
return object
Example #1
0
        /// <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);
        }
Example #2
0
        /// <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 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);
            }
        }
        /// <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);
        }
Example #5
0
        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 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);
        }
Example #7
0
        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);
        }
Example #8
0
        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 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);
        }
        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 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;
        }
Example #13
0
        /// <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");
            }
        }
 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;
        }
Example #16
0
        /// <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 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>
        /// 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();
        }
        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;
        }