01: /***
02: * jwma Java WebMail
03: * Copyright (c) 2000-2003 jwma team
04: *
05: * jwma is free software; you can distribute and use this source
06: * under the terms of the BSD-style license received along with
07: * the distribution.
08: ***/package dtw.webmail.util;
09:
10: /**
11: * Abstract class implementing the
12: * <tt>Identifiable</tt> interface.
13: *
14: * @author Dieter Wimberger
15: * @version 0.9.7 07/02/2003
16: */
17: public abstract class AbstractIdentifiable implements Identifiable {
18:
19: //instance attributes
20: private String m_UID;
21:
22: public AbstractIdentifiable() {
23: //ensure a unique identifier to be set
24: setUID("");
25: }//constructor
26:
27: public String getUID() {
28: return m_UID;
29: }//getUID
30:
31: /**
32: * Sets the unique identifier.
33: *
34: * @param uid the unique identifer as <tt>String</tt>.
35: */
36: public void setUID(String uid) {
37: if (uid == null || uid.length() == 0
38: || uid.indexOf(UID_PREFIX) == -1) {
39: m_UID = UID_PREFIX + UIDGenerator.getUID();
40: } else {
41: m_UID = uid;
42: }
43: }//setUID
44:
45: public boolean equals(Object o) {
46: if (o == null)
47: return false;
48: String oid = "";
49: if (o instanceof Identifiable) {
50: oid = ((Identifiable) o).getUID();
51: } else if (o instanceof String) {
52: oid = (String) o;
53: } else {
54: oid = o.toString();
55: }
56: return m_UID.equals(oid);
57: }//equals
58:
59: private static final String UID_PREFIX = "jwma-";
60:
61: }//interface Identifiable
|