KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > idaremedia > antx > apis > Tk


1 /**
2  * $Id: Tk.java 180 2007-03-15 12:56:38Z ssmc $
3  * Copyright 2004 iDare Media, Inc. All rights reserved.
4  *
5  * Originally written by iDare Media, Inc. for release into the public domain. This
6  * library, source form and binary form, is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License (LGPL) as published
8  * by the Free Software Foundation; either version 2.1 of the License, or (at your option)
9  * any later version.<p>
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU LGPL for more details.<p>
14  *
15  * You should have received a copy of the GNU Lesser General Public License along with this
16  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite
17  * 330, Boston, MA 02111-1307 USA. The GNU LGPL can be found online at
18  * http://www.fsf.org/copyleft/lesser.html<p>
19  *
20  * This product has been influenced by several projects within the open-source community.
21  * The JWare developers wish to acknowledge the open-source community's support. For more
22  * information regarding the open-source products used within JWare, please visit the
23  * JWare website.
24  *----------------------------------------------------------------------------------------*
25  * WEBSITE- http://www.jware.info EMAIL- inquiries@jware.info
26  *----------------------------------------------------------------------------------------*
27  **/

28
29 package com.idaremedia.antx.apis;
30
31 import org.apache.tools.ant.Project;
32
33 /**
34  * Utilities used by implementation classes in this package. We are at the top of
35  * the interface food chain so we cannot depend on the standard AntX helpers package
36  * or any other.
37  *
38  * @since JWare/AntX 0.5
39  * @author ssmc, &copy;2004 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
40  * @version 0.5
41  * @.safety multiple
42  * @.group impl,helper
43  **/

44
45 final class Tk
46 {
47     /**
48      * Returns the leaf of a class's name. If the leaf partion of the
49      * class name includes the '$' character (as for inner or anonymous
50      * classes), all occurances of '$' are replaced by a '-'
51      * character.
52      * @param cls the class (non-null)
53      **/

54     static String JavaDoc leafNameFrom(Class JavaDoc cls)
55     {
56         if (cls==null) {
57             throw new IllegalArgumentException JavaDoc("leafFrom- NULL class");
58         }
59         String JavaDoc cn = cls.getName();
60         int i= cn.lastIndexOf('.');
61         if (i != -1) {
62             return cn.substring(i+1).replace('$','-');
63         }
64         return cn;
65     }
66
67
68
69     /**
70      * Returns a generic system identity string for given object.
71      * @param thing the thing to be stringified (can be <i>null</i>)
72      * @since JWare/AntX 0.4
73      **/

74     static String JavaDoc identityStringFrom(Object JavaDoc thing)
75     {
76         if (thing==null) {
77             return "null";
78         }
79         return thing.getClass().getName()
80             +"@"
81             +System.identityHashCode(thing);
82     }
83
84
85
86     /**
87      * Tries to obtain the result of an object's
88      * <span class="src">toString()</span> handling. If the object's
89      * handling generates an exception (often the case in Ant 1.6+)
90      * this method returns a generic system identity string.
91      * @param thing the thing to be stringified (can be <i>null</i>)
92      * @param P [optional] project for problem logging purposes
93      * @since JWare/AntX 0.4
94      **/

95     static String JavaDoc stringFrom(Object JavaDoc thing, Project P)
96     {
97         try {
98             return String.valueOf(thing);
99         } catch(RuntimeException JavaDoc rtX) {
100             if (P!=null) {
101                 P.log(rtX.getMessage(),Project.MSG_INFO);
102             }
103             return identityStringFrom(thing);
104         }
105     }
106
107     private Tk()
108     {
109     }
110 }
111
112 /* end-of-Tk.java */
Popular Tags