KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > interop > properties > DoubleProperty


1 /**
2  *
3  * Copyright 2004-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.geronimo.interop.properties;
19
20 public class DoubleProperty extends PropertyType {
21     private double defaultValue = 0;
22     private double minimumValue = 0;
23     private double maximumValue = Double.MAX_VALUE;
24
25     public DoubleProperty(Class JavaDoc componentClass, String JavaDoc propertyName) {
26         super(componentClass, propertyName);
27     }
28
29     public DoubleProperty displayName(String JavaDoc displayName) {
30         setDisplayName(displayName);
31         return this;
32     }
33
34     public DoubleProperty displayOnlyIf(PropertyType other, String JavaDoc value) {
35         setDisplayOnlyIf(other, value);
36         return this;
37     }
38
39     public DoubleProperty description(String JavaDoc description) {
40         setDescription(description);
41         return this;
42     }
43
44     public DoubleProperty consoleHelp(String JavaDoc consoleHelp) {
45         setConsoleHelp(consoleHelp);
46         return this;
47     }
48
49     public DoubleProperty sortOrder(int sortOrder) {
50         setSortOrder(sortOrder);
51         return this;
52     }
53
54     public DoubleProperty defaultValue(double defaultValue) {
55         this.defaultValue = defaultValue;
56         return this;
57     }
58
59     public DoubleProperty minimumValue(double minimumValue) {
60         this.minimumValue = minimumValue;
61         return this;
62     }
63
64     public DoubleProperty maximumValue(double maximumValue) {
65         this.maximumValue = maximumValue;
66         return this;
67     }
68
69     public double getDefaultValue() {
70         return defaultValue;
71     }
72
73     public String JavaDoc getDefaultValueAsString() {
74         return String.valueOf(defaultValue);
75     }
76
77     public double getMinimumValue() {
78         return minimumValue;
79     }
80
81     public double getMaximumValue() {
82         return maximumValue;
83     }
84
85     public double getDouble() {
86         return getDouble(null, getComponentProperties());
87     }
88
89     public double getDouble(String JavaDoc instanceName, PropertyMap props) {
90         double n;
91         boolean ok = true;
92         String JavaDoc value = props.getProperty(getPropertyName(), String.valueOf(defaultValue));
93         try {
94             n = Double.parseDouble(value);
95         } catch (NumberFormatException JavaDoc ex) {
96             ok = false;
97             n = 0;
98         }
99         if (n < minimumValue || n > maximumValue) {
100             ok = false;
101         }
102         if (!ok) {
103             badPropertyValue(instanceName, value, expectedNumberInRange(minimumValue, maximumValue));
104         }
105         logPropertyValue(instanceName, value, n == defaultValue);
106         return n;
107     }
108 }
109
Popular Tags