KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > java > plugin > registry > xml > IdentityImpl


1 /*****************************************************************************
2  * Java Plug-in Framework (JPF)
3  * Copyright (C) 2004-2006 Dmitry Olshansky
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
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  *****************************************************************************/

19 package org.java.plugin.registry.xml;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23 import org.java.plugin.registry.Identity;
24 import org.java.plugin.registry.ManifestProcessingException;
25
26 /**
27  * @version $Id: IdentityImpl.java,v 1.4 2006/08/26 15:14:08 ddimon Exp $
28  */

29 abstract class IdentityImpl implements Identity {
30     /**
31      * Makes logging service available for descending classes.
32      */

33     protected final Log log = LogFactory.getLog(getClass());
34
35     private final String JavaDoc id;
36
37     protected IdentityImpl(final String JavaDoc anId)
38             throws ManifestProcessingException {
39         id = anId;
40         if ((id == null) || (id.trim().length() == 0)) {
41             throw new ManifestProcessingException(
42                     PluginRegistryImpl.PACKAGE_NAME,
43                     "manifestElementIdIsBlank"); //$NON-NLS-1$
44
}
45     }
46
47     /**
48      * @see org.java.plugin.registry.Identity#getId()
49      */

50     public String JavaDoc getId() {
51         return id;
52     }
53     
54     protected abstract boolean isEqualTo(final Identity idt);
55     
56     /**
57      * @see java.lang.Object#equals(java.lang.Object)
58      */

59     public boolean equals(final Object JavaDoc 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     public int hashCode() {
75         if (hashCode == -1) {
76             hashCode = getClass().hashCode() ^ getId().hashCode();
77         }
78         return hashCode;
79     }
80 }
81
Popular Tags