KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Arrays JavaDoc;
19 import java.util.HashSet JavaDoc;
20 import java.util.Set JavaDoc;
21
22 /**
23  * Represents a single named deferred binding property that can answer with its
24  * value.
25  */

26 public class Property implements Comparable JavaDoc {
27
28   private String JavaDoc activeValue;
29
30   private Set JavaDoc knownValues = new HashSet JavaDoc();
31
32   private String JavaDoc[] knownValuesLazyArray;
33
34   private final String JavaDoc name;
35
36   private PropertyProvider provider;
37
38   public Property(String JavaDoc name) {
39     this.name = name;
40   }
41
42   public void addKnownValue(String JavaDoc knownValue) {
43     knownValues.add(knownValue);
44     knownValuesLazyArray = null;
45   }
46
47   public int compareTo(Object JavaDoc other) {
48     return name.compareTo(((Property) other).name);
49   }
50
51   /**
52    * Gets the property value or <code>null</code> if the property has no
53    * value.
54    */

55   public String JavaDoc getActiveValue() {
56     return activeValue;
57   }
58
59   /**
60    * Lists all the known values for this property in sorted order.
61    */

62   public String JavaDoc[] getKnownValues() {
63     if (knownValuesLazyArray == null) {
64       int n = knownValues.size();
65       knownValuesLazyArray = (String JavaDoc[]) knownValues.toArray(new String JavaDoc[n]);
66       Arrays.sort(knownValuesLazyArray);
67     }
68     return knownValuesLazyArray;
69   }
70
71   public String JavaDoc getName() {
72     return name;
73   }
74
75   public PropertyProvider getProvider() {
76     return provider;
77   }
78
79   public boolean isKnownValue(String JavaDoc value) {
80     return knownValues.contains(value);
81   }
82
83   /**
84    * Sets the property value, or clears it by specifying <code>null</code>.
85    */

86   public void setActiveValue(String JavaDoc value) {
87     this.activeValue = value;
88   }
89
90   public void setProvider(PropertyProvider provider) {
91     this.provider = provider;
92   }
93
94   public String JavaDoc toString() {
95     return name;
96   }
97 }
98
Popular Tags