1 22 package org.jboss.mx.metadata; 23 24 import java.util.Map ; 25 import java.util.HashMap ; 26 27 import javax.management.MBeanInfo ; 28 import javax.management.NotCompliantMBeanException ; 29 30 41 public abstract class AbstractBuilder 42 implements MetaDataBuilder 43 { 44 45 47 50 protected Map properties = new HashMap (); 51 52 54 57 public AbstractBuilder() {} 58 59 public AbstractBuilder(Map properties) 60 { 61 this.properties = properties; 62 } 63 64 66 79 public boolean getBooleanProperty(String key) throws IllegalPropertyException 80 { 81 Object value = properties.get(key); 82 83 if (value == null) 84 throw new IllegalPropertyException("boolean property " + key + " does not exist"); 85 86 if (value instanceof String ) 87 { 88 String v = (String ) value; 89 if (v.equalsIgnoreCase("true")) 90 return true; 91 if (v.equalsIgnoreCase("false")) 92 return false; 93 if (v.equalsIgnoreCase("t")) 94 return true; 95 if (v.equalsIgnoreCase("f")) 96 return false; 97 98 throw new IllegalPropertyException("unknown string value '" + v + "' for boolean property"); 99 } 100 if (value instanceof Boolean ) 101 return ((Boolean )value).booleanValue(); 102 103 throw new IllegalPropertyException("illegal property type: " + value.getClass().getName()); 104 } 105 106 109 public String getStringProperty(String key) 110 { 111 return (String )properties.get(key); 112 } 113 114 115 117 120 public void setProperty(String key, Object value) 121 { 122 properties.put(key, value); 123 } 124 125 128 public Object getProperty(String key) 129 { 130 return properties.get(key); 131 } 132 133 public abstract MBeanInfo build() throws NotCompliantMBeanException ; 134 135 136 142 protected void setProperties(Map properties) 143 { 144 this.properties = new HashMap (properties); 145 } 146 147 150 protected Map getProperties() 151 { 152 return properties; 153 } 154 155 156 } 157 158 159 160 161 | Popular Tags |