示例#1
0
        public override object Instantiate(UnmarshallingContext context)
        {
            object @object = new object();

            OnInstantiate(context, @object);
            return(@object);
        }
        public object FromXml(XStreamReader reader, UnmarshallingContext context)
        {
            int count = reader.NoOfChildren();

            // Use the actual data type we are deserializing to rather than inferring from xml metadata
            Type arrayType = context.currentTargetType;

            string arrayTypeName = reader.GetAttribute(ARRAY_TYPE);

            if (arrayTypeName != "")
            {
                arrayType = context.GetTypeFromOtherAssemblies(arrayTypeName);
            }

            if (arrayType.IsArray)
            {
                // Due to the way that the currentTargetType and the constructor works, we need to get the element type instead of the current type.
                //  This probably won't work well for arrays of arrays.
                arrayType = arrayType.GetElementType();
            }

            Array result = Array.CreateInstance(arrayType, count);

            if (count != 0)
            {
                reader.MoveDown();
                for (int i = 0; i < count; i++)
                {
                    result.SetValue(context.ConvertOriginal(), i);
                    reader.MoveNext();
                }
                reader.MoveUp();
            }
            return(result);
        }
示例#3
0
 public static void Activate(UnmarshallingContext context, ITypeHandler4 handler)
 {
     if (handler is IReferenceTypeHandler)
     {
         ((IReferenceTypeHandler)handler).Activate(context);
     }
 }
 public override void Activate(UnmarshallingContext context)
 {
     if (!CheckEnabled(context, context))
     {
         return;
     }
     context.SlotFormat().DoWithSlotIndirection(context, new _IClosure4_110(this, context
                                                                            ));
 }
示例#5
0
        public virtual object ReadPrefetch(Db4objects.Db4o.Internal.Transaction trans, ByteArrayBuffer
                                           buffer, int addToIDTree)
        {
            UnmarshallingContext context = new UnmarshallingContext(trans, buffer, this, addToIDTree
                                                                    , false);

            context.ActivationDepth(new FixedActivationDepth(1, ActivationMode.Prefetch));
            return(context.Read());
        }
示例#6
0
        public object Read(Db4objects.Db4o.Internal.Transaction trans, ByteArrayBuffer buffer
                           , object obj, IActivationDepth instantiationDepth, int addToIDTree, bool checkIDTree
                           )
        {
            UnmarshallingContext context = new UnmarshallingContext(trans, buffer, this, addToIDTree
                                                                    , checkIDTree);

            context.PersistentObject(obj);
            context.ActivationDepth(instantiationDepth);
            return(context.Read());
        }
        private static void GetValueObject(UnmarshallingContext context, ref object value, XStreamReader reader)
        {
            Type previousType = context.currentTargetType;
            Type valueType    = context.currentTargetType.GenericTypeArguments[1];

            string nodeName = reader.GetNodeName();

            context.currentTargetType = valueType;
            value = context.ConvertOriginal(valueType);

            context.currentTargetType = previousType;
        }
        private static void GetKeyObject(UnmarshallingContext context, ref object key, XStreamReader reader)
        {
            Type previousType = context.currentTargetType;
            Type keyType      = context.currentTargetType.GenericTypeArguments[0];

            string nodeName = reader.GetNodeName();

            context.currentTargetType = keyType;
            key = context.ConvertOriginal(keyType);

            context.currentTargetType = previousType;
        }
        public override object Instantiate(UnmarshallingContext context)
        {
            object obj = context.PersistentObject();

            if (obj == null)
            {
                obj = context.Read(TypeHandler());
                context.SetObjectWeak(obj);
            }
            context.SetStateClean();
            return(obj);
        }
 public object FromXml(XStreamReader reader, UnmarshallingContext context)
 {
     IList result = (IList) DynamicInstanceBuilder.CreateInstance(Type.GetType(reader.GetAttribute(LIST_TYPE)));
     int count = reader.NoOfChildren();
     reader.MoveDown();
     for (int i = 0; i < count; i++) {
         result.Add(context.ConvertAnother());
         reader.MoveNext();
     }
     reader.MoveUp();
     return result;
 }
示例#11
0
 public object FromXml(XStreamReader reader, UnmarshallingContext context) {
     int count = reader.NoOfChildren();
     Array result = Array.CreateInstance(context.GetTypeFromOtherAssemblies(reader.GetAttribute(ARRAY_TYPE)), count);
     if (count != 0) {
         reader.MoveDown();
         for (int i = 0; i < count; i++) {
             result.SetValue(context.ConvertOriginal(), i);
             reader.MoveNext();
         }
         reader.MoveUp();
     }
     return result;
 }
示例#12
0
        public override void Activate(UnmarshallingContext context)
        {
            object obj = Read(context);

            // Activation of members is necessary on purpose here.
            // Classes like Hashtable need fully activated members
            // to be able to calculate hashCode()
            if (obj != null)
            {
                context.Container().Activate(context.Transaction(), obj, context.ActivationDepth(
                                                 ));
            }
            SetOn(context.Transaction(), context.PersistentObject(), obj);
        }
        private static void GetObject(UnmarshallingContext context, ref object key, ref object value, XStreamReader reader)
        {
            string nodeName = reader.GetNodeName();
            object o        = context.ConvertOriginal();

            if (BaseDictionaryConverter <Hashtable> .KEY.Equals(nodeName))
            {
                key = o;
            }
            else
            {
                value = o;
            }
        }
示例#14
0
        public object FromXml(XStreamReader reader, UnmarshallingContext context)
        {
            IList result = (IList)DynamicInstanceBuilder.CreateInstance(Type.GetType(reader.GetAttribute(LIST_TYPE)));
            int   count  = reader.NoOfChildren();

            reader.MoveDown();
            for (int i = 0; i < count; i++)
            {
                result.Add(context.ConvertAnother());
                reader.MoveNext();
            }
            reader.MoveUp();
            return(result);
        }
示例#15
0
        public object FromXml(XStreamReader reader, UnmarshallingContext context)
        {
            byte[] bytes = null;

            int count = reader.NoOfChildren();

            if (reader.MoveDown("byte-array"))
            {
                string base64 = reader.GetValue();
                bytes = Convert.FromBase64String(base64);
                reader.MoveUp();
            }

            return(bytes);
        }
示例#16
0
        public override void Activate(UnmarshallingContext context)
        {
            if (!CheckAlive(context, context))
            {
                return;
            }
            if (!ShouldStoreField())
            {
                IncrementOffset(context, context);
                return;
            }
            object toSet = Read(context);

            InformAboutTransaction(toSet, context.Transaction());
            Set(context.PersistentObject(), toSet);
        }
示例#17
0
        public object FromXml(XStreamReader reader, UnmarshallingContext context)
        {
            int   count  = reader.NoOfChildren();
            Array result = Array.CreateInstance(context.GetTypeFromOtherAssemblies(reader.GetAttribute(ARRAY_TYPE)), count);

            if (count != 0)
            {
                reader.MoveDown();
                for (int i = 0; i < count; i++)
                {
                    result.SetValue(context.ConvertOriginal(), i);
                    reader.MoveNext();
                }
                reader.MoveUp();
            }
            return(result);
        }
示例#18
0
        public static int SlotHandlerVersion(IExtObjectContainer objectContainer, object
                                             obj)
        {
            int                  id         = (int)objectContainer.GetID(obj);
            IObjectInfo          objectInfo = objectContainer.GetObjectInfo(obj);
            ObjectContainerBase  container  = (ObjectContainerBase)objectContainer;
            Transaction          trans      = container.Transaction;
            ByteArrayBuffer      buffer     = container.ReadBufferById(trans, id);
            UnmarshallingContext context    = new UnmarshallingContext(trans, (ObjectReference)objectInfo
                                                                       , Const4.Transient, false);

            context.Buffer(buffer);
            context.PersistentObject(obj);
            context.ActivationDepth(new LegacyActivationDepth(0));
            context.Read();
            return(context.HandlerVersion());
        }
        public object FromXml(XStreamReader reader, UnmarshallingContext context)
        {
            IDictionary result = EmptyDictionary(reader);
            int         count  = reader.NoOfChildren();

            reader.MoveDown();
            for (int i = 0; i < count; i++)
            {
                reader.MoveDown();
                object key = null, value = null;
                GetObject(context, ref key, ref value, reader);
                reader.MoveNext();
                GetObject(context, ref key, ref value, reader);
                result.Add(key, value);
                reader.MoveUp();
                reader.MoveNext();
            }
            return(result);
        }
        public void ActivateAspects(UnmarshallingContext context)
        {
            BooleanByRef           schemaUpdateDetected = new BooleanByRef();
            ContextState           savedState           = context.SaveState();
            ITraverseAspectCommand command = new _MarshallingInfoTraverseAspectCommand_63(context
                                                                                          , schemaUpdateDetected, EnsureFieldList(context));

            // TODO: cant the aspect handle it itself?
            // Probably no because old aspect versions might not be able
            // to handle null...
            TraverseAllAspects(context, command);
            if (schemaUpdateDetected.value)
            {
                context.RestoreState(savedState);
                command = new _MarshallingInfoTraverseAspectCommand_94(context, EnsureFieldList(context
                                                                                                ));
                TraverseAllAspects(context, command);
            }
        }
示例#21
0
        public virtual void Activate(IReferenceActivationContext context)
        {
            UnmarshallingContext unmarshallingContext = (UnmarshallingContext)context;
            IDictionary          map = (IDictionary)unmarshallingContext.PersistentObject();

            map.Clear();
            KeyValueHandlerPair handlers = ReadKeyValueTypeHandlers(context, context);
            int elementCount             = context.ReadInt();

            for (int i = 0; i < elementCount; i++)
            {
                object key = unmarshallingContext.ReadFullyActivatedObjectForKeys(handlers._keyHandler
                                                                                  );
                if (key == null && !unmarshallingContext.LastReferenceReadWasReallyNull())
                {
                    continue;
                }
                object value = context.ReadObject(handlers._valueHandler);
                map[key] = value;
            }
        }
示例#22
0
        public object Get(Transaction trans, object onObject)
        {
            if (_containingClass == null)
            {
                return(null);
            }
            ObjectContainerBase container = Container();

            if (container == null)
            {
                return(null);
            }
            lock (container.Lock())
            {
                // FIXME: The following is not really transactional.
                //        This will work OK for normal C/S and for
                //        single local mode but the transaction will
                //        be wrong for MTOC.
                if (trans == null)
                {
                    trans = container.Transaction;
                }
                container.CheckClosed();
                ObjectReference @ref = trans.ReferenceForObject(onObject);
                if (@ref == null)
                {
                    return(null);
                }
                int id = @ref.GetID();
                if (id <= 0)
                {
                    return(null);
                }
                UnmarshallingContext context = new UnmarshallingContext(trans, @ref, Const4.AddToIdTree
                                                                        , false);
                context.ActivationDepth(new LegacyActivationDepth(1));
                return(context.ReadFieldValue(this));
            }
        }
示例#23
0
        public object FromXml(XStreamReader reader, UnmarshallingContext context)
        {
            IList result = (IList)DynamicInstanceBuilder.CreateInstance(context.currentTargetType);

            Type elementType = null;

            if (context.currentTargetType.HasElementType)
            {
                elementType = context.currentTargetType.GetElementType();
            }
            else if (context.currentTargetType.IsGenericType)
            {
                elementType = context.currentTargetType.GenericTypeArguments[0];
            }
            else
            {
                throw new Exception("Unable to get element type for: " + context.currentTargetType.ToString());
            }

            int count = reader.NoOfChildren();

            if (reader.MoveDown() && count > 0)
            {
                Type previousType = context.currentTargetType;
                context.currentTargetType = elementType;

                for (int i = 0; i < count; i++)
                {
                    result.Add(context.ConvertAnother(elementType));
                    Debug.Assert(reader.MoveNext() || result.Count == count);
                }
                reader.MoveUp();

                context.currentTargetType = previousType;
            }

            return(result);
        }
示例#24
0
        public virtual void AttemptUpdate(UnmarshallingContext context)
        {
            if (!Updating())
            {
                IncrementOffset(context, context);
                return;
            }
            int savedOffset = context.Offset();

            try
            {
                object toSet = context.Read(GetHandler());
                if (toSet != null)
                {
                    Set(context.PersistentObject(), toSet);
                }
            }
            catch (Exception)
            {
                // FIXME: COR-547 Diagnostics here please.
                context.Buffer().Seek(savedOffset);
                IncrementOffset(context, context);
            }
        }
示例#25
0
        private object WriteAndRead(object obj)
        {
            int             imaginativeID = 500;
            ObjectReference @ref          = new ObjectReference(ClassMetadataForObject(obj), imaginativeID
                                                                );

            @ref.SetObject(obj);
            MarshallingContext marshallingContext = new MarshallingContext(Trans(), @ref, Container
                                                                               ().UpdateDepthProvider().ForDepth(int.MaxValue), true);

            Handlers4.Write(@ref.ClassMetadata().TypeHandler(), marshallingContext, obj);
            Pointer4        pointer = marshallingContext.AllocateSlot();
            ByteArrayBuffer buffer  = marshallingContext.ToWriteBuffer(pointer);

            buffer.Seek(0);
            //        String str = new String(buffer._buffer);
            //        System.out.println(str);
            UnmarshallingContext unmarshallingContext = new UnmarshallingContext(Trans(), @ref
                                                                                 , Const4.AddToIdTree, false);

            unmarshallingContext.Buffer(buffer);
            unmarshallingContext.ActivationDepth(new LegacyActivationDepth(5));
            return(unmarshallingContext.Read());
        }
示例#26
0
 public object FromXml(XStreamReader reader, UnmarshallingContext context) {
     return Enum.Parse(Type.GetType(reader.GetAttribute(Attributes.AttributeType)), reader.GetValue());
 }
 public override void Activate(UnmarshallingContext context)
 {
     context.ObjectReference().ProduceVirtualAttributes();
     Instantiate1(context);
 }
 public _MarshallingInfoTraverseAspectCommand_63(UnmarshallingContext context, BooleanByRef
                                                 schemaUpdateDetected, IMarshallingInfo baseArg1) : base(baseArg1)
 {
     this.context = context;
     this.schemaUpdateDetected = schemaUpdateDetected;
 }
 public _MarshallingInfoTraverseAspectCommand_94(UnmarshallingContext context, IMarshallingInfo
                                                 baseArg1) : base(baseArg1)
 {
     this.context = context;
 }
示例#30
0
 public object FromXml(XStreamReader reader, UnmarshallingContext context) {
     return null;
 }
 internal override void InstantiateFields(UnmarshallingContext context)
 {
     throw new NotImplementedException();
 }
 public override object InstantiateTransient(UnmarshallingContext context)
 {
     return(Handlers4.ReadValueType(context, CorrectHandlerVersion(context)));
 }
示例#33
0
 public abstract void Activate(UnmarshallingContext context);
示例#34
0
 public object FromXml(XStreamReader reader, UnmarshallingContext context)
 {
     return(Enum.Parse(Type.GetType(reader.GetAttribute(Attributes.AttributeType)), reader.GetValue()));
 }