001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.wicket.util.lang; 018 019import org.apache.wicket.util.io.IClusterable; 020 021/** 022 * A type-safe package name class since Package is unreliable (it's not a Package object, but rather 023 * a sometimes-available holder for versioning information). 024 * 025 * @author Jonathan Locke 026 */ 027public class PackageName implements IClusterable 028{ 029 private static final long serialVersionUID = 1L; 030 031 // The name of this package 032 private final String name; 033 034 /** 035 * @param c 036 * The class to get a PackageName object for 037 * @return The PackageName object 038 */ 039 public static PackageName forClass(final Class<?> c) 040 { 041 return new PackageName(Packages.extractPackageName(c)); 042 } 043 044 /** 045 * @param p 046 * The package to get a PackageName object for 047 * @return The package name 048 */ 049 public static PackageName forPackage(final Package p) 050 { 051 return new PackageName(p.getName()); 052 } 053 054 /** 055 * Constructor 056 * 057 * @param name 058 * The name of this package 059 */ 060 private PackageName(final String name) 061 { 062 this.name = name; 063 } 064 065 @Override 066 public boolean equals(final Object that) 067 { 068 if (that instanceof PackageName) 069 { 070 return ((PackageName)that).name.equals(name); 071 } 072 return false; 073 } 074 075 @Override 076 public int hashCode() 077 { 078 final int prime = 31; 079 int result = 1; 080 result = prime * result + ((name == null) ? 0 : name.hashCode()); 081 return result; 082 } 083 084 /** 085 * @return The fully qualified name of this package 086 */ 087 public String getName() 088 { 089 return name; 090 } 091 092 /** 093 * @see java.lang.Object#toString() 094 */ 095 @Override 096 public String toString() 097 { 098 return name; 099 } 100}