01: /*****************************************************************************
02: * Java Plug-in Framework (JPF)
03: * Copyright (C) 2004-2007 Dmitry Olshansky
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: *****************************************************************************/package org.java.plugin.registry.xml;
19:
20: import org.apache.commons.logging.Log;
21: import org.apache.commons.logging.LogFactory;
22: import org.java.plugin.registry.Identity;
23: import org.java.plugin.registry.ManifestProcessingException;
24:
25: /**
26: * @version $Id$
27: */
28: abstract class IdentityImpl implements Identity {
29: /**
30: * Makes logging service available for descending classes.
31: */
32: protected final Log log = LogFactory.getLog(getClass());
33:
34: private final String id;
35:
36: protected IdentityImpl(final String anId)
37: throws ManifestProcessingException {
38: id = anId;
39: if ((id == null) || (id.trim().length() == 0)) {
40: throw new ManifestProcessingException(
41: PluginRegistryImpl.PACKAGE_NAME,
42: "manifestElementIdIsBlank"); //$NON-NLS-1$
43: }
44: }
45:
46: /**
47: * @see org.java.plugin.registry.Identity#getId()
48: */
49: public String getId() {
50: return id;
51: }
52:
53: protected abstract boolean isEqualTo(final Identity idt);
54:
55: /**
56: * @see java.lang.Object#equals(java.lang.Object)
57: */
58: @Override
59: public boolean equals(final Object obj) {
60: if (this == obj) {
61: return true;
62: }
63: if (!(obj instanceof Identity)) {
64: return false;
65: }
66: return isEqualTo((Identity) obj);
67: }
68:
69: private int hashCode = -1;
70:
71: /**
72: * @see java.lang.Object#hashCode()
73: */
74: @Override
75: public int hashCode() {
76: if (hashCode == -1) {
77: hashCode = getClass().hashCode() ^ getId().hashCode();
78: }
79: return hashCode;
80: }
81: }
|