org.chromium.sdk/src/org/chromium/sdk/internal/protocolparser/dynamicimpl/SubtypeCaster.java
changeset 2 e4420d2515f1
equal deleted inserted replaced
1:ef76fc2ac88c 2:e4420d2515f1
       
     1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
       
     2 // Use of this source code is governed by a BSD-style license that can be
       
     3 // found in the LICENSE file.
       
     4 
       
     5 package org.chromium.sdk.internal.protocolparser.dynamicimpl;
       
     6 
       
     7 import org.chromium.sdk.internal.protocolparser.JsonProtocolParseException;
       
     8 
       
     9 /**
       
    10  * An internal facility for navigating from object of base type to object of subtype. Used only
       
    11  * when user wants to parse JSON object as subtype.
       
    12  * It works in terms of {@link ObjectData}.
       
    13  */
       
    14 abstract class SubtypeCaster {
       
    15   private final Class<?> baseType;
       
    16   private final RefToType<?> subtypeRef;
       
    17 
       
    18   SubtypeCaster(Class<?> baseType, RefToType<?> subtypeRef) {
       
    19     this.baseType = baseType;
       
    20     this.subtypeRef = subtypeRef;
       
    21   }
       
    22 
       
    23   abstract ObjectData getSubtypeObjectData(ObjectData baseObjectData)
       
    24       throws JsonProtocolParseException;
       
    25 
       
    26   Class<?> getSubtype() {
       
    27     return subtypeRef.getTypeClass();
       
    28   }
       
    29 
       
    30   TypeHandler<?> getSubtypeHandler() {
       
    31     return subtypeRef.get();
       
    32   }
       
    33 
       
    34   Class<?> getBaseType() {
       
    35     return baseType;
       
    36   }
       
    37 }