/// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="componentABSTRACTDeserializer">Deserializer for the instances in the array</param>
 public CArrayDeserializer(AbstractDeserializer componentABSTRACTDeserializer)
 {
     if (componentABSTRACTDeserializer != null)
     {
         m_componentType = componentABSTRACTDeserializer.GetOwnType();
     }
 }
        /// <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>
        /// Returns according deserializer to the given type
        /// </summary>
        /// <param name="type">Type of the deserializer</param>
        /// <returns>Deserializer instance</returns>
        public AbstractDeserializer GetDeserializer(Type type)
        {
            object val;
            AbstractDeserializer abstractDeserializer = null;

            if (!m_htDeserializerMap.TryGetValue(type, out val))
            {
                if (typeof(IDictionary).IsAssignableFrom(type))
                {
                    abstractDeserializer = new CMapDeserializer(type);
                }
                else if (type.IsGenericType && typeof(System.Nullable <>).IsAssignableFrom(type.GetGenericTypeDefinition()))
                {
                    // nullbarer Typ
                    Type[] args = type.GetGenericArguments();
                    return(GetDeserializer(args[0]));
                }
                else if (type.IsEnum)
                {
                    return(new CEnumDeserializer(type));
                }
                else if (type.IsArray)
                {
                    abstractDeserializer = new CArrayDeserializer(GetDeserializer(type.GetElementType()));
                }
                else if (typeof(IList).IsAssignableFrom(type) ||
                         (type.IsGenericType &&
                          typeof(System.Collections.Generic.List <>).IsAssignableFrom(type.GetGenericTypeDefinition())))
                {
                    abstractDeserializer = new CCollectionDeserializer(type);
                }
                else if (typeof(Exception).IsAssignableFrom(type))
                {
                    abstractDeserializer = new CExceptionDeserializer(type);
                }
                else
                {
                    if (m_htCachedDeserializerMap.TryGetValue(type.FullName, out val))
                    {
                        abstractDeserializer = (AbstractDeserializer)val;
                    }
                    else
                    {
                        abstractDeserializer = new CObjectDeserializer(type);
                        m_htCachedDeserializerMap.Add(type.FullName, abstractDeserializer);
                    }
                }
            }
            else
            {
                abstractDeserializer = (AbstractDeserializer)val;
            }
            return(abstractDeserializer);
        }
        /// <summary>
        /// Returns the Deserializer - instance that reads object as a map
        /// </summary>
        /// <param name="strType">Object - Type</param>
        /// <returns>Deserializer object</returns>
        public AbstractDeserializer GetObjectDeserializer(string strType)

        {
            AbstractDeserializer abstractDeserializer = GetDeserializer(strType);

            if (abstractDeserializer != null)
            {
                return(abstractDeserializer);
            }
            else
            {
                return(new CMapDeserializer(typeof(Dictionary <Object, Object>)));
            }
        }
        /// <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));
            }
        }
Exemplo n.º 6
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 != PROT_NULL)
                {
                    switch (intTag)
                    {
                    case 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 PROT_REF_TYPE:
                    {
                        int intRefNumber = ParseInt();
                        return(m_arrRefs[intRefNumber]);
                    }

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

                    case PROT_LIST_TYPE:
                    {
                        string strType   = this.ReadType();
                        int    intLength = this.ReadLength();
                        AbstractDeserializer deserializer = this.m_serializerFactory.GetObjectDeserializer(strType);
                        if (expectedType != deserializer.GetType() && expectedType.IsAssignableFrom(deserializer.GetType()))
                        {
                            //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);
        }
        /// <summary>
        /// Returns a deserializer based on a string type.
        /// </summary>
        /// <param name="strType">Type of the object for deserialization</param>
        /// <returns>deserializer based on a string type</returns>
        public AbstractDeserializer GetDeserializer(string strType)
        {
            if (strType == null || strType.Equals(""))
            {
                return(null);
            }

            AbstractDeserializer abstractDeserializer = null;
            object val = null;

            if (m_htTypeMap.TryGetValue(strType, out val))
            {
                return((AbstractDeserializer)val);
            }

            if (strType.StartsWith("["))
            {
                AbstractDeserializer subABSTRACTDeserializer = GetDeserializer(strType.Substring(1));
                abstractDeserializer = new CArrayDeserializer(subABSTRACTDeserializer);
                return(abstractDeserializer);
            }
            else
            {
                                #if COMPACT_FRAMEWORK
                // do CF stuff
                if (m_assamblyFiles == null)
                {
                    m_assamblyFiles = AllAssamblyNamesInCurrentDirectory();
                }
                foreach (string ass in m_assamblyFiles)
                {
                    string typeString = strType + "," + ass;
                    Type   searchType = Type.GetType(typeString);
                    if (searchType != null)
                    {
                        abstractDeserializer = GetDeserializer(searchType);
                        return(abstractDeserializer);
                    }
                }
                                #else
                // do other stuff
                //Diese Typsuche funzt bei Mobileloesung nicht:
                //Es wurde ein andere Suche implementiert
                Assembly[] ass = AppDomain.CurrentDomain.GetAssemblies();
                Type       t   = null;
                foreach (Assembly a in ass)
                {
                    t = a.GetType(strType);
                    if (t != null)
                    {
                        break;
                    }
                }
                if (t != null)
                {
                    abstractDeserializer = GetDeserializer(t);
                }
                        #endif
            }

            /* TODO: Implementieren Type.GetType(type) geht nicht, man muss die Assembly eingeben.
             */
            //deserializer = getDeserializer(Type.GetType(type));
            return(abstractDeserializer);
        }
Exemplo n.º 8
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="componentABSTRACTDeserializer">Deserializer for the instances in the array</param>
 public CArrayDeserializer(AbstractDeserializer componentABSTRACTDeserializer)
 {
     if (componentABSTRACTDeserializer != null)
         m_componentType = componentABSTRACTDeserializer.GetOwnType();
 }