01: /*
02: * Copyright 2006 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16: package com.google.gwt.dev.cfg;
17:
18: import com.google.gwt.core.ext.BadPropertyValueException;
19: import com.google.gwt.core.ext.GeneratorContext;
20: import com.google.gwt.core.ext.PropertyOracle;
21: import com.google.gwt.core.ext.TreeLogger;
22: import com.google.gwt.core.ext.UnableToCompleteException;
23:
24: /**
25: * A deferred binding condition to determine whether a named property has a
26: * particular value.
27: */
28: public class ConditionWhenPropertyIs extends Condition {
29:
30: private final String propName;
31:
32: private final String value;
33:
34: public ConditionWhenPropertyIs(String propName, String value) {
35: this .propName = propName;
36: this .value = value;
37: }
38:
39: public String toString() {
40: return "<when-property-is name='" + propName + "' value='"
41: + value + "'/>";
42: }
43:
44: protected boolean doEval(TreeLogger logger,
45: GeneratorContext context, String testType)
46: throws UnableToCompleteException {
47: String testValue;
48: try {
49: PropertyOracle propertyOracle = context.getPropertyOracle();
50: testValue = propertyOracle.getPropertyValue(logger,
51: propName);
52: logger.log(TreeLogger.DEBUG, "Property value is '"
53: + testValue + "'", null);
54: if (testValue.equals(value)) {
55: return true;
56: } else {
57: return false;
58: }
59: } catch (BadPropertyValueException e) {
60: String msg = "Unable to get value of property '" + propName
61: + "'";
62: logger.log(TreeLogger.ERROR, msg, e);
63: throw new UnableToCompleteException();
64: }
65: }
66:
67: protected String getEvalAfterMessage(String testType, boolean result) {
68: if (result) {
69: return "Yes, the property value matched";
70: } else {
71: return "No, the value did not match";
72: }
73: }
74:
75: protected String getEvalBeforeMessage(String testType) {
76: return toString();
77: }
78: }
|