KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > dev > cfg > StaticPropertyOracle


1 /*
2  * Copyright 2006 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.PropertyOracle;
20 import com.google.gwt.core.ext.TreeLogger;
21
22 /**
23  * An implementation of {@link PropertyOracle} that maintains explicit property
24  * values, rather than computing them.
25  */

26 public class StaticPropertyOracle implements PropertyOracle {
27
28   private Property[] currentProps;
29
30   private String JavaDoc[] currentValues;
31
32   public StaticPropertyOracle() {
33   }
34
35   public String JavaDoc getPropertyValue(TreeLogger logger, String JavaDoc propertyName)
36       throws BadPropertyValueException {
37     // In practice there will probably be so few properties that a linear
38
// search is at least as fast as a map lookup by name would be.
39
// If that turns out not to be the case, the ctor could build a
40
// name-to-index map.
41
//
42
for (int i = 0; i < currentProps.length; i++) {
43       Property prop = currentProps[i];
44       if (prop.getName().equals(propertyName)) {
45         String JavaDoc value = currentValues[i];
46         if (prop.isKnownValue(value)) {
47           return value;
48         } else {
49           throw new BadPropertyValueException(propertyName, value);
50         }
51       }
52     }
53
54     // Didn't find it.
55
//
56
throw new BadPropertyValueException(propertyName);
57   }
58
59   public void setPropertyValues(Property[] props, String JavaDoc[] values) {
60     currentProps = props;
61     currentValues = values;
62   }
63 }
64
Popular Tags