1 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 componentClass, String propertyName) { 26 super(componentClass, propertyName); 27 } 28 29 public IntProperty displayName(String displayName) { 30 setDisplayName(displayName); 31 return this; 32 } 33 34 public IntProperty displayOnlyIf(PropertyType other, String value) { 35 setDisplayOnlyIf(other, value); 36 return this; 37 } 38 39 public IntProperty description(String description) { 40 setDescription(description); 41 return this; 42 } 43 44 public IntProperty consoleHelp(String 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 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 instanceName, PropertyMap props) { 90 int n; 91 boolean ok = true; 92 String value = props.getProperty(getPropertyName(), String.valueOf(defaultValue)); 93 try { 94 n = Integer.parseInt(value); 95 } catch (NumberFormatException 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 |