KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > modules > jboss > jmx > JMXTagsHandler


1 /*
2  * Copyright (c) 2001, 2002 The XDoclet team
3  * All rights reserved.
4  */

5 package xdoclet.modules.jboss.jmx;
6
7 import java.util.Collections JavaDoc;
8 import java.util.HashMap JavaDoc;
9 import java.util.Map JavaDoc;
10 import java.util.Properties JavaDoc;
11
12 import xdoclet.TemplateSubTask;
13 import xdoclet.XDocletException;
14
15 import xdoclet.tagshandler.ClassTagsHandler;
16 import xdoclet.tagshandler.PropertyTagsHandler;
17
18 import xdoclet.template.TemplateException;
19
20 /**
21  * @author <a HREF="mailto:mnewcomb@users.sourceforge.net">Michael Newcomb</a>
22  * @created April 17, 2003
23  * @xdoclet.taghandler namespace="JMX"
24  */

25 public class JMXTagsHandler
26      extends ClassTagsHandler
27 {
28     private final static Map JavaDoc INTERNAL_TYPES;
29     static {
30         Map JavaDoc m = new HashMap JavaDoc();
31
32         m.put(Byte.TYPE.getName(), "B");
33         m.put(Short.TYPE.getName(), "S");
34         m.put(Integer.TYPE.getName(), "I");
35         m.put(Long.TYPE.getName(), "J");
36         m.put(Float.TYPE.getName(), "F");
37         m.put(Double.TYPE.getName(), "D");
38         m.put(Boolean.TYPE.getName(), "Z");
39         m.put(Character.TYPE.getName(), "C");
40
41         INTERNAL_TYPES = Collections.unmodifiableMap(m);
42     }
43
44
45     public String JavaDoc managedAttributeType()
46          throws XDocletException
47     {
48         Properties JavaDoc attributes = new Properties JavaDoc();
49
50         attributes.setProperty("tagName", "jmx.managed-attribute");
51
52         // lookup the PropertyTagsHandler
53
//
54
PropertyTagsHandler pth = null;
55
56         try {
57             pth = (PropertyTagsHandler) ((TemplateSubTask) getDocletContext().getActiveSubTask()).getEngine().getTagHandlerFor("Property");
58         }
59         catch (TemplateException te) {
60             throw new XDocletException(te, "there's some funky shiat going on!");
61         }
62
63         // get the normal type
64
//
65
String JavaDoc type = pth.propertyTypeWithTag(attributes);
66
67         // if it is an array, we need to re-arrange it into psuedo internal java
68
// type so java.lang.String[] will become [java.lang.String
69
//
70
int indexOfOpenBracket = type.indexOf('[');
71
72         if (indexOfOpenBracket != -1) {
73             String JavaDoc originalType = type;
74
75             type = originalType.substring(0, indexOfOpenBracket);
76
77             // replace primitives with their internal java type and surround classes
78
// with L<class>;
79
//
80
type =
81                 INTERNAL_TYPES.containsKey(type) ? (String JavaDoc) INTERNAL_TYPES.get(type) :
82                 ("L" + type + ";");
83
84             // add a '[' for each dimension
85
//
86
for (int index = indexOfOpenBracket; index != -1;
87                 index = originalType.indexOf('[', index + 1)) {
88                 type = '[' + type;
89             }
90         }
91
92         return type;
93     }
94 }
95
Popular Tags