KickJava   Java API By Example, From Geeks To Geeks.

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


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