1 23 24 29 30 package com.sun.jdo.api.persistence.model.mapping.impl; 31 32 import java.beans.*; 33 import java.util.ResourceBundle ; 34 import java.text.Collator ; 35 36 import com.sun.jdo.api.persistence.model.ModelException; 37 import com.sun.jdo.api.persistence.model.ModelVetoException; 38 import com.sun.jdo.api.persistence.model.mapping.MappingElement; 39 import com.sun.jdo.spi.persistence.utility.I18NHelper; 40 41 46 public abstract class MappingElementImpl implements MappingElement 47 { 48 49 private static final ResourceBundle _messages = I18NHelper.loadBundle( 50 "com.sun.jdo.api.persistence.model.Bundle", MappingElementImpl.class.getClassLoader()); 52 53 54 private PropertyChangeSupport _support; 55 56 57 private transient VetoableChangeSupport _vetoableSupport; 58 59 String _name; 60 61 64 public MappingElementImpl () 65 { 66 this(null); 67 } 68 69 72 public MappingElementImpl (String name) 73 { 74 super(); 75 _name = name; 76 } 77 78 80 protected static final ResourceBundle getMessages () { return _messages; } 81 82 86 public String toString () { return getName(); } 87 88 94 public boolean equals(Object obj) 95 { 96 if (obj == null) 97 return false; 98 if (obj == this) 99 return true; 100 101 return (getClass() == obj.getClass()) && (compareTo(obj) == 0); 103 } 104 105 108 public int hashCode() 109 { 110 return (getName()==null) ? 0 : getName().hashCode(); 111 } 112 113 118 protected void firePropertyChange (String name, Object o, Object n) 119 { 120 if (_support != null) 121 _support.firePropertyChange(name, o, n); 122 } 123 124 130 protected void fireVetoableChange (String name, Object o, Object n) 131 throws PropertyVetoException 132 { 133 if (_vetoableSupport != null) 134 _vetoableSupport.fireVetoableChange(name, o, n); 135 } 136 137 139 142 public synchronized void addPropertyChangeListener 143 (PropertyChangeListener l) 144 { 145 if (_support == null) 146 { 147 synchronized(this) 148 { 149 if (_support == null) 151 _support = new PropertyChangeSupport(this); 152 } 153 } 154 155 _support.addPropertyChangeListener(l); 156 } 157 158 161 public void removePropertyChangeListener (PropertyChangeListener l) 162 { 163 if (_support != null) 164 _support.removePropertyChangeListener(l); 165 } 166 167 170 public synchronized void addVetoableChangeListener 171 (VetoableChangeListener l) 172 { 173 if (_vetoableSupport == null) 174 _vetoableSupport = new VetoableChangeSupport(this); 175 176 _vetoableSupport.addVetoableChangeListener(l); 177 } 178 179 182 public synchronized void removeVetoableChangeListener ( 183 VetoableChangeListener l) 184 { 185 if (_vetoableSupport != null) 186 _vetoableSupport.removeVetoableChangeListener(l); 187 } 188 189 192 public String getName () { return _name; } 193 194 198 public void setName (String name) throws ModelException 199 { 200 String old = getName(); 201 202 try 203 { 204 fireVetoableChange(PROP_NAME, old, name); 205 _name = name; 206 firePropertyChange(PROP_NAME, old, name); 207 } 208 catch (PropertyVetoException e) 209 { 210 throw new ModelVetoException(e); 211 } 212 } 213 214 216 227 public int compareTo(Object o) 228 { 229 if (o == null) 231 throw new ClassCastException (); 232 if (o == this) 233 return 0; 234 235 String thisName = getName(); 236 String otherName = ((MappingElementImpl)o).getName(); 238 if (thisName == null) 240 return (otherName == null) ? 0 : -1; 241 if (otherName == null) 243 return 1; 244 int ret = Collator.getInstance().compare(thisName, otherName); 247 if ((ret == 0) && (getClass() != o.getClass())) 250 ret = getClass().getName().compareTo(o.getClass().getName()); 251 return ret; 252 } 253 254 } 255 256 | Popular Tags |