KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > management > loading > MLet


1 /*
2  * @(#)MLet.java 1.84 04/03/26
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.management.loading;
9
10
11 // Java import
12
import java.io.Externalizable JavaDoc;
13 import java.io.File JavaDoc;
14 import java.io.FileOutputStream JavaDoc;
15 import java.io.InputStream JavaDoc;
16 import java.io.IOException JavaDoc;
17 import java.io.ObjectInput JavaDoc;
18 import java.io.ObjectInputStream JavaDoc;
19 import java.io.ObjectOutput JavaDoc;
20 import java.lang.reflect.Constructor JavaDoc;
21 import java.net.MalformedURLException JavaDoc;
22 import java.net.URL JavaDoc;
23 import java.net.URLClassLoader JavaDoc;
24 import java.net.URLStreamHandlerFactory JavaDoc;
25 import java.security.AccessController JavaDoc;
26 import java.security.PrivilegedAction JavaDoc;
27 import java.util.Arrays JavaDoc;
28 import java.util.Enumeration JavaDoc;
29 import java.util.HashSet JavaDoc;
30 import java.util.Hashtable JavaDoc;
31 import java.util.Iterator JavaDoc;
32 import java.util.Map JavaDoc;
33 import java.util.Set JavaDoc;
34 import java.util.StringTokenizer JavaDoc;
35 import java.util.Vector JavaDoc;
36
37 import javax.management.ServiceNotFoundException JavaDoc;
38 import javax.management.ObjectInstance JavaDoc;
39 import javax.management.ObjectName JavaDoc;
40 import javax.management.MBeanServer JavaDoc;
41 import javax.management.ReflectionException JavaDoc;
42 import javax.management.InstanceAlreadyExistsException JavaDoc;
43 import javax.management.MBeanRegistrationException JavaDoc;
44 import javax.management.MBeanException JavaDoc;
45 import javax.management.NotCompliantMBeanException JavaDoc;
46 import javax.management.InstanceNotFoundException JavaDoc;
47 import javax.management.MBeanRegistration JavaDoc;
48 import javax.management.MBeanServerFactory JavaDoc;
49 import javax.management.loading.ClassLoaderRepository JavaDoc;
50
51 import com.sun.jmx.mbeanserver.GetPropertyAction;
52
53 import com.sun.jmx.defaults.ServiceName;
54 import com.sun.jmx.defaults.JmxProperties;
55
56 import com.sun.jmx.trace.Trace;
57
58
59 /**
60  * Allows you to instantiate and register one or several MBeans in the MBean server
61  * coming from a remote URL. M-let is a shortcut for management applet. The m-let service does this
62  * by loading an m-let text file, which specifies information on the MBeans to be obtained.
63  * The information on each MBean is specified in a single instance of a tag, called the MLET tag.
64  * The location of the m-let text file is specified by a URL.
65  * <p>
66  * The <CODE>MLET</CODE> tag has the following syntax:
67  * <p>
68  * &lt;<CODE>MLET</CODE><BR>
69  * <CODE>CODE = </CODE><VAR>class</VAR><CODE> | OBJECT = </CODE><VAR>serfile</VAR><BR>
70  * <CODE>ARCHIVE = &quot;</CODE><VAR>archiveList</VAR><CODE>&quot;</CODE><BR>
71  * <CODE>[CODEBASE = </CODE><VAR>codebaseURL</VAR><CODE>]</CODE><BR>
72  * <CODE>[NAME = </CODE><VAR>mbeanname</VAR><CODE>]</CODE><BR>
73  * <CODE>[VERSION = </CODE><VAR>version</VAR><CODE>]</CODE><BR>
74  * &gt;<BR>
75  * <CODE>[</CODE><VAR>arglist</VAR><CODE>]</CODE><BR>
76  * &lt;<CODE>/MLET</CODE>&gt;
77  * <p>
78  * where:
79  * <DL>
80  * <DT><CODE>CODE = </CODE><VAR>class</VAR></DT>
81  * <DD>
82  * This attribute specifies the full Java class name, including package name, of the MBean to be obtained.
83  * The compiled <CODE>.class</CODE> file of the MBean must be contained in one of the <CODE>.jar</CODE> files specified by the <CODE>ARCHIVE</CODE>
84  * attribute. Either <CODE>CODE</CODE> or <CODE>OBJECT</CODE> must be present.
85  * </DD>
86  * <DT><CODE>OBJECT = </CODE><VAR>serfile</VAR></DT>
87  * <DD>
88  * This attribute specifies the <CODE>.ser</CODE> file that contains a serialized representation of the MBean to be obtained.
89  * This file must be contained in one of the <CODE>.jar</CODE> files specified by the <CODE>ARCHIVE</CODE> attribute. If the <CODE>.jar</CODE> file contains a directory hierarchy, specify the path of the file within this hierarchy. Otherwise a match will not be found. Either <CODE>CODE</CODE> or <CODE>OBJECT</CODE> must be present.
90  * </DD>
91  * <DT><CODE>ARCHIVE = &quot;</CODE><VAR>archiveList</VAR><CODE>&quot;</CODE></DT>
92  * <DD>
93  * This mandatory attribute specifies one or more <CODE>.jar</CODE> files
94  * containing MBeans or other resources used by
95  * the MBean to be obtained. One of the <CODE>.jar</CODE> files must contain the file specified by the <CODE>CODE</CODE> or <CODE>OBJECT</CODE> attribute.
96  * If archivelist contains more than one file:
97  * <UL>
98  * <LI>Each file must be separated from the one that follows it by a comma (,).
99  * <LI><VAR>archivelist</VAR> must be enclosed in double quote marks.
100  * </UL>
101  * All <CODE>.jar</CODE> files in <VAR>archivelist</VAR> must be stored in the directory specified by the code base URL.
102  * </DD>
103  * <DT><CODE>CODEBASE = </CODE><VAR>codebaseURL</VAR></DT>
104  * <DD>
105  * This optional attribute specifies the code base URL of the MBean to be obtained. It identifies the directory that contains
106  * the <CODE>.jar</CODE> files specified by the <CODE>ARCHIVE</CODE> attribute. Specify this attribute only if the <CODE>.jar</CODE> files are not in the same
107  * directory as the m-let text file. If this attribute is not specified, the base URL of the m-let text file is used.
108  * </DD>
109  * <DT><CODE>NAME = </CODE><VAR>mbeanname</VAR></DT>
110  * <DD>
111  * This optional attribute specifies the object name to be assigned to the
112  * MBean instance when the m-let service registers it. If
113  * <VAR>mbeanname</VAR> starts with the colon character (:), the domain
114  * part of the object name is the domain of the agent. The m-let service
115  * invokes the <CODE>getDomain()</CODE> method of the Framework class to
116  * obtain this information.
117  * </DD>
118  * <DT><CODE>VERSION = </CODE><VAR>version</VAR></DT>
119  * <DD>
120  * This optional attribute specifies the version number of the MBean and
121  * associated <CODE>.jar</CODE> files to be obtained. This version number can
122  * be used to specify that the <CODE>.jar</CODE> files are loaded from the
123  * server to update those stored locally in the cache the next time the m-let
124  * text file is loaded. <VAR>version</VAR> must be a series of non-negative
125  * decimal integers each separated by a period from the one that precedes it.
126  * </DD>
127  * <DT><VAR>arglist</VAR></DT>
128  * <DD>
129  * This optional attribute specifies a list of one or more parameters for the
130  * MBean to be instantiated. This list describes the parameters to be passed the MBean's constructor.
131  * Use the following syntax to specify each item in
132  * <VAR>arglist</VAR>:</DD>
133  * <DL>
134  * <P>
135  * <DT>&lt;<CODE>ARG TYPE=</CODE><VAR>argumentType</VAR> <CODE>VALUE=</CODE><VAR>value</VAR>&gt;</DT>
136  * <P>
137  * <DD>where:</DD>
138  * <UL>
139  * <LI><VAR>argumentType</VAR> is the type of the argument that will be passed as parameter to the MBean's constructor.</UL>
140  * </DL>
141  * <P>The arguments' type in the argument list should be a Java primitive type or a Java basic type
142  * (<CODE>java.lang.Boolean, java.lang.Byte, java.lang.Short, java.lang.Long, java.lang.Integer, java.lang.Float, java.lang.Double, java.lang.String</CODE>).
143  * </DL>
144  *
145  * When an m-let text file is loaded, an
146  * instance of each MBean specified in the file is created and registered.
147  * <P>
148  * The m-let Service extends the <CODE>java.net.URLClassLoader</CODE> and can be used to load remote classes
149  * and jar files in the VM of the agent.
150  * <p><STRONG>Note - </STRONG> The <CODE>MLet</CODE> class loader uses the {@link javax.management.MBeanServerFactory#getClassLoaderRepository(javax.management.MBeanServer)}
151  * to load classes that could not be found in the loaded jar files.
152  *
153  * @since 1.5
154  */

155 public class MLet extends java.net.URLClassLoader JavaDoc
156      implements MLetMBean JavaDoc, MBeanRegistration JavaDoc, Externalizable JavaDoc {
157
158      private static final long serialVersionUID = 3636148327800330130L;
159
160      /*
161      * ------------------------------------------
162      * PRIVATE VARIABLES
163      * ------------------------------------------
164      */

165      
166      /**
167       * The reference to the MBean server.
168       * @serial
169       */

170      private MBeanServer JavaDoc server = null;
171
172      
173      /**
174       * The list of instances of the <CODE>MLetContant</CODE>
175       * class found at the specified URL.
176       * @serial
177       */

178      private Vector JavaDoc mletList = new Vector JavaDoc();
179      
180    
181      /**
182       * The directory used for storing libraries locally before they are loaded.
183       */

184      private String JavaDoc libraryDirectory;
185      
186      
187      /**
188       * The object name of the MLet Service.
189       * @serial
190       */

191      private ObjectName JavaDoc mletObjectName = null;
192      
193      /**
194       * The URLs of the MLet Service.
195       * @serial
196       */

197      private URL JavaDoc[] myUrls = null;
198
199      /**
200       * The name of this class to be used for trace messages
201       */

202      private static final String JavaDoc dbgTag = "MLet";
203
204      /**
205       * What ClassLoaderRepository, if any, to use if this MLet
206       * doesn't find an asked-for class.
207       */

208      private transient ClassLoaderRepository JavaDoc currentClr;
209
210      /**
211       * True if we should consult the {@link ClassLoaderRepository}
212       * when we do not find a class ourselves.
213       */

214      private transient boolean delegateToCLR;
215
216      /**
217       * objects maps from primitive classes to primitive object classes.
218       */

219      private Hashtable JavaDoc primitiveClasses = new Hashtable JavaDoc(8) ;
220      {
221      primitiveClasses.put(Boolean.TYPE.toString(), Boolean JavaDoc.class);
222      primitiveClasses.put(Character.TYPE.toString(), Character JavaDoc.class);
223      primitiveClasses.put(Byte.TYPE.toString(), Byte JavaDoc.class);
224      primitiveClasses.put(Short.TYPE.toString(), Short JavaDoc.class);
225      primitiveClasses.put(Integer.TYPE.toString(), Integer JavaDoc.class);
226      primitiveClasses.put(Long.TYPE.toString(), Long JavaDoc.class);
227      primitiveClasses.put(Float.TYPE.toString(), Float JavaDoc.class);
228      primitiveClasses.put(Double.TYPE.toString(), Double JavaDoc.class);
229     
230      }
231  
232
233      /*
234       * ------------------------------------------
235       * CONSTRUCTORS
236       * ------------------------------------------
237       */

238
239      /*
240       * The constructor stuff would be considerably simplified if our
241       * parent, URLClassLoader, specified that its one- and
242       * two-argument constructors were equivalent to its
243       * three-argument constructor with trailing null arguments. But
244       * it doesn't, which prevents us from having all the constructors
245       * but one call this(...args...).
246       */

247      
248      /**
249       * Constructs a new MLet using the default delegation parent ClassLoader.
250       */

251      public MLet() {
252      this(new URL JavaDoc[0]);
253      }
254
255      /**
256       * Constructs a new MLet for the specified URLs using the default
257       * delegation parent ClassLoader. The URLs will be searched in
258       * the order specified for classes and resources after first
259       * searching in the parent class loader.
260       *
261       * @param urls The URLs from which to load classes and resources.
262       *
263       */

264      public MLet(URL JavaDoc[] urls) {
265      this(urls, true);
266      }
267      
268      /**
269       * Constructs a new MLet for the given URLs. The URLs will be
270       * searched in the order specified for classes and resources
271       * after first searching in the specified parent class loader.
272       * The parent argument will be used as the parent class loader
273       * for delegation.
274       *
275       * @param urls The URLs from which to load classes and resources.
276       * @param parent The parent class loader for delegation.
277       *
278       */

279      public MLet(URL JavaDoc[] urls, ClassLoader JavaDoc parent) {
280      this(urls, parent, true);
281      }
282    
283      /**
284       * Constructs a new MLet for the specified URLs, parent class
285       * loader, and URLStreamHandlerFactory. The parent argument will
286       * be used as the parent class loader for delegation. The factory
287       * argument will be used as the stream handler factory to obtain
288       * protocol handlers when creating new URLs.
289       *
290       * @param urls The URLs from which to load classes and resources.
291       * @param parent The parent class loader for delegation.
292       * @param factory The URLStreamHandlerFactory to use when creating URLs.
293       *
294       */

295      public MLet(URL JavaDoc[] urls,
296          ClassLoader JavaDoc parent,
297          URLStreamHandlerFactory JavaDoc factory) {
298      this(urls, parent, factory, true);
299      }
300
301      /**
302       * Constructs a new MLet for the specified URLs using the default
303       * delegation parent ClassLoader. The URLs will be searched in
304       * the order specified for classes and resources after first
305       * searching in the parent class loader.
306       *
307       * @param urls The URLs from which to load classes and resources.
308       * @param delegateToCLR True if, when a class is not found in
309       * either the parent ClassLoader or the URLs, the MLet should delegate
310       * to its containing MBeanServer's {@link ClassLoaderRepository}.
311       *
312       * @since.unbundled JMX 1.2
313       */

314      public MLet(URL JavaDoc[] urls, boolean delegateToCLR) {
315      super(urls);
316      init(delegateToCLR);
317      }
318
319      /**
320       * Constructs a new MLet for the given URLs. The URLs will be
321       * searched in the order specified for classes and resources
322       * after first searching in the specified parent class loader.
323       * The parent argument will be used as the parent class loader
324       * for delegation.
325       *
326       * @param urls The URLs from which to load classes and resources.
327       * @param parent The parent class loader for delegation.
328       * @param delegateToCLR True if, when a class is not found in
329       * either the parent ClassLoader or the URLs, the MLet should delegate
330       * to its containing MBeanServer's {@link ClassLoaderRepository}.
331       *
332       * @since.unbundled JMX 1.2
333       */

334      public MLet(URL JavaDoc[] urls, ClassLoader JavaDoc parent, boolean delegateToCLR) {
335      super(urls, parent);
336      init(delegateToCLR);
337      }
338
339      /**
340       * Constructs a new MLet for the specified URLs, parent class
341       * loader, and URLStreamHandlerFactory. The parent argument will
342       * be used as the parent class loader for delegation. The factory
343       * argument will be used as the stream handler factory to obtain
344       * protocol handlers when creating new URLs.
345       *
346       * @param urls The URLs from which to load classes and resources.
347       * @param parent The parent class loader for delegation.
348       * @param factory The URLStreamHandlerFactory to use when creating URLs.
349       * @param delegateToCLR True if, when a class is not found in
350       * either the parent ClassLoader or the URLs, the MLet should delegate
351       * to its containing MBeanServer's {@link ClassLoaderRepository}.
352       *
353       * @since.unbundled JMX 1.2
354       */

355      public MLet(URL JavaDoc[] urls,
356          ClassLoader JavaDoc parent,
357          URLStreamHandlerFactory JavaDoc factory,
358          boolean delegateToCLR) {
359      super(urls, parent, factory);
360      init(delegateToCLR);
361      }
362
363      private void init(boolean delegateToCLR) {
364      this.delegateToCLR = delegateToCLR;
365
366      try {
367          libraryDirectory = System.getProperty(JmxProperties.MLET_LIB_DIR);
368          if (libraryDirectory == null)
369          libraryDirectory = getTmpDir();
370      } catch (SecurityException JavaDoc e) {
371          // OK : We don't do AccessController.doPrivileged, but we don't
372
// stop the user from creating an MLet just because they
373
// can't read the MLET_LIB_DIR or java.io.tmpdir properties
374
// either.
375
}
376      }
377
378      
379      /*
380       * ------------------------------------------
381       * PUBLIC METHODS
382       * ------------------------------------------
383       */

384      
385      
386      /**
387       * Appends the specified URL to the list of URLs to search for classes and
388       * resources.
389       */

390      public void addURL(URL JavaDoc url) {
391      if (!Arrays.asList(getURLs()).contains(url))
392          super.addURL(url);
393      }
394
395      /**
396       * Appends the specified URL to the list of URLs to search for classes and
397       * resources.
398       * @exception ServiceNotFoundException The specified URL is malformed.
399       */

400      public void addURL(String JavaDoc url) throws ServiceNotFoundException JavaDoc {
401      try {
402          URL JavaDoc ur = new URL JavaDoc(url);
403          if (!Arrays.asList(getURLs()).contains(ur))
404          super.addURL(ur);
405      } catch (MalformedURLException JavaDoc e) {
406          debug("addURL", url + ": Malformed URL. " + e);
407          throw new
408          ServiceNotFoundException JavaDoc("The specified URL is malformed");
409      }
410      }
411       
412      /** Returns the search path of URLs for loading classes and resources.
413       * This includes the original list of URLs specified to the constructor,
414       * along with any URLs subsequently appended by the addURL() method.
415       */

416      public URL JavaDoc[] getURLs() {
417      return super.getURLs();
418      }
419
420      /**
421       * Loads a text file containing MLET tags that define the MBeans to
422       * be added to the agent. The location of the text file is specified by
423       * a URL. The MBeans specified in the MLET file will be instantiated and
424       * registered by the MBean server.
425       *
426       * @param url The URL of the text file to be loaded as URL object.
427       *
428       * @return A set containing one entry per MLET tag in the m-let text file loaded.
429       * Each entry specifies either the ObjectInstance for the created MBean, or a throwable object
430       * (that is, an error or an exception) if the MBean could not be created.
431       *
432       * @exception ServiceNotFoundException One of the following errors has occurred: The m-let text file does
433       * not contain an MLET tag, the m-let text file is not found, a mandatory
434       * attribute of the MLET tag is not specified, the value of url is
435       * null.
436       * @exception IllegalStateException MLet MBean is not registered with an MBeanServer.
437       */

438      public Set JavaDoc getMBeansFromURL(URL JavaDoc url) throws ServiceNotFoundException JavaDoc {
439      if (url == null) {
440          throw new ServiceNotFoundException JavaDoc("The specified URL is null");
441      }
442      return getMBeansFromURL(url.toString());
443      }
444
445      /**
446       * Loads a text file containing MLET tags that define the MBeans to
447       * be added to the agent. The location of the text file is specified by
448       * a URL. The MBeans specified in the MLET file will be instantiated and
449       * registered by the MBean server.
450       *
451       * @param url The URL of the text file to be loaded as String object.
452       *
453       * @return A set containing one entry per MLET tag in the m-let text file loaded.
454       * Each entry specifies either the ObjectInstance for the created MBean, or a throwable object
455       * (that is, an error or an exception) if the MBean could not be created.
456       *
457       * @exception ServiceNotFoundException One of the following errors has occurred: The m-let text file does
458       * not contain an MLET tag, the m-let text file is not found, a mandatory
459       * attribute of the MLET tag is not specified, the url is malformed.
460       * @exception IllegalStateException MLet MBean is not registered with an MBeanServer.
461       *
462       */

463      public Set JavaDoc getMBeansFromURL(String JavaDoc url) throws ServiceNotFoundException JavaDoc {
464      
465      String JavaDoc mth = "getMBeansFromURL";
466
467      if (server == null) {
468          throw new IllegalStateException JavaDoc("This MLet MBean is not registered with an MBeanServer.");
469      }
470      // Parse arguments
471
if (url == null) {
472          if (isTraceOn()) {
473          trace(mth, "URL is null");
474          }
475          throw new ServiceNotFoundException JavaDoc("The specified URL is null");
476      } else {
477          url = url.replace(File.separatorChar,'/');
478      }
479      if (isTraceOn()) {
480          trace(mth, "<URL = " + url + ">");
481      }
482
483      // Parse URL
484
try {
485          MLetParser JavaDoc parser = new MLetParser JavaDoc();
486          mletList = parser.parseURL(url);
487      } catch (Exception JavaDoc e) {
488          final String JavaDoc msg =
489          "Problems while parsing URL [" + url +
490          "], got exception [" + e.toString() + "]";
491          if (isTraceOn()) {
492          trace(mth, msg);
493          }
494          ServiceNotFoundException JavaDoc snfe = new ServiceNotFoundException JavaDoc(msg);
495          /* Make a best effort to set the cause, but if we don't
496         succeed, too bad, you don't get that useful debugging
497         information. We jump through hoops here so that we can
498         work on platforms prior to J2SE 1.4 where the
499         Throwable.initCause method was introduced. If we change
500         the public interface of JMRuntimeException in a future
501         version we can add getCause() so we don't need to do this. */

502          try {
503          java.lang.reflect.Method JavaDoc initCause =
504              Throwable JavaDoc.class.getMethod("initCause",
505                            new Class JavaDoc[] {Throwable JavaDoc.class});
506          initCause.invoke(snfe, new Object JavaDoc[] {e});
507          } catch (Exception JavaDoc x) {
508          // OK: just means we won't have debugging info
509
}
510          throw snfe;
511      }
512
513      // Check that the list of MLets is not empty
514
if (mletList.size() == 0) {
515          if (isTraceOn()) {
516          trace(mth, "File " + url + " not found or MLET tag not defined in file");
517          }
518          throw new ServiceNotFoundException JavaDoc("File " + url + " not found or MLET tag not defined in file");
519      }
520      
521      // Walk through the list of MLets
522
HashSet JavaDoc mbeans = new HashSet JavaDoc();
523      for(Enumeration JavaDoc e = mletList.elements(); e.hasMoreElements(); ) {
524          // Get MLet item from list
525
MLetContent JavaDoc elmt = (MLetContent JavaDoc) e.nextElement();
526          // Initialise local variables
527
String JavaDoc code = elmt.getCode();
528          if (code != null) {
529          if (code.endsWith(".class")) {
530              code = code.substring(0, code.length() - 6);
531          }
532          }
533          String JavaDoc name = elmt.getName();
534          URL JavaDoc codebase = elmt.getCodeBase();
535          String JavaDoc version = elmt.getVersion();
536          String JavaDoc serName = elmt.getSerializedObject();
537          String JavaDoc jarFiles = elmt.getJarFiles();
538          URL JavaDoc documentBase = elmt.getDocumentBase();
539          Map JavaDoc attributes = elmt.getAttributes();
540          
541          // Display debug information
542
if (isTraceOn()) {
543          trace(mth, "MLET TAG = " + attributes.toString());
544          trace(mth, "CODEBASE = " + codebase);
545          trace(mth, "ARCHIVE = " + jarFiles);
546          trace(mth, "CODE = " + code);
547          trace(mth, "OBJECT = " + serName);
548          trace(mth, "NAME = " + name);
549          trace(mth, "VERSION = " + version);
550          trace(mth, "DOCUMENT URL = " + documentBase);
551          }
552          
553          // Load classes from JAR files
554
StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(jarFiles, ",", false);
555          while (st.hasMoreTokens()) {
556          String JavaDoc tok = st.nextToken().trim();
557          if (isTraceOn()) {
558              trace(mth, "Load archive for codebase <" + codebase + ">, file <" + tok + ">");
559          }
560          // Check which is the codebase to be used for loading the jar file.
561
// If we are using the base MLet implementation then it will be
562
// always the remote server but if the service has been extended in
563
// order to support caching and versioning then this method will
564
// return the appropriate one.
565
//
566
try {
567              codebase = check(version, codebase, tok, elmt);
568          } catch (Exception JavaDoc ex) {
569              if (isDebugOn()) {
570              debug(mth, "check returned exception: " + ex);
571              }
572              mbeans.add(ex);
573              continue;
574          }
575          
576          // Appends the specified JAR file URL to the list of URLs to search for classes and resources.
577
try {
578              if (!Arrays.asList(getURLs()).contains(new URL JavaDoc(codebase.toString() + tok))) {
579              addURL(codebase + tok);
580              }
581          } catch (MalformedURLException JavaDoc me) {
582              // OK : Ignore jar file if its name provokes the URL to be an invalid one.
583
}
584          
585          }
586          // Instantiate the class specified in the
587
// CODE or OBJECT section of the MLet tag
588
//
589
Object JavaDoc o = null;
590          ObjectInstance JavaDoc objInst = null;
591          
592          if (code != null && serName != null) {
593          if (isTraceOn()) {
594              trace(mth, "CODE and OBJECT parameters cannot be specified at the same time in tag MLET.");
595          }
596          mbeans.add(new Error JavaDoc("CODE and OBJECT parameters cannot be specified at the same time in tag MLET"));
597          continue;
598          }
599          if (code == null && serName == null) {
600          if (isTraceOn()) {
601              trace(mth, "Either CODE or OBJECT parameter must be specified in tag MLET.");
602          }
603          mbeans.add(new Error JavaDoc("Either CODE or OBJECT parameter must be specified in tag MLET"));
604          continue;
605          }
606          try {
607          if (code != null) {
608         
609              Vector JavaDoc signat = new Vector JavaDoc();
610              Vector JavaDoc pars = new Vector JavaDoc();
611
612              for (Iterator JavaDoc p = attributes.keySet().iterator(); p.hasNext(); ) {
613              String JavaDoc param_name = (String JavaDoc) p.next();
614              if (param_name.equals("types")) {
615                  signat = (Vector JavaDoc)elmt.getParameter(param_name);
616              }
617              if (param_name.equals("values")) {
618                  pars = (Vector JavaDoc)elmt.getParameter(param_name);
619              }
620              }
621
622              for (int i = 0; i < signat.size(); i++) {
623              pars.setElementAt(constructParameter((String JavaDoc)pars.elementAt(i), (String JavaDoc)signat.elementAt(i)), i);
624              }
625              if (signat.isEmpty()) {
626              if (name == null) {
627                  objInst = server.createMBean(code, null, mletObjectName);
628              } else {
629                  objInst = server.createMBean(code, new ObjectName JavaDoc(name), mletObjectName);
630              }
631              } else {
632              Object JavaDoc[] parms = pars.toArray();
633              String JavaDoc[] signature = new String JavaDoc[signat.size()];
634              for (int i=0;i<signature.length;i++) {
635                  signature[i] = (String JavaDoc) signat.elementAt(i);
636              }
637              if (isDebugOn()) {
638                  for (int i=0;i<signature.length;i++) {
639                  debug(mth, "Signature = " + signature[i]);
640                  debug(mth, "Params = " + parms[i].toString());
641                  }
642              }
643              if (name == null) {
644                  objInst = server.createMBean(code, null, mletObjectName, parms, signature);
645              } else {
646                  objInst = server.createMBean(code, new ObjectName JavaDoc(name), mletObjectName, parms, signature);
647              }
648              }
649          } else {
650              o = loadSerializedObject(codebase,serName);
651              if (name == null) {
652              server.registerMBean(o, null);
653              } else {
654              server.registerMBean(o, new ObjectName JavaDoc(name));
655              }
656              objInst = new ObjectInstance JavaDoc(name, o.getClass().getName());
657          }
658          } catch (ReflectionException JavaDoc ex) {
659          if (isTraceOn()) {
660              trace(mth, "ReflectionException: " + ex.getMessage());
661          }
662          mbeans.add(ex);
663          continue;
664          } catch (InstanceAlreadyExistsException JavaDoc ex) {
665          if (isTraceOn()) {
666              trace(mth, "InstanceAlreadyExistsException: " + ex.getMessage());
667          }
668          mbeans.add(ex);
669          continue;
670          } catch (MBeanRegistrationException JavaDoc ex) {
671          if (isTraceOn()) {
672              trace(mth, "MBeanRegistrationException: " + ex.getMessage());
673          }
674          mbeans.add(ex);
675          continue;
676          } catch (MBeanException JavaDoc ex) {
677          if (isTraceOn()) {
678              trace(mth, "MBeanException: " + ex.getMessage());
679          }
680          mbeans.add(ex);
681          continue;
682          } catch (NotCompliantMBeanException JavaDoc ex) {
683          if (isTraceOn()) {
684              trace(mth, "NotCompliantMBeanException: " + ex.getMessage());
685          }
686          mbeans.add(ex);
687          continue;
688          } catch (InstanceNotFoundException JavaDoc ex) {
689          if (isTraceOn()) {
690              trace(mth, "InstanceNotFoundException: " + ex.getMessage());
691          }
692          mbeans.add(ex);
693          continue;
694          } catch (IOException JavaDoc ex) {
695          if (isTraceOn()) {
696              trace(mth, "IOException: " + ex.getMessage());
697          }
698          mbeans.add(ex);
699          continue;
700          } catch (SecurityException JavaDoc ex) {
701          if (isTraceOn()) {
702              trace(mth, "SecurityException: " + ex.getMessage());
703          }
704          mbeans.add(ex);
705          continue;
706          } catch (Exception JavaDoc ex) {
707          if (isTraceOn()) {
708              trace(mth, "Exception: " + ex.getClass().getName() + ex.getMessage());
709          }
710          mbeans.add(ex);
711          continue;
712          } catch (Error JavaDoc ex) {
713          if (isTraceOn()) {
714              trace(mth, "Error: " + ex.getMessage());
715          }
716          mbeans.add(ex);
717          continue;
718          }
719          mbeans.add(objInst);
720      }
721      return mbeans;
722      }
723      
724      /**
725       * Gets the current directory used by the library loader for
726       * storing native libraries before they are loaded into memory.
727       *
728       * @return The current directory used by the library loader.
729       *
730       * @see #setLibraryDirectory
731       */

732      public String JavaDoc getLibraryDirectory() {
733      return libraryDirectory;
734      }
735      
736      /**
737       * Sets the directory used by the library loader for storing
738       * native libraries before they are loaded into memory.
739       *
740       * @param libdir The directory used by the library loader.
741       *
742       * @see #getLibraryDirectory
743       */

744      public void setLibraryDirectory(String JavaDoc libdir) {
745      libraryDirectory = libdir;
746      }
747           
748      /**
749       * Allows the m-let to perform any operations it needs before
750       * being registered in the MBean server. If the ObjectName is
751       * null, the m-let provides a default name for its registration
752       * &lt;defaultDomain&gt;:type=MLet
753       *
754       * @param server The MBean server in which the m-let will be registered.
755       * @param name The object name of the m-let.
756       *
757       * @return The name of the m-let registered.
758       *
759       * @exception java.lang.Exception This exception should be caught by the MBean server and re-thrown
760       *as an MBeanRegistrationException.
761       */

762      public ObjectName JavaDoc preRegister(MBeanServer JavaDoc server, ObjectName JavaDoc name) throws java.lang.Exception JavaDoc {
763      
764      // Initialise local pointer to the MBean server
765
setMBeanServer(server);
766      
767      // If no name is specified return a default name for the MLet
768
if (name == null) {
769          name = new ObjectName JavaDoc(server.getDefaultDomain() + ":" + ServiceName.MLET);
770      }
771
772     this.mletObjectName = name;
773     return this.mletObjectName;
774      }
775      
776      /**
777       * Allows the m-let to perform any operations needed after having been
778       * registered in the MBean server or after the registration has failed.
779       *
780       * @param registrationDone Indicates whether or not the m-let has been successfully registered in
781       * the MBean server. The value false means that either the registration phase
782       * has failed.
783       *
784       */

785      public void postRegister (Boolean JavaDoc registrationDone) {
786      }
787           
788      /**
789       * Allows the m-let to perform any operations it needs before being unregistered
790       * by the MBean server.
791       *
792       * @exception java.langException This exception should be caught by the MBean server and re-thrown
793       * as an MBeanRegistrationException.
794       */

795      public void preDeregister() throws java.lang.Exception JavaDoc {
796      }
797      
798      
799      /**
800       * Allows the m-let to perform any operations needed after having been
801       * unregistered in the MBean server.
802       */

803      public void postDeregister() {
804      }
805
806      /**
807       * <p>Save this MLet's contents to the given {@link ObjectOutput}.
808       * Not all implementations support this method. Those that do not
809       * throw {@link UnsupportedOperationException}. A subclass may
810       * override this method to support it or to change the format of
811       * the written data.</p>
812       *
813       * <p>The format of the written data is not specified, but if
814       * an implementation supports {@link #writeExternal} it must
815       * also support {@link #readExternal} in such a way that what is
816       * written by the former can be read by the latter.</p>
817       *
818       * @param out The object output stream to write to.
819       *
820       * @exception IOException If a problem occurred while writing.
821       * @exception UnsupportedOperationException If this
822       * implementation does not support this operation.
823       */

824      public void writeExternal(ObjectOutput JavaDoc out)
825          throws IOException JavaDoc, UnsupportedOperationException JavaDoc {
826      throw new UnsupportedOperationException JavaDoc("MLet.writeExternal");
827      }
828
829      /**
830       * <p>Restore this MLet's contents from the given {@link ObjectInput}.
831       * Not all implementations support this method. Those that do not
832       * throw {@link UnsupportedOperationException}. A subclass may
833       * override this method to support it or to change the format of
834       * the read data.</p>
835       *
836       * <p>The format of the read data is not specified, but if an
837       * implementation supports {@link #readExternal} it must also
838       * support {@link #writeExternal} in such a way that what is
839       * written by the latter can be read by the former.</p>
840       *
841       * @param in The object input stream to read from.
842       *
843       * @exception IOException if a problem occurred while reading.
844       * @exception ClassNotFoundException if the class for the object
845       * being restored cannot be found.
846       * @exception UnsupportedOperationException if this
847       * implementation does not support this operation.
848       */

849      public void readExternal(ObjectInput JavaDoc in)
850          throws IOException JavaDoc, ClassNotFoundException JavaDoc,
851             UnsupportedOperationException JavaDoc {
852      throw new UnsupportedOperationException JavaDoc("MLet.readExternal");
853      }
854
855      /*
856       * ------------------------------------------
857       * PACKAGE METHODS
858       * ------------------------------------------
859       */

860
861      /**
862       * <p>Load a class, using the given {@link ClassLoaderRepository} if
863       * the class is not found in this MLet's URLs. The given
864       * ClassLoaderRepository can be null, in which case a {@link
865       * ClassNotFoundException} occurs immediately if the class is not
866       * found in this MLet's URLs.</p>
867       *
868       * @param name The name of the class we want to load.
869       * @param clr The ClassLoaderRepository that will be used to search
870       * for the given class, if it is not found in this
871       * ClassLoader. May be null.
872       * @return The resulting Class object.
873       * @exception ClassNotFoundException The specified class could not be
874       * found in this ClassLoader nor in the given
875       * ClassLoaderRepository.
876       *
877       * @since.unbundled JMX 1.1
878       */

879      public synchronized Class JavaDoc loadClass(String JavaDoc name,
880                      ClassLoaderRepository JavaDoc clr)
881           throws ClassNotFoundException JavaDoc {
882      final ClassLoaderRepository JavaDoc before=currentClr;
883      try {
884          currentClr = clr;
885          final Class JavaDoc c = loadClass(name);
886          return c;
887      } finally {
888          currentClr = before;
889      }
890      }
891
892      /*
893       * ------------------------------------------
894       * PROTECTED METHODS
895       * ------------------------------------------
896       */

897      
898      /**
899       * This is the main method for class loaders that is being redefined.
900       *
901       * @param name The name of the class.
902       *
903       * @return The resulting Class object.
904       *
905       * @exception ClassNotFoundException The specified class could not be
906       * found.
907       */

908      protected Class JavaDoc findClass(String JavaDoc name) throws ClassNotFoundException JavaDoc {
909      /* currentClr is context sensitive - used to avoid recursion
910         in the class loader repository. (This is no longer
911         necessary with the new CLR semantics but is kept for
912         compatibility with code that might have called the
913         two-parameter loadClass explicitly.) */

914      return findClass(name, currentClr);
915      }
916
917      /**
918       * Called by {@link MLet#findClass(java.lang.String)}.
919       *
920       * @param name The name of the class that we want to load/find.
921       * @param clr The ClassLoaderRepository that can be used to search
922       * for the given class. This parameter is
923       * <code>null</code> when called from within the
924       * {@link javax.management.MBeanServerFactory#getClassLoaderRepository(javax.management.MBeanServer) Class Loader Repository}.
925       * @exception ClassNotFoundException The specified class could not be
926       * found.
927       *
928       **/

929      Class JavaDoc findClass(String JavaDoc name, ClassLoaderRepository JavaDoc clr)
930      throws ClassNotFoundException JavaDoc {
931      Class JavaDoc c = null;
932      if (isTraceOn()) {
933          trace("findClass", name);
934      }
935      // Try looking in the JAR:
936
try {
937          c = super.findClass(name);
938          if (isTraceOn()) {
939          trace("findClass", "Class "+name+
940                " loaded through mlet classloader");
941          }
942      } catch (ClassNotFoundException JavaDoc e) {
943          // Drop through
944
debug("findClass", "Class "+name+ " not found locally.");
945      }
946      // if we are not called from the ClassLoaderRepository
947
if (c == null && delegateToCLR && clr != null) {
948          // Try the classloader repository:
949
//
950
try {
951          debug("findClass", "Class "+name+": looking in CLR");
952          c = clr.loadClassBefore(this, name);
953          // The loadClassBefore method never returns null.
954
// If the class is not found we get an exception.
955
if (isTraceOn()) {
956              trace("findClass", "Class "+name+
957                " loaded through the default classloader repository");
958          }
959          } catch (ClassNotFoundException JavaDoc e) {
960          debug("findClass", "Class "+name+ " not found in CLR.");
961          // Drop through
962
}
963      }
964      if (c == null) {
965          debug("findClass","Failed to load class " + name);
966          throw new ClassNotFoundException JavaDoc(name);
967          }
968      return c;
969      }
970
971      /**
972       * Returns the absolute path name of a native library. The VM invokes this method to locate the native
973       * libraries that belong to classes loaded with this class loader. Libraries are searched in the JAR files
974       * using first just the native library name and if not found the native library name together with the
975       * architecture-specific path name (<code>OSName/OSArch/OSVersion/lib/nativelibname</code>), i.e.
976       * <p>
977       * the library stat on Solaris SPARC 5.7 will be searched in the JAR file as:
978       * <OL>
979       * <LI>libstat.so
980       * <LI>SunOS/sparc/5.7/lib/libstat.so
981       * </OL>
982       * the library stat on Windows NT 4.0 will be searched in the JAR file as:
983       * <OL>
984       * <LI>stat.dll
985       * <LI>WindowsNT/x86/4.0/lib/stat.dll
986       * </OL>
987       * <p>
988       * If this method returns <code>null</code>, i.e. the libraries were not found in any of the JAR
989       * files loaded with this class loader, the VM searches the library along the path specified as
990       * the <code>java.library.path</code> property.
991       *
992       * @param libname The library name.
993       *
994       * @return The absolute path of the native library.
995       */

996      protected String JavaDoc findLibrary(String JavaDoc libname) {
997      
998      String JavaDoc abs_path;
999      String JavaDoc mth = "findLibrary";
1000     
1001     // Get the platform-specific string representing a native library.
1002
//
1003
String JavaDoc nativelibname = System.mapLibraryName(libname);
1004     
1005     //
1006
// See if the native library is accessible as a resource through the JAR file.
1007
//
1008
if (isTraceOn()) {
1009         trace(mth, "Search " + libname + " in all JAR files.");
1010     }
1011     
1012     // First try to locate the library in the JAR file using only the native library name.
1013
// e.g. if user requested a load for "foo" on Solaris SPARC 5.7 we try to load
1014
// "libfoo.so" from the JAR file.
1015
//
1016
if (isTraceOn()) {
1017         trace(mth, "loadLibraryAsResource(" + nativelibname + ")");
1018     }
1019     abs_path = loadLibraryAsResource(nativelibname);
1020     if (abs_path != null) {
1021         if (isTraceOn()) {
1022         trace(mth, nativelibname + " loaded " + "absolute path = " + abs_path);
1023         }
1024         return abs_path;
1025     }
1026
1027     // Next try to locate it using the native library name and the architecture-specific path name.
1028
// e.g. if user requested a load for "foo" on Solaris SPARC 5.7 we try to load
1029
// "SunOS/sparc/5.7/lib/libfoo.so" from the JAR file.
1030
//
1031
nativelibname = removeSpace(System.getProperty("os.name")) + File.separator +
1032         removeSpace(System.getProperty("os.arch")) + File.separator +
1033         removeSpace(System.getProperty("os.version")) + File.separator +
1034         "lib" + File.separator + nativelibname;
1035     if (isTraceOn()) {
1036         trace(mth, "loadLibraryAsResource(" + nativelibname + ")");
1037     }
1038     
1039     abs_path = loadLibraryAsResource(nativelibname);
1040     if (abs_path != null) {
1041         if (isTraceOn()) {
1042         trace(mth, nativelibname + " loaded " + "absolute path = " + abs_path);
1043         }
1044         return abs_path;
1045     }
1046     
1047     //
1048
// All paths exhausted, library not found in JAR file.
1049
//
1050

1051     if (isTraceOn()) {
1052         trace(mth, libname + " not found in any JAR file.");
1053         trace(mth, "Search " + libname + " along the path specified as the java.library.path property.");
1054     }
1055     
1056     
1057     // Let the VM search the library along the path
1058
// specified as the java.library.path property.
1059
//
1060
return null;
1061     }
1062
1063
1064     /*
1065      * ------------------------------------------
1066      * PRIVATE METHODS
1067      * ------------------------------------------
1068      */

1069
1070     private String JavaDoc getTmpDir() {
1071     // JDK 1.4
1072
String JavaDoc tmpDir = (String JavaDoc)System.getProperty("java.io.tmpdir");
1073     if (tmpDir != null) return tmpDir;
1074
1075     // JDK < 1.4
1076
File JavaDoc tmpFile = null;
1077     try {
1078         // Try to guess the system temporary dir...
1079
tmpFile = File.createTempFile("tmp","jmx");
1080         if (tmpFile == null) return null;
1081         final File JavaDoc tmpDirFile = tmpFile.getParentFile();
1082         if (tmpDirFile == null) return null;
1083         return tmpDirFile.getAbsolutePath();
1084     } catch (Exception JavaDoc x) {
1085         debug("getTmpDir","Failed to determine system temporary dir.");
1086         return null;
1087     } finally {
1088         // Cleanup ...
1089
if (tmpFile!=null) try {
1090         tmpFile.delete();
1091         } catch (Exception JavaDoc x) {
1092         debug("getTmpDir","Failed to delete temporary file: " + x.getMessage());
1093     }
1094     }
1095     }
1096
1097     /**
1098      * Search the specified native library in any of the JAR files loaded by this classloader.
1099      * If the library is found copy it into the library directory and return the absolute path.
1100      * If the library is not found then return null.
1101      */

1102     private synchronized String JavaDoc loadLibraryAsResource(String JavaDoc libname) {
1103     try {
1104         InputStream JavaDoc is = getResourceAsStream(libname.replace(File.separatorChar,'/'));
1105         if (is != null) {
1106         File JavaDoc directory = new File JavaDoc(libraryDirectory);
1107         directory.mkdirs();
1108         File JavaDoc file = File.createTempFile(libname + ".", null, directory);
1109         file.deleteOnExit();
1110         FileOutputStream JavaDoc fileOutput = new FileOutputStream JavaDoc(file);
1111         int c;
1112         while ((c = is.read()) != -1) {
1113             fileOutput.write(c);
1114         }
1115         is.close();
1116         fileOutput.close();
1117         if (file.exists()) {
1118             return file.getAbsolutePath();
1119         }
1120         }
1121     } catch (Exception JavaDoc e) {
1122         debug("loadLibraryAsResource",libname+
1123           ": Failed to load library. " + e);
1124         return null;
1125     }
1126     return null;
1127     }
1128     
1129   /**
1130    * Removes any white space from a string. This is used to
1131    * convert strings such as "Windows NT" to "WindowsNT".
1132    */

1133     private String JavaDoc removeSpace(String JavaDoc s) {
1134     s = s.trim();
1135     int j = s.indexOf(' ');
1136     if (j == -1) {
1137         return s;
1138     }
1139     String JavaDoc temp = "";
1140     int k = 0;
1141     while (j != -1) {
1142         s = s.substring(k);
1143         j = s.indexOf(' ');
1144         if (j != -1) {
1145         temp = temp + s.substring(0, j);
1146         } else {
1147         temp = temp + s.substring(0);
1148         }
1149         k = j + 1;
1150     }
1151     return temp;
1152     }
1153
1154     /**
1155      * <p>This method is to be overridden when extending this service to
1156      * support caching and versioning. It is called from {@link
1157      * #getMBeansFromURL getMBeansFromURL} when the version,
1158      * codebase, and jarfile have been extracted from the MLet file,
1159      * and can be used to verify that it is all right to load the
1160      * given MBean, or to replace the given URL with a different one.</p>
1161      *
1162      * <p>The default implementation of this method returns
1163      * <code>codebase</code> unchanged.</p>
1164      *
1165      * @param version The version number of the <CODE>.jar</CODE>
1166      * file stored locally.
1167      * @param codebase The base URL of the remote <CODE>.jar</CODE> file.
1168      * @param jarfile The name of the <CODE>.jar</CODE> file to be loaded.
1169      * @param mlet The <CODE>MLetContent</CODE> instance that
1170      * represents the <CODE>MLET</CODE> tag.
1171      *
1172      * @return the codebase to use for the loaded MBean. The returned
1173      * value should not be null.
1174      *
1175      * @exception Exception if the MBean is not to be loaded for some
1176      * reason. The exception will be added to the set returned by
1177      * {@link #getMBeansFromURL getMBeansFromURL}.
1178      *
1179      * @since.unbundled JMX 1.2
1180      */

1181     protected URL JavaDoc check(String JavaDoc version, URL JavaDoc codebase, String JavaDoc jarfile,
1182             MLetContent JavaDoc mlet)
1183         throws Exception JavaDoc {
1184     return codebase;
1185     }
1186         
1187    /**
1188     * Loads the serialized object specified by the <CODE>OBJECT</CODE>
1189     * attribute of the <CODE>MLET</CODE> tag.
1190     *
1191     * @param codebase The <CODE>codebase</CODE>.
1192     * @param filename The name of the file containing the serialized object.
1193     * @return The serialized object.
1194     * @exception ClassNotFoundException The specified serialized object could not be found.
1195     * @exception IOException An I/O error occurred while loading serialized object.
1196     */

1197     private Object JavaDoc loadSerializedObject(URL JavaDoc codebase, String JavaDoc filename) throws IOException JavaDoc, ClassNotFoundException JavaDoc {
1198        if (filename != null) {
1199            filename = filename.replace(File.separatorChar,'/');
1200        }
1201    if (isTraceOn()) {
1202        trace("loadSerializedObject", codebase.toString() + filename);
1203    }
1204        InputStream JavaDoc is = getResourceAsStream(filename);
1205        if (is != null) {
1206            try {
1207                ObjectInputStream JavaDoc ois = new MLetObjectInputStream JavaDoc(is, this);
1208                Object JavaDoc serObject = ois.readObject();
1209                ois.close();
1210                return serObject;
1211            } catch (IOException JavaDoc e) {
1212        if (isDebugOn()) {
1213            debug("loadSerializedObject", "Exception while deserializing " + filename + ", " + e.getMessage());
1214        }
1215                throw e;
1216            } catch (ClassNotFoundException JavaDoc e) {
1217        if (isDebugOn()) {
1218            debug("loadSerializedObject", "Exception while deserializing " + filename + ", " + e.getMessage());
1219        }
1220                throw e;
1221            }
1222        } else {
1223        if (isDebugOn()) {
1224        debug("loadSerializedObject", "Error: File " + filename + " containing serialized object not found");
1225        }
1226            throw new Error JavaDoc("File " + filename + " containing serialized object not found");
1227        }
1228     }
1229
1230     /**
1231      * Converts the String value of the constructor's parameter to
1232      * a basic Java object with the type of the parameter.
1233      */

1234     private Object JavaDoc constructParameter(String JavaDoc param, String JavaDoc type) {
1235     // check if it is a primitive type
1236
Class JavaDoc c = (Class JavaDoc) primitiveClasses.get(type);
1237     if (c != null) {
1238        try {
1239        Constructor JavaDoc cons =
1240            c.getConstructor(new Class JavaDoc[] {String JavaDoc.class});
1241        Object JavaDoc[] oo = new Object JavaDoc[1];
1242        oo[0]=param;
1243        return(cons.newInstance(oo));
1244
1245        } catch (Exception JavaDoc e) {
1246        if (isDebugOn()) {
1247            debug(dbgTag, "constructParameter", "Unexpected Exception" + e.getClass().getName() + " occured");
1248        }
1249        }
1250    }
1251    if (type.compareTo("java.lang.Boolean") == 0)
1252         return new Boolean JavaDoc(param);
1253    if (type.compareTo("java.lang.Byte") == 0)
1254         return new Byte JavaDoc(param);
1255    if (type.compareTo("java.lang.Short") == 0)
1256         return new Short JavaDoc(param);
1257    if (type.compareTo("java.lang.Long") == 0)
1258         return new Long JavaDoc(param);
1259    if (type.compareTo("java.lang.Integer") == 0)
1260         return new Integer JavaDoc(param);
1261    if (type.compareTo("java.lang.Float") == 0)
1262         return new Float JavaDoc(param);
1263    if (type.compareTo("java.lang.Double") == 0)
1264         return new Double JavaDoc(param);
1265    if (type.compareTo("java.lang.String") == 0)
1266         return param;
1267    
1268    return param;
1269     }
1270
1271    private synchronized void setMBeanServer(final MBeanServer JavaDoc server) {
1272     this.server = server;
1273        currentClr = (ClassLoaderRepository JavaDoc)
1274            AccessController.doPrivileged(new PrivilegedAction JavaDoc() {
1275                    public Object JavaDoc run() {
1276                        return server.getClassLoaderRepository();
1277     }
1278                });
1279    }
1280
1281     // TRACES & DEBUG
1282
//---------------
1283

1284     private boolean isTraceOn() {
1285        return Trace.isSelected(Trace.LEVEL_TRACE, Trace.INFO_MLET);
1286     }
1287     
1288     private void trace(String JavaDoc clz, String JavaDoc func, String JavaDoc info) {
1289     Trace.send(Trace.LEVEL_TRACE, Trace.INFO_MLET, clz, func, info);
1290     }
1291     
1292     private void trace(String JavaDoc func, String JavaDoc info) {
1293     trace(dbgTag, func, info);
1294     }
1295     
1296     private boolean isDebugOn() {
1297     return Trace.isSelected(Trace.LEVEL_DEBUG, Trace.INFO_MLET);
1298     }
1299     
1300     private void debug(String JavaDoc clz, String JavaDoc func, String JavaDoc info) {
1301     Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_MLET, clz, func, info);
1302     }
1303     
1304     private void debug(String JavaDoc func, String JavaDoc info) {
1305     debug(dbgTag, func, info);
1306     }
1307 }
1308
Popular Tags