1 56 57 package org.objectstyle.cayenne.event; 58 59 import java.util.Map ; 60 61 import org.apache.commons.collections.map.ReferenceMap; 62 63 78 79 public class EventSubject extends Object { 80 81 private static Map _registeredSubjects = 83 new ReferenceMap(ReferenceMap.HARD, ReferenceMap.WEAK); 84 85 private String _fullyQualifiedSubjectName; 87 88 96 public static EventSubject getSubject(Class subjectOwner, String subjectName) { 97 if (subjectOwner == null) { 98 throw new IllegalArgumentException ("Owner class must not be null."); 99 } 100 101 if ((subjectName == null) || (subjectName.length() == 0)) { 102 throw new IllegalArgumentException ("Subject name must not be null or empty."); 103 } 104 105 String fullSubjectName = subjectOwner.getName() + "/" + subjectName; 106 EventSubject newSubject = (EventSubject) _registeredSubjects.get(fullSubjectName); 107 if (newSubject == null) { 108 newSubject = new EventSubject(fullSubjectName); 109 _registeredSubjects.put(newSubject.getSubjectName(), newSubject); 110 } 111 112 return newSubject; 113 } 114 115 118 private EventSubject() { 119 } 120 121 126 protected EventSubject(String fullSubjectName) { 127 super(); 128 _fullyQualifiedSubjectName = fullSubjectName; 129 } 130 131 public boolean equals(Object obj) { 132 if (obj instanceof EventSubject) { 133 return _fullyQualifiedSubjectName.equals( 134 ((EventSubject) obj).getSubjectName()); 135 } 136 137 return false; 138 } 139 140 public int hashCode() { 141 return (super.hashCode() ^ _fullyQualifiedSubjectName.hashCode()); 142 } 143 144 public String getSubjectName() { 145 return _fullyQualifiedSubjectName; 146 } 147 148 154 public String toString() { 155 StringBuffer buf = new StringBuffer (64); 156 157 buf.append("<"); 158 buf.append(this.getClass().getName()); 159 buf.append(" 0x"); 160 buf.append(Integer.toHexString(System.identityHashCode(this))); 161 buf.append("> "); 162 buf.append(_fullyQualifiedSubjectName); 163 164 return buf.toString(); 165 } 166 167 } 168 | Popular Tags |