1 22 package org.jboss.util.property; 23 24 import java.util.Properties ; 25 26 32 public class PropertyContainer 33 extends PropertyMap 34 { 35 36 protected String groupname = "<unknown>"; 37 38 43 public PropertyContainer(final Properties props) { 44 super(props); 45 } 46 47 52 public PropertyContainer(final String groupname) { 53 this(Property.getGroup(groupname)); 54 this.groupname = groupname; 55 } 56 57 62 public PropertyContainer(final Class type) { 63 this(type.getName()); 64 } 65 66 76 protected void bindField(final String name, final String propertyName) { 77 if (name == null || name.equals("")) 78 throw new IllegalArgumentException ("name"); 79 if (propertyName == null || propertyName.equals("")) 80 throw new IllegalArgumentException ("propertyName"); 81 82 addPropertyListener 83 (new FieldBoundPropertyListener(this, name, propertyName)); 84 } 85 86 95 protected void bindField(final String name) { 96 bindField(name, name); 97 } 98 99 109 protected void bindMethod(final String name, final String propertyName) { 110 if (name == null || name.equals("")) 111 throw new IllegalArgumentException ("name"); 112 if (propertyName == null || propertyName.equals("")) 113 throw new IllegalArgumentException ("propertyName"); 114 115 addPropertyListener (new MethodBoundPropertyListener(this, propertyName, name)); 117 } 118 119 128 protected void bindMethod(final String name) { 129 bindMethod(name, name); 130 } 131 132 private String makeName(final String name) { 133 return groupname + "." + name; 134 } 135 136 protected void throwException(final String name) 137 throws PropertyException 138 { 139 throw new PropertyException(makeName(name)); 140 } 141 142 protected void throwException(final String name, final String msg) 143 throws PropertyException 144 { 145 throw new PropertyException(makeName(name) + ": " + msg); 146 } 147 148 protected void throwException(final String name, final String msg, final Throwable nested) 149 throws PropertyException 150 { 151 throw new PropertyException(makeName(name) + ": " + msg, nested); 152 } 153 154 protected void throwException(final String name, final Throwable nested) 155 throws PropertyException 156 { 157 throw new PropertyException(makeName(name), nested); 158 } 159 } 160 | Popular Tags |