01: /*
02: * $Id: PackageName.java 458405 2005-12-30 20:21:01Z jonl $ $Revision: 458405 $
03: * $Date: 2005-12-30 21:21:01 +0100 (Fri, 30 Dec 2005) $
04: *
05: * ==============================================================================
06: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
07: * use this file except in compliance with the License. You may obtain a copy of
08: * the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15: * License for the specific language governing permissions and limitations under
16: * the License.
17: */
18: package wicket.util.lang;
19:
20: /**
21: * A type-safe package name class since Package is unreliable (it's not a
22: * Package object, but rather a sometimes-available holder for versioning
23: * information).
24: *
25: * @author Jonathan Locke
26: */
27: public class PackageName {
28: // The name of this package
29: private final String name;
30:
31: /**
32: * @param c
33: * The class to get a PackageName object for
34: * @return The PackageName object
35: */
36: public static PackageName forClass(final Class c) {
37: return new PackageName(Packages.extractPackageName(c));
38: }
39:
40: /**
41: * @param p
42: * The package to get a PackageName object for
43: * @return The package name
44: */
45: public static PackageName forPackage(final Package p) {
46: return new PackageName(p.getName());
47: }
48:
49: /**
50: * Constructor
51: *
52: * @param name
53: * The name of this package
54: */
55: private PackageName(final String name) {
56: this .name = name;
57: }
58:
59: /**
60: * @see java.lang.Object#equals(java.lang.Object)
61: */
62: public boolean equals(Object that) {
63: if (that instanceof PackageName) {
64: return ((PackageName) that).name.equals(this .name);
65: }
66: return false;
67: }
68:
69: /**
70: * @return The fully qualified name of this package
71: */
72: public String getName() {
73: return name;
74: }
75:
76: /**
77: * @see java.lang.Object#toString()
78: */
79: public String toString() {
80: return name;
81: }
82: }
|