KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > mx > loading > MBeanElement


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.mx.loading;
23
24 import java.util.*;
25
26 /**
27  * Dataholder class used with MBean file parsers. Contains the information
28  * that at minimum should allow the MBean loaded and registered to the MBean
29  * server.
30  *
31  * @see org.jboss.mx.loading.MBeanFileParser
32  * @see org.jboss.mx.loading.MLetParser
33  * @see org.jboss.mx.loading.XMLMBeanParser
34  *
35  * @author <a HREF="mailto:juha@jboss.org">Juha Lindfors</a>.
36  * @version $Revision: 37459 $
37  *
38  */

39 public class MBeanElement
40 {
41    // Attributes ----------------------------------------------------
42

43     // Constants -----------------------------------------------------
44

45     /**
46      * Property key for setting the boolean value 'delegateToCLR' for MLet
47      * MBeans (JMX 1.2)
48      */

49     public final static String JavaDoc MLET_DELEGATE_TO_CLR = "delegateToCLR";
50
51     /**
52      * Additional properties to be provided to the MBean installer/registration
53      * process. This map should contain properties that are not necessarily
54      * shared between all MBeans (for example, the delegateToCLR property for
55      * MLets).
56      */

57     private Map properties = new HashMap(2);
58
59    /**
60     * Fully qualified class name.
61     */

62    private String JavaDoc code = null;
63
64    /**
65     * Name of serialized MBean representation in the archive.
66     */

67    private String JavaDoc object = null;
68
69    /**
70     * Object name
71     */

72    private String JavaDoc name = null;
73
74    /**
75     * Overrides default codebase.
76     */

77    private String JavaDoc codebase = null;
78
79    /**
80     * MBean jars.
81     */

82    private ArrayList archives = new ArrayList();
83
84    /**
85     * spec only allows one version tag -- doesn't work very well with an archivelist.
86     */

87    private ArrayList versions = new ArrayList();
88
89    /**
90     * MBean constructor argument types.
91     */

92    private ArrayList argTypes = new ArrayList();
93
94    /**
95     * MBean constructor argument values.
96     */

97    private ArrayList argValues = new ArrayList();
98
99
100    // Public --------------------------------------------------------
101

102    /**
103     * Returns fully qualified class name of the MBean.
104     *
105     * @return class name or <tt>null</tt> if name not set
106     */

107    public String JavaDoc getCode()
108    {
109       return code;
110    }
111
112    /**
113     * Returns the name of a serialized MBean representation in the archive.
114     * Note that if the archive contains a file structure then the path to the
115     * serialized file is included in this string.
116     *
117     * @return serial file name or <tt>null</tt> if not set
118     */

119    public String JavaDoc getObject()
120    {
121       return object;
122    }
123
124    /**
125     * Returns the object name of the MBean.
126     *
127     * @return string representation of object name or <tt>null</tt> if not set
128     */

129    public String JavaDoc getName()
130    {
131       return name;
132    }
133
134    /**
135     * Returns MBean archives.
136     *
137     * @return a list of MBean Java archives. An empty list if archives is not set.
138     */

139    public List getArchives()
140    {
141       return archives;
142    }
143
144    /**
145     * Returns MBean versions.
146     *
147     * @return a list of MBean versions. An empty list if versions is not set.
148     */

149    public List getVersions()
150    {
151       return versions;
152    }
153
154    /**
155     * Returns MBean codebase URL.
156     *
157     * @return codebase or <tt>null</tt> if not set
158     */

159    public String JavaDoc getCodebase()
160    {
161       return codebase;
162    }
163
164    /**
165     * Sets the fully qualified class name of the MBean entry. The name is trimmed
166     * of quotes (") and additional equals (=) sign.
167     *
168     * @param code fully qualified class name of the MBean
169     */

170    public void setCode(String JavaDoc code)
171    {
172       this.code = trim(code);
173       if (this.code.endsWith(".class"))
174          this.code = this.code.substring(0, this.code.length() - 6);
175    }
176
177    /**
178     * Sets the name of the serialized MBean instance. Notice that if the archive
179     * contains a file structure its path must be included in the name. Tje name is
180     * trimmed of quotes (") and additional equals (=) sign.
181     *
182     * @param object file name and path in the archive
183     */

184    public void setObject(String JavaDoc object)
185    {
186       this.object = trim(object);
187    }
188
189    /**
190     * Sets the object name of the MBean. The name is trimmed of quotes (") and additional
191     * equals (=) sign.
192     *
193     * @param name string representation of an MBean object name
194     */

195    public void setName(String JavaDoc name)
196    {
197       this.name = trim(name);
198    }
199
200    /**
201     * Sets the code base for an MLET entry. The codebase is trimmed of quotes (") and
202     * additional equals (=) sign.
203     *
204     * @param url url string pointing to the codebase
205     */

206    public void setCodebase(String JavaDoc url)
207    {
208       this.codebase = trim(url);
209    }
210
211    public void setArchive(String JavaDoc archive)
212    {
213       archive = trim(archive);
214       StringTokenizer tokenizer = new StringTokenizer(archive, " ,");
215
216       while (tokenizer.hasMoreTokens())
217          archives.add(tokenizer.nextToken());
218    }
219
220    public void setVersion(String JavaDoc version)
221    {
222       version = trim(version);
223       StringTokenizer tokenizer = new StringTokenizer(version, " ,");
224
225       while (tokenizer.hasMoreTokens())
226          versions.add(tokenizer.nextToken());
227    }
228
229    public void addArg(String JavaDoc type, String JavaDoc value)
230    {
231       argTypes.add(trim(type));
232       argValues.add(trim(value));
233    }
234
235    public String JavaDoc[] getConstructorTypes()
236    {
237       return (String JavaDoc[])argTypes.toArray(new String JavaDoc[0]);
238    }
239
240    public String JavaDoc[] getConstructorValues()
241    {
242       return (String JavaDoc[])argValues.toArray(new String JavaDoc[0]);
243    }
244
245    // Private -------------------------------------------------------
246
private String JavaDoc trim(String JavaDoc str)
247    {
248       if (str == null)
249          return str;
250
251       // trim values that start with '="someValue"'
252
if (str.startsWith("="))
253          str = str.substring(1, str.length());
254
255       if (str.startsWith("\"") && str.endsWith("\""))
256          return str.substring(1, str.length() - 1);
257       else
258          return str;
259    }
260
261     public void setProperty(String JavaDoc key, Object JavaDoc value)
262     {
263        if (key == null || key.equals(""))
264           throw new IllegalArgumentException JavaDoc("null or empty string keys not allowed");
265        if (value == null)
266           throw new IllegalArgumentException JavaDoc("null values not allowed");
267
268        properties.put(key, value);
269     }
270
271     public Object JavaDoc getProperty(String JavaDoc key)
272     {
273        return properties.get(key);
274     }
275
276 }
277
278
279
280
281
Popular Tags