|
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.JsonProtocolModelParseException; |
|
8 import org.chromium.sdk.internal.protocolparser.JsonProtocolParseException; |
|
9 |
|
10 /** |
|
11 * An implementation of JsonSubtypeCondition* annotations. Basically it only holds all parameters |
|
12 * and delegates actual condition evaluating to {@link #conditionLogic}. |
|
13 */ |
|
14 class FieldCondition { |
|
15 private final String propertyName; |
|
16 private final QuickParser<?> quickParser; |
|
17 private final FieldConditionLogic conditionLogic; |
|
18 |
|
19 FieldCondition(String propertyName, QuickParser<?> quickParser, |
|
20 FieldConditionLogic conditionLogic) throws JsonProtocolModelParseException { |
|
21 if (conditionLogic.requiresQuickParser() && quickParser == null) { |
|
22 throw new JsonProtocolModelParseException( |
|
23 "The choose condition does not work with the type of " + propertyName); |
|
24 } |
|
25 this.propertyName = propertyName; |
|
26 this.quickParser = quickParser; |
|
27 this.conditionLogic = conditionLogic; |
|
28 } |
|
29 |
|
30 String getPropertyName() { |
|
31 return propertyName; |
|
32 } |
|
33 |
|
34 /** |
|
35 * @param hasValue whether field exists in JSON object (however its value may be null) |
|
36 * @param unparsedValue value of the field if hasValue is true or undefined otherwise |
|
37 */ |
|
38 boolean checkValue(boolean hasValue, Object unparsedValue) throws JsonProtocolParseException { |
|
39 return conditionLogic.checkValue(hasValue, unparsedValue, quickParser); |
|
40 } |
|
41 } |