KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > idaremedia > antx > tests > UncloneableNothingType


1 /**
2  * $Id: UncloneableNothingType.java 187 2007-03-25 17:59:16Z ssmc $
3  * Copyright 2007 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; version 2.1 of the License.
9  *
10  *----------------------------------------------------------------------------------------*
11  * WEBSITE- http://antxtras.sf.net/ EMAIL- jware[at]users[dot]sourceforge[dot]net
12  *----------------------------------------------------------------------------------------*
13  **/

14
15 package com.idaremedia.antx.tests;
16
17 import java.util.Iterator JavaDoc;
18 import java.util.Map JavaDoc;
19  
20 import org.apache.tools.ant.Project;
21
22 import com.idaremedia.antx.AntX;
23 import com.idaremedia.antx.helpers.Strings;
24 import com.idaremedia.antx.ownhelpers.ProjectDependentSkeleton;
25
26 /**
27  * Helper that does not come from Ant's data type (which implements Cloneable as of
28  * Ant 1.7).
29  *
30  * @since JWare/AntXtras 0.5.1
31  * @author ssmc, &copy;2007 <a HREF="http://antxtras.sf.net/">iDare&nbsp;Media,&nbsp;Inc.</a>
32  * @version 0.5.1
33  * @.safety single
34  * @.group impl,test,helper
35  **/

36
37 public final class UncloneableNothingType extends ProjectDependentSkeleton
38 {
39     /**
40      * Initializes a new uncloneable nothing type instance.
41      **/

42     public UncloneableNothingType()
43     {
44     }
45
46
47     /**
48      * Tries to return an interesting identifier for this type.
49      **/

50     public String JavaDoc getId()
51     {
52         return getClass().getName()+"@"+
53             String.valueOf(System.identityHashCode(this));
54     }
55
56
57
58     /**
59      * Tries to determine the (fully qualified) script name of
60      * this object. Will return "<span class="src">none</span>" if
61      * not able to determine proper name.
62      * @since JWare/AntX 0.4
63      * @.bug Does not work for two declarations of same type in
64      * different namespaces!
65      **/

66     public synchronized String JavaDoc getTypeName()
67     {
68         if (m_typeName==null) {
69             verifyInProject_("typeName");
70             Class JavaDoc myClass = getClass();
71             Iterator JavaDoc itr= getProject().getDataTypeDefinitions().
72                 entrySet().iterator();//lock|clone?
73
while (itr.hasNext()) {
74                 Map.Entry JavaDoc mE= (Map.Entry JavaDoc)itr.next();
75                 if (myClass==mE.getValue()) {
76                     m_typeName = (String JavaDoc)mE.getKey();
77                     break;
78                 }
79             }
80         }
81         return m_typeName==null ? Strings.NONE : m_typeName;
82     }
83
84
85
86     /** Sets this type's trigger attribute; some diagnostics
87         are logged for manual eyeballing. **/

88     public void setLabel(String JavaDoc label)
89     {
90         m_label = label;
91         StringBuffer JavaDoc sb = new StringBuffer JavaDoc(100);
92         sb.append(label);
93         sb.append(Strings.NL);
94         sb.append("Id: ");
95         sb.append(getId());
96         sb.append(Strings.NL);
97         sb.append("TypeName: ");
98         sb.append(getTypeName());
99         System.out.println(sb.toString());
100     }
101     
102
103
104     /**
105      * Lets AntX's lenient stringifier generate something useful.
106      */

107     public String JavaDoc toString()
108     {
109         return m_label;
110     }
111
112
113
114     /**
115      * Verifies we're in a live project (created from build
116      * process).
117      **/

118     protected final void verifyInProject_(String JavaDoc calr)
119     {
120         if (getProject()==null) {
121             String JavaDoc ermsg = AntX.uistrs().get("cv.verifyInP","UncloneableNothingType:",calr);
122             log(ermsg, Project.MSG_ERR);
123             throw new IllegalStateException JavaDoc(ermsg);
124         }
125     }
126
127
128     private String JavaDoc m_label="";
129     private String JavaDoc m_typeName;//NB: lazy-inited
130
}
131
132
133 /* end-of-UncloneableNothingType.java */
134
Popular Tags