예제 #1
0
        /// <summary>
        /// Reads the object as a map.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="expectedType"></param>
        /// <returns></returns>
        public IDeserializer GetListDeserializer(String type, Type expectedType)
        {
            IDeserializer reader = GetListDeserializer(type);

            if (expectedType == null ||
                expectedType.Equals(reader.GetOwnType()) ||
                expectedType.IsAssignableFrom(reader.GetOwnType()))
            {
                return(reader);
            }

            return(GetDeserializer(expectedType));
        }
예제 #2
0
        /// <summary>
        /// Reads the object as a map.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="expectedType"></param>
        /// <returns></returns>
        public IDeserializer GetObjectDeserializer(String type, Type expectedType)
        {
            IDeserializer reader = GetObjectDeserializer(type);

            if (expectedType == null ||
                expectedType == reader.GetOwnType() ||
                expectedType.IsAssignableFrom(reader.GetOwnType()) ||
                reader.IsReadResolve() ||
                typeof(IHessianHandle).IsAssignableFrom(reader.GetOwnType()))
            {
                return(reader);
            }

            return(GetDeserializer(expectedType));
        }
예제 #3
0
        /// <summary>
        /// Reads an arbitrary object from the input stream.
        /// </summary>
        /// <param name="expectedType">the expected class if the protocol doesn't supply it.</param>
        /// <returns>Read object</returns>
        /// <exception cref="CHessianException"/>
        /// <exception cref="CHessianException"/>
        public override object ReadObject(Type expectedType)
        {
            object objResult = null;

            if (expectedType == null || expectedType.Equals(typeof(object)))
            {
                objResult = ReadObject();
            }
            else
            {
                int intTag = Read();
                if (intTag != CHessianProtocolConstants.PROT_NULL)
                {
                    switch (intTag)
                    {
                    case CHessianProtocolConstants.PROT_MAP_TYPE:
                    {
                        string strType = ReadType();

                        AbstractDeserializer deserializer = GetObjectDeserializer(strType);

                        if (expectedType == deserializer.GetOwnType() || expectedType.IsAssignableFrom(deserializer.GetOwnType()))
                        {
                            return(deserializer.ReadMap(this));
                        }

                        deserializer = GetDeserializer(expectedType);


                        return(deserializer.ReadMap(this));
                    }

                    case CHessianProtocolConstants.PROT_REF_TYPE:
                    {
                        int intRefNumber = ParseInt();
                        return(m_arrRefs[intRefNumber]);
                    }

                    case 'r':
                    {
                        throw new CHessianException("remote type is not implemented");
                    }

                    case CHessianProtocolConstants.PROT_LIST_TYPE:
                    {
                        string        strType      = this.ReadType();
                        int           intLength    = this.ReadLength();
                        IDeserializer deserializer = this.m_serializerFactory.GetObjectDeserializer(strType);
                        if ((expectedType == deserializer.GetOwnType() || expectedType.IsAssignableFrom(deserializer.GetOwnType())))
                        {
                            //if (expectedType != deserializer.GetOwnType() && expectedType.IsAssignableFrom(deserializer.GetOwnType()))
                            return(deserializer.ReadList(this, intLength));
                        }
                        deserializer = m_serializerFactory.GetDeserializer(expectedType);
                        return(deserializer.ReadList(this, intLength));
                    }
                    }

                    m_intPeek = intTag;

                    objResult = m_serializerFactory.GetDeserializer(expectedType).ReadObject(this);
                }
            }
            return(objResult);
        }