KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > annotations > internal > AnnotatedModuleLocation


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.hivemind.annotations.internal;
16
17 import java.lang.reflect.Method JavaDoc;
18
19 import org.apache.hivemind.Location;
20 import org.apache.hivemind.Resource;
21
22 /**
23  * Implementation of the {@link org.apache.hivemind.Location} interface.
24  * Uses a method name of a class as position.
25  *
26  * @author Achim Huegen
27  */

28 public final class AnnotatedModuleLocation implements Location
29 {
30     private Resource _resource;
31     private Class JavaDoc _moduleClass;
32     private Method JavaDoc _method;
33
34     public AnnotatedModuleLocation(Resource resource, Class JavaDoc moduleClass, Method JavaDoc method)
35     {
36         _resource = resource;
37         _moduleClass = moduleClass;
38         _method = method;
39     }
40     
41     public AnnotatedModuleLocation(Resource resource, Class JavaDoc moduleClass)
42     {
43         this(resource, moduleClass, null);
44     }
45
46     public Resource getResource()
47     {
48         return _resource;
49     }
50     
51     public Method JavaDoc getMethod()
52     {
53         return _method;
54     }
55
56     public Class JavaDoc getModuleClass()
57     {
58         return _moduleClass;
59     }
60
61     public int hashCode()
62     {
63         return ((237 + _resource.hashCode()) + 13 * _moduleClass.hashCode())
64             + (_method != null ? _method.hashCode() : 0);
65     }
66
67     public boolean equals(Object JavaDoc other)
68     {
69         if (!(other instanceof AnnotatedModuleLocation))
70             return false;
71
72         AnnotatedModuleLocation l = (AnnotatedModuleLocation) other;
73
74         if (_moduleClass.equals(l.getModuleClass()))
75             return false;
76         
77         if (_method.equals(l.getMethod()))
78             return false;
79
80         return _resource.equals(l.getResource());
81     }
82
83     /**
84      * Returns the position in format "class x, method y"
85      *
86      * @see org.apache.hivemind.Location#getPosition()
87      */

88     public String JavaDoc getPosition()
89     {
90         String JavaDoc result = "Class " + _moduleClass.getName();
91         if (_method != null) {
92             result += ", method " + _method.getName();
93         }
94         return result;
95     }
96     
97     public String JavaDoc toString()
98     {
99         return getPosition();
100     }
101
102  }
103
Popular Tags