Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/15/09 12:29:13 (15 years ago)
Author:
epitzer
Message:

Namespace refactoring: rename formatters & decomposers -> primitive and composite serializers. (#603)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Persistence/3.3/Core/DeSerializer.cs

    r1795 r1823  
    88
    99namespace HeuristicLab.Persistence.Core {
    10 
    11   public class TypeLoader {
    12 
    13     public static Type Load(string typeNameString) {
    14       Type type;
    15       try {
    16         type = Type.GetType(typeNameString, true);
    17       } catch (Exception) {
    18         Logger.Warn(String.Format(
    19           "Cannot load type \"{0}\", falling back to partial name", typeNameString));
    20         try {
    21           TypeName typeName = TypeNameParser.Parse(typeNameString);
    22           Assembly a = Assembly.LoadWithPartialName(typeName.AssemblyName);
    23           type = a.GetType(typeName.ToString(false, false), true);
    24         } catch (Exception) {
    25           throw new PersistenceException(String.Format(
    26             "Could not load type \"{0}\"",
    27             typeNameString));
    28         }
    29         try {
    30           TypeName requestedTypeName = TypeNameParser.Parse(typeNameString);
    31           TypeName loadedTypeName = TypeNameParser.Parse(type.AssemblyQualifiedName);
    32           if (!requestedTypeName.IsCompatible(loadedTypeName))
    33             throw new PersistenceException(String.Format(
    34               "Serialized type is incompatible with available type: serialized: {0}, loaded: {1}",
    35               typeNameString,
    36               type.AssemblyQualifiedName));
    37           if (requestedTypeName.IsNewerThan(loadedTypeName))
    38             throw new PersistenceException(String.Format(
    39               "Serialized type is newer than available type: serialized: {0}, loaded: {1}",
    40               typeNameString,
    41               type.AssemblyQualifiedName));
    42         } catch (PersistenceException) {
    43           throw;
    44         } catch (Exception e) {
    45           Logger.Warn(String.Format(
    46             "Could not perform version check requested type was {0} while loaded type is {1}:",
    47             typeNameString,
    48             type.AssemblyQualifiedName),
    49             e);
    50         }
    51       }
    52       return type;
    53     }
    54 
    55   }
    5610
    5711  public class Deserializer {
     
    6620      private List<Tag> customValues;
    6721      private Type type;
    68       private IDecomposer decomposer;
     22      private ICompositeSerializer compositeSerializer;
    6923
    7024      public Midwife(object value) {
     
    7226      }
    7327
    74       public Midwife(Type type, IDecomposer decomposer, int? id) {
     28      public Midwife(Type type, ICompositeSerializer compositeSerializer, int? id) {
    7529        this.type = type;
    76         this.decomposer = decomposer;
     30        this.compositeSerializer = compositeSerializer;
    7731        this.Id = id;
    7832        MetaMode = false;
     
    8438        if (Obj != null)
    8539          throw new PersistenceException("object already instantiated");
    86         Obj = decomposer.CreateInstance(type, metaInfo);
     40        Obj = compositeSerializer.CreateInstance(type, metaInfo);
    8741      }
    8842
     
    9650
    9751      public void Populate() {
    98         decomposer.Populate(Obj, customValues, type);
     52        compositeSerializer.Populate(Obj, customValues, type);
    9953      }
    10054    }
     
    159113    private void CompositeStartHandler(BeginToken token) {
    160114      Type type = typeIds[(int)token.TypeId];
    161       IDecomposer decomposer = null;
     115      ICompositeSerializer compositeSerializer = null;
    162116      if (serializerMapping.ContainsKey(type))
    163         decomposer = serializerMapping[type] as IDecomposer;
    164       if (decomposer == null)
     117        compositeSerializer = serializerMapping[type] as ICompositeSerializer;
     118      if (compositeSerializer == null)
    165119        throw new PersistenceException(String.Format(
    166120          "No suitable method for deserialization of type \"{0}\" found.",
    167121          type.VersionInvariantName()));
    168       parentStack.Push(new Midwife(type, decomposer, token.Id));
     122      parentStack.Push(new Midwife(type, compositeSerializer, token.Id));
    169123    }
    170124
     
    180134    private void PrimitiveHandler(PrimitiveToken token) {
    181135      Type type = typeIds[(int)token.TypeId];
    182       object value = ((IFormatter)serializerMapping[type]).Parse(token.SerialData);
     136      object value = ((IPrimitiveSerializer)serializerMapping[type]).Parse(token.SerialData);
    183137      if (token.Id != null)
    184138        id2obj[(int)token.Id] = value;
Note: See TracChangeset for help on using the changeset viewer.