1 23 24 29 30 package com.sun.jdo.api.persistence.model.jdo; 31 32 import java.util.ResourceBundle ; 33 import java.beans.PropertyChangeListener ; 34 import java.beans.VetoableChangeListener ; 35 import java.text.Collator ; 36 37 import com.sun.jdo.api.persistence.model.ModelException; 38 import com.sun.jdo.spi.persistence.utility.I18NHelper; 39 40 45 public abstract class PersistenceElement extends Object 46 implements PersistenceElementProperties, Comparable 47 { 48 49 private static final ResourceBundle _messages = I18NHelper.loadBundle( 50 "com.sun.jdo.api.persistence.model.Bundle", PersistenceElement.class.getClassLoader()); 52 53 54 Impl _impl; 55 56 59 public PersistenceElement () 60 { 61 this(null); 62 } 63 64 68 protected PersistenceElement (PersistenceElement.Impl impl) 69 { 70 setImpl(impl); 71 } 72 73 75 public final Impl getImpl () { return _impl; } 76 77 79 protected static final ResourceBundle getMessages () { return _messages; } 80 81 85 public final void addPropertyChangeListener (PropertyChangeListener l) 86 { 87 getImpl().addPropertyChangeListener(l); 88 } 89 90 94 public final void removePropertyChangeListener (PropertyChangeListener l) 95 { 96 getImpl().removePropertyChangeListener(l); 97 } 98 99 103 public final void addVetoableChangeListener (VetoableChangeListener l) 104 { 105 getImpl().addVetoableChangeListener(l); 106 } 107 108 112 public final void removeVetoableChangeListener (VetoableChangeListener l) 113 { 114 getImpl().removeVetoableChangeListener(l); 115 } 116 117 120 public String getName() { return getImpl().getName(); } 121 122 126 public void setName (String name) throws ModelException 127 { 128 getImpl().setName(name); 129 } 130 131 135 public String toString () { return getName(); } 136 137 143 public boolean equals(Object obj) 144 { 145 if (obj == null) 146 return false; 147 if (obj == this) 148 return true; 149 150 return (getClass() == obj.getClass()) && (compareTo(obj) == 0); 152 } 153 154 157 public int hashCode() 158 { 159 return (getName()==null) ? 0 : getName().hashCode(); 160 } 161 162 164 175 public int compareTo(Object o) 176 { 177 if (o == null) 179 throw new ClassCastException (); 180 if (o == this) 181 return 0; 182 183 String thisName = getName(); 184 String otherName = ((PersistenceElement)o).getName(); 186 if (thisName == null) 188 return (otherName == null) ? 0 : -1; 189 if (otherName == null) 191 return 1; 192 int ret = Collator.getInstance().compare(thisName, otherName); 195 if ((ret == 0) && (getClass() != o.getClass())) 198 ret = getClass().getName().compareTo(o.getClass().getName()); 199 return ret; 200 } 201 202 204 209 public void setImpl (PersistenceElement.Impl impl) 210 { 211 _impl = impl; 212 213 if (_impl != null) 214 getImpl().attachToElement(this); 215 } 216 217 220 public interface Impl 221 { 222 223 public static final int ADD = 1; 224 225 public static final int REMOVE = -1; 226 227 public static final int SET = 0; 228 229 236 public void attachToElement (PersistenceElement element); 237 238 241 public void addPropertyChangeListener (PropertyChangeListener l); 242 243 246 public void removePropertyChangeListener (PropertyChangeListener l); 247 248 251 public void addVetoableChangeListener (VetoableChangeListener l); 252 253 256 public void removeVetoableChangeListener (VetoableChangeListener l); 257 258 261 public String getName (); 262 263 267 public void setName (String name) throws ModelException; 268 } 269 } 270 | Popular Tags |