KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > services > monitor > ProtocolKey


1 /*
2
3    Derby - Class org.apache.derby.impl.services.monitor.ProtocolKey
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.services.monitor;
23
24 import org.apache.derby.iapi.error.StandardException;
25 import org.apache.derby.iapi.services.monitor.Monitor;
26
27
28 /**
29     A class that represents a key for a module search.
30 */

31
32
33 class ProtocolKey {
34
35     /*
36     ** Fields.
37     */

38
39     /**
40         The class of the factory
41     */

42     protected Class JavaDoc factoryInterface;
43
44     /**
45         name of module, can be null
46     */

47     protected String JavaDoc identifier;
48
49     /*
50     ** Constructor
51     */

52
53     protected ProtocolKey(Class JavaDoc factoryInterface, String JavaDoc identifier)
54     {
55         super();
56         this.factoryInterface = factoryInterface;
57         this.identifier = identifier;
58     }
59
60     static ProtocolKey create(String JavaDoc className, String JavaDoc identifier) throws StandardException {
61
62         Throwable JavaDoc t;
63         try {
64             return new ProtocolKey(Class.forName(className), identifier);
65
66         } catch (ClassNotFoundException JavaDoc cnfe) {
67             t = cnfe;
68         } catch (IllegalArgumentException JavaDoc iae) {
69             t = iae;
70         }
71
72         throw Monitor.exceptionStartingModule(t);
73     }
74
75     /*
76     ** Methods required to use this key
77     */

78
79     protected Class JavaDoc getFactoryInterface() {
80         return factoryInterface;
81     }
82
83     protected String JavaDoc getIdentifier() {
84         return identifier;
85     }
86
87     /*
88     **
89     */

90
91     public int hashCode() {
92         return factoryInterface.hashCode() +
93             (identifier == null ? 0 : identifier.hashCode());
94     }
95
96     public boolean equals(Object JavaDoc other) {
97         if (other instanceof ProtocolKey) {
98             ProtocolKey otherKey = (ProtocolKey) other;
99
100             if (factoryInterface != otherKey.factoryInterface)
101                 return false;
102
103             if (identifier == null) {
104                 if (otherKey.identifier != null)
105                     return false;
106             } else {
107
108                 if (otherKey.identifier == null)
109                     return false;
110
111                 if (!identifier.equals(otherKey.identifier))
112                     return false;
113             }
114
115             return true;
116         }
117         return false;
118     }
119
120     public String JavaDoc toString() {
121
122         return factoryInterface.getName() + " (" + identifier + ")";
123     }
124 }
125
Popular Tags