Return the package name of the class. Sometimes there will be no Package object for the class, e.g., if the class loader hasn't created one (see Class.getPackage()). @param clazz the class source. @return the package name or an empty string.
(Class<?> clazz)
| 359 | * @return the package name or an empty string. |
| 360 | */ |
| 361 | private String packageOf(Class<?> clazz) { |
| 362 | Package p = clazz.getPackage(); |
| 363 | if (p != null) |
| 364 | return p.getName(); // hopefully the common case |
| 365 | String cname = clazz.getName(); |
| 366 | int i = cname.lastIndexOf('.'); |
| 367 | if (i > 0) |
| 368 | return cname.substring(0, i); |
| 369 | // no package name, now what? |
| 370 | return ""; |
| 371 | } |
| 372 | |
| 373 | /** |
| 374 | * A disadvantage of not being able to use Logger directly in Jakarta Mail |