KickJava   Java API By Example, From Geeks To Geeks.

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


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 IntProperty extends PropertyType {
21     private int defaultValue = 0;
22     private int minimumValue = 0;
23     private int maximumValue = Integer.MAX_VALUE;
24
25     public IntProperty(Class JavaDoc componentClass, String JavaDoc propertyName) {
26         super(componentClass, propertyName);
27     }
28
29     public IntProperty displayName(String JavaDoc displayName) {
30         setDisplayName(displayName);
31         return this;
32     }
33
34     public IntProperty displayOnlyIf(PropertyType other, String JavaDoc value) {
35         setDisplayOnlyIf(other, value);
36         return this;
37     }
38
39     public IntProperty description(String JavaDoc description) {
40         setDescription(description);
41         return this;
42     }
43
44     public IntProperty consoleHelp(String JavaDoc consoleHelp) {
45         setConsoleHelp(consoleHelp);
46         return this;
47     }
48
49     public IntProperty sortOrder(int sortOrder) {
50         setSortOrder(sortOrder);
51         return this;
52     }
53
54     public IntProperty defaultValue(int defaultValue) {
55         this.defaultValue = defaultValue;
56         return this;
57     }
58
59     public IntProperty minimumValue(int minimumValue) {
60         this.minimumValue = minimumValue;
61         return this;
62     }
63
64     public IntProperty maximumValue(int maximumValue) {
65         this.maximumValue = maximumValue;
66         return this;
67     }
68
69     public int getDefaultValue() {
70         return defaultValue;
71     }
72
73     public String JavaDoc getDefaultValueAsString() {
74         return String.valueOf(defaultValue);
75     }
76
77     public int getMinimumValue() {
78         return minimumValue;
79     }
80
81     public int getMaximumValue() {
82         return maximumValue;
83     }
84
85     public int getInt() {
86         return getInt(null, getComponentProperties());
87     }
88
89     public int getInt(String JavaDoc instanceName, PropertyMap props) {
90         int n;
91         boolean ok = true;
92         String JavaDoc value = props.getProperty(getPropertyName(), String.valueOf(defaultValue));
93         try {
94             n = Integer.parseInt(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