API Overview API Index Package Overview Direct link to this page
JDK 1.6
  javax.management.loading. MLet View Javadoc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338

/*
 * @(#)MLet.java	1.92 06/06/15
 *
 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

package javax.management.loading;


// Java import
import java.io.Externalizable;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.lang.reflect.Constructor;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLStreamHandlerFactory;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;

import javax.management.ServiceNotFoundException;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
import javax.management.MBeanServer;
import javax.management.ReflectionException;
import javax.management.InstanceAlreadyExistsException;
import javax.management.MBeanRegistrationException;
import javax.management.MBeanException;
import javax.management.NotCompliantMBeanException;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanRegistration;
import javax.management.MBeanServerFactory;
import javax.management.loading.ClassLoaderRepository;

import com.sun.jmx.mbeanserver.GetPropertyAction;

import com.sun.jmx.defaults.ServiceName;
import com.sun.jmx.defaults.JmxProperties;

import com.sun.jmx.remote.util.EnvHelp;

import com.sun.jmx.trace.Trace;


/**
 * Allows you to instantiate and register one or several MBeans in the MBean server
 * coming from a remote URL. M-let is a shortcut for management applet. The m-let service does this
 * by loading an m-let text file, which specifies information on the MBeans to be obtained.
 * The information on each MBean is specified in a single instance of a tag, called the MLET tag.
 * The location of the m-let text file is specified by a URL.
 * <p>
 * The <CODE>MLET</CODE> tag has the following syntax:
 * <p>
 * &lt;<CODE>MLET</CODE><BR>
 *      <CODE>CODE = </CODE><VAR>class</VAR><CODE> | OBJECT = </CODE><VAR>serfile</VAR><BR>
 *      <CODE>ARCHIVE = &quot;</CODE><VAR>archiveList</VAR><CODE>&quot;</CODE><BR>
 *      <CODE>[CODEBASE = </CODE><VAR>codebaseURL</VAR><CODE>]</CODE><BR>
 *      <CODE>[NAME = </CODE><VAR>mbeanname</VAR><CODE>]</CODE><BR>
 *      <CODE>[VERSION = </CODE><VAR>version</VAR><CODE>]</CODE><BR>
 * &gt;<BR>
 *	<CODE>[</CODE><VAR>arglist</VAR><CODE>]</CODE><BR>
 * &lt;<CODE>/MLET</CODE>&gt;
 * <p>
 * where:
 * <DL>
 * <DT><CODE>CODE = </CODE><VAR>class</VAR></DT>
 * <DD>
 * This attribute specifies the full Java class name, including package name, of the MBean to be obtained.
 * 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>
 * attribute. Either <CODE>CODE</CODE> or <CODE>OBJECT</CODE> must be present.
 * </DD>
 * <DT><CODE>OBJECT = </CODE><VAR>serfile</VAR></DT>
 * <DD>
 * This attribute specifies the <CODE>.ser</CODE> file that contains a serialized representation of the MBean to be obtained.
 * 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.
 * </DD>
 * <DT><CODE>ARCHIVE = &quot;</CODE><VAR>archiveList</VAR><CODE>&quot;</CODE></DT>
 * <DD>
 * This mandatory attribute specifies one or more <CODE>.jar</CODE> files
 * containing MBeans or other resources used by
 * 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.
 * If archivelist contains more than one file:
 * <UL>
 * <LI>Each file must be separated from the one that follows it by a comma (,).
 * <LI><VAR>archivelist</VAR> must be enclosed in double quote marks.
 * </UL>
 * All <CODE>.jar</CODE> files in <VAR>archivelist</VAR> must be stored in the directory specified by the code base URL.
 * </DD>
 * <DT><CODE>CODEBASE = </CODE><VAR>codebaseURL</VAR></DT>
 * <DD>
 * This optional attribute specifies the code base URL of the MBean to be obtained. It identifies the directory that contains
 * 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
 * directory as the m-let text file. If this attribute is not specified, the base URL of the m-let text file is used.
 * </DD>
 * <DT><CODE>NAME = </CODE><VAR>mbeanname</VAR></DT>
 * <DD>
 * This optional attribute specifies the object name to be assigned to the
 * MBean instance when the m-let service registers it. If
 * <VAR>mbeanname</VAR> starts with the colon character (:), the domain
 * part of the object name is the default domain of the MBean server,
 * as returned by {@link javax.management.MBeanServer#getDefaultDomain()}.
 * </DD>
 * <DT><CODE>VERSION = </CODE><VAR>version</VAR></DT>
 * <DD>
 * This optional attribute specifies the version number of the MBean and
 * associated <CODE>.jar</CODE> files to be obtained. This version number can
 * be used to specify that the <CODE>.jar</CODE> files are loaded from the
 * server to update those stored locally in the cache the next time the m-let
 * text file is loaded. <VAR>version</VAR> must be a series of non-negative
 * decimal integers each separated by a period from the one that precedes it.
 * </DD>
 * <DT><VAR>arglist</VAR></DT>
 * <DD>
 * This optional attribute specifies a list of one or more parameters for the
 * MBean to be instantiated. This list describes the parameters to be passed the MBean's constructor.
 * Use the following syntax to specify each item in
 * <VAR>arglist</VAR>:</DD>
 * <DL>
 * <P>
 * <DT>&lt;<CODE>ARG TYPE=</CODE><VAR>argumentType</VAR> <CODE>VALUE=</CODE><VAR>value</VAR>&gt;</DT>
 * <P>
 * <DD>where:</DD>
 * <UL>
 * <LI><VAR>argumentType</VAR> is the type of the argument that will be passed as parameter to the MBean's constructor.</UL>
 * </DL>
 * <P>The arguments' type in the argument list should be a Java primitive type or a Java basic type
 * (<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>).
 * </DL>
 *
 * When an m-let text file is loaded, an
 * instance of each MBean specified in the file is created and registered.
 * <P>
 * The m-let service extends the <CODE>java.net.URLClassLoader</CODE> and can be used to load remote classes
 * and jar files in the VM of the agent.
 * <p><STRONG>Note - </STRONG> The <CODE>MLet</CODE> class loader uses the {@link javax.management.MBeanServerFactory#getClassLoaderRepository(javax.management.MBeanServer)}
 * to load classes that could not be found in the loaded jar files.
 *
 * @since 1.5
 */
public class MLet extends java.net.URLClassLoader
     implements MLetMBean, MBeanRegistration, Externalizable {

     private static final long serialVersionUID = 3636148327800330130L;

     /*
     * ------------------------------------------
     *   PRIVATE VARIABLES
     * ------------------------------------------
     */

     /**
      * The reference to the MBean server.
      * @serial
      */
     private MBeanServer server = null;


     /**
      * The list of instances of the <CODE>MLetContent</CODE>
      * class found at the specified URL.
      * @serial
      */
     private List<MLetContent> mletList = new ArrayList<MLetContent>();


     /**
      * The directory used for storing libraries locally before they are loaded.
      */
     private String libraryDirectory;


     /**
      * The object name of the MLet Service.
      * @serial
      */
     private ObjectName mletObjectName = null;

     /**
      * The URLs of the MLet Service.
      * @serial
      */
     private URL[] myUrls = null;

     /**
      * The name of this class to be used for trace messages
      */
     private static final String dbgTag = "MLet";

     /**
      * What ClassLoaderRepository, if any, to use if this MLet
      * doesn't find an asked-for class.
      */
     private transient ClassLoaderRepository currentClr;

     /**
      * True if we should consult the {@link ClassLoaderRepository}
      * when we do not find a class ourselves.
      */
     private transient boolean delegateToCLR;

     /**
      * objects maps from primitive classes to primitive object classes.
      */
     private Map<String,Class<?>> primitiveClasses =
	 new HashMap<String,Class<?>>(8) ;
     {
	 primitiveClasses.put(Boolean.TYPE.toString(), Boolean.class);
	 primitiveClasses.put(Character.TYPE.toString(), Character.class);
	 primitiveClasses.put(Byte.TYPE.toString(), Byte.class);
	 primitiveClasses.put(Short.TYPE.toString(), Short.class);
	 primitiveClasses.put(Integer.TYPE.toString(), Integer.class);
	 primitiveClasses.put(Long.TYPE.toString(), Long.class);
	 primitiveClasses.put(Float.TYPE.toString(), Float.class);
	 primitiveClasses.put(Double.TYPE.toString(), Double.class);

     }


     /*
      * ------------------------------------------
      *  CONSTRUCTORS
      * ------------------------------------------
      */

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

     /**
      * Constructs a new MLet using the default delegation parent ClassLoader.
      */
     public MLet() {
	 this(new URL[0]);
     }

     /**
      * Constructs a new MLet for the specified URLs using the default
      * delegation parent ClassLoader.  The URLs will be searched in
      * the order specified for classes and resources after first
      * searching in the parent class loader.
      *
      * @param  urls  The URLs from which to load classes and resources.
      *
      */
     public MLet(URL[] urls) {
	 this(urls, true);
     }

     /**
      * Constructs a new MLet for the given URLs. The URLs will be
      * searched in the order specified for classes and resources
      * after first searching in the specified parent class loader.
      * The parent argument will be used as the parent class loader
      * for delegation.
      *
      * @param  urls  The URLs from which to load classes and resources.
      * @param  parent The parent class loader for delegation.
      *
      */
     public MLet(URL[] urls, ClassLoader parent) {
	 this(urls, parent, true);
     }

     /**
      * Constructs a new MLet for the specified URLs, parent class
      * loader, and URLStreamHandlerFactory. The parent argument will
      * be used as the parent class loader for delegation. The factory
      * argument will be used as the stream handler factory to obtain
      * protocol handlers when creating new URLs.
      *
      * @param  urls  The URLs from which to load classes and resources.
      * @param  parent The parent class loader for delegation.
      * @param  factory  The URLStreamHandlerFactory to use when creating URLs.
      *
      */
     public MLet(URL[] urls,
		 ClassLoader parent,
		 URLStreamHandlerFactory factory) {
	 this(urls, parent, factory, true);
     }

     /**
      * Constructs a new MLet for the specified URLs using the default
      * delegation parent ClassLoader.  The URLs will be searched in
      * the order specified for classes and resources after first
      * searching in the parent class loader.
      *
      * @param  urls  The URLs from which to load classes and resources.
      * @param  delegateToCLR  True if, when a class is not found in
      * either the parent ClassLoader or the URLs, the MLet should delegate
      * to its containing MBeanServer's {@link ClassLoaderRepository}.
      *
      * @since.unbundled JMX 1.2
      */
     public MLet(URL[] urls, boolean delegateToCLR) {
	 super(urls);
	 init(delegateToCLR);
     }

     /**
      * Constructs a new MLet for the given URLs. The URLs will be
      * searched in the order specified for classes and resources
      * after first searching in the specified parent class loader.
      * The parent argument will be used as the parent class loader
      * for delegation.
      *
      * @param  urls  The URLs from which to load classes and resources.
      * @param  parent The parent class loader for delegation.
      * @param  delegateToCLR  True if, when a class is not found in
      * either the parent ClassLoader or the URLs, the MLet should delegate
      * to its containing MBeanServer's {@link ClassLoaderRepository}.
      *
      * @since.unbundled JMX 1.2
      */
     public MLet(URL[] urls, ClassLoader parent, boolean delegateToCLR) {
	 super(urls, parent);
	 init(delegateToCLR);
     }

     /**
      * Constructs a new MLet for the specified URLs, parent class
      * loader, and URLStreamHandlerFactory. The parent argument will
      * be used as the parent class loader for delegation. The factory
      * argument will be used as the stream handler factory to obtain
      * protocol handlers when creating new URLs.
      *
      * @param  urls  The URLs from which to load classes and resources.
      * @param  parent The parent class loader for delegation.
      * @param  factory  The URLStreamHandlerFactory to use when creating URLs.
      * @param  delegateToCLR  True if, when a class is not found in
      * either the parent ClassLoader or the URLs, the MLet should delegate
      * to its containing MBeanServer's {@link ClassLoaderRepository}.
      *
      * @since.unbundled JMX 1.2
      */
     public MLet(URL[] urls,
		 ClassLoader parent,
		 URLStreamHandlerFactory factory,
		 boolean delegateToCLR) {
	 super(urls, parent, factory);
	 init(delegateToCLR);
     }

     private void init(boolean delegateToCLR) {
	 this.delegateToCLR = delegateToCLR;

	 try {
	     libraryDirectory = System.getProperty(JmxProperties.MLET_LIB_DIR);
	     if (libraryDirectory == null)
		 libraryDirectory = getTmpDir();
	 } catch (SecurityException e) {
	     // OK : We don't do AccessController.doPrivileged, but we don't
	     //      stop the user from creating an MLet just because they
	     //      can't read the MLET_LIB_DIR or java.io.tmpdir properties
	     //      either.
	 }
     }


     /*
      * ------------------------------------------
      *  PUBLIC METHODS
      * ------------------------------------------
      */


     /**
      * Appends the specified URL to the list of URLs to search for classes and
      * resources.
      */
     public void addURL(URL url) {
	 if (!Arrays.asList(getURLs()).contains(url))
	     super.addURL(url);
     }

     /**
      * Appends the specified URL to the list of URLs to search for classes and
      * resources.
      * @exception ServiceNotFoundException The specified URL is malformed.
      */
     public void addURL(String url) throws ServiceNotFoundException {
	 try {
	     URL ur = new URL(url);
	     if (!Arrays.asList(getURLs()).contains(ur))
		 super.addURL(ur);
	 } catch (MalformedURLException e) {
	     debug("addURL", url + ": Malformed URL. " + e);
	     throw new
		 ServiceNotFoundException("The specified URL is malformed");
	 }
     }

     /** Returns the search path of URLs for loading classes and resources.
      * This includes the original list of URLs specified to the constructor,
      * along with any URLs subsequently appended by the addURL() method.
      */
     public URL[] getURLs() {
	 return super.getURLs();
     }

     /**
      * Loads a text file containing MLET tags that define the MBeans to
      * be added to the MBean server. The location of the text file is specified by
      * a URL. The MBeans specified in the MLET file will be instantiated and
      * registered in the MBean server.
      *
      * @param url The URL of the text file to be loaded as URL object.
      *
      * @return  A set containing one entry per MLET tag in the m-let text file loaded.
      * Each entry specifies either the ObjectInstance for the created MBean, or a throwable object
      * (that is, an error or an exception) if the MBean could not be created.
      *
      * @exception ServiceNotFoundException One of the following errors has occurred: The m-let text file does
      * not contain an MLET tag, the m-let text file is not found, a mandatory
      * attribute of the MLET tag is not specified, the value of url is
      * null.
      * @exception IllegalStateException MLet MBean is not registered with an MBeanServer.
      */
     public Set<Object> getMBeansFromURL(URL url)
	     throws ServiceNotFoundException  {
	 if (url == null) {
	     throw new ServiceNotFoundException("The specified URL is null");
	 }
	 return getMBeansFromURL(url.toString());
     }

     /**
      * Loads a text file containing MLET tags that define the MBeans to
      * be added to the MBean server. The location of the text file is specified by
      * a URL. The MBeans specified in the MLET file will be instantiated and
      * registered in the MBean server.
      *
      * @param url The URL of the text file to be loaded as String object.
      *
      * @return A set containing one entry per MLET tag in the m-let
      * text file loaded.  Each entry specifies either the
      * ObjectInstance for the created MBean, or a throwable object
      * (that is, an error or an exception) if the MBean could not be
      * created.
      *
      * @exception ServiceNotFoundException One of the following
      * errors has occurred: The m-let text file does not contain an
      * MLET tag, the m-let text file is not found, a mandatory
      * attribute of the MLET tag is not specified, the url is
      * malformed.
      * @exception IllegalStateException MLet MBean is not registered
      * with an MBeanServer.
      *
      */
     public Set<Object> getMBeansFromURL(String url)
	     throws ServiceNotFoundException  {

	 String mth = "getMBeansFromURL";

	 if (server == null) {
	     throw new IllegalStateException("This MLet MBean is not " +
					     "registered with an MBeanServer.");
	 }
	 // Parse arguments
	 if (url == null) {
	     if (isTraceOn()) {
		 trace(mth, "URL is null");
	     }
	     throw new ServiceNotFoundException("The specified URL is null");
	 } else {
	     url = url.replace(File.separatorChar,'/');
	 }
	 if (isTraceOn()) {
	     trace(mth, "<URL = " + url + ">");
	 }

	 // Parse URL
	 try {
	     MLetParser parser = new MLetParser();
	     mletList = parser.parseURL(url);
	 } catch (Exception e) {
	     final String msg =
		 "Problems while parsing URL [" + url +
		 "], got exception [" + e.toString() + "]";
	     if (isTraceOn()) {
		 trace(mth, msg);
	     }
	     throw EnvHelp.initCause(new ServiceNotFoundException(msg), e);
	 }

	 // Check that the list of MLets is not empty
	 if (mletList.size() == 0) {
	     final String msg =
		 "File " + url + " not found or MLET tag not defined in file";
	     if (isTraceOn()) {
		 trace(mth, msg);
	     }
	     throw new ServiceNotFoundException(msg);
	 }

	 // Walk through the list of MLets
	 Set<Object> mbeans = new HashSet<Object>();
	 for (MLetContent elmt : mletList) {
	     // Initialize local variables
	     String code = elmt.getCode();
	     if (code != null) {
		 if (code.endsWith(".class")) {
		     code = code.substring(0, code.length() - 6);
		 }
	     }
	     String name = elmt.getName();
	     URL codebase = elmt.getCodeBase();
	     String version = elmt.getVersion();
	     String serName = elmt.getSerializedObject();
	     String jarFiles = elmt.getJarFiles();
	     URL documentBase = elmt.getDocumentBase();

	     // Display debug information
	     if (isTraceOn()) {
		 trace(mth, "MLET TAG     = " + elmt.getAttributes());
		 trace(mth, "CODEBASE     = " + codebase);
		 trace(mth, "ARCHIVE      = " + jarFiles);
		 trace(mth, "CODE         = " + code);
		 trace(mth, "OBJECT       = " + serName);
		 trace(mth, "NAME         = " + name);
		 trace(mth, "VERSION      = " + version);
		 trace(mth, "DOCUMENT URL = " + documentBase);
	     }

	     // Load classes from JAR files
	     StringTokenizer st = new StringTokenizer(jarFiles, ",", false);
	     while (st.hasMoreTokens()) {
		 String tok = st.nextToken().trim();
		 if (isTraceOn()) {
		     trace(mth, "Load archive for codebase <" + codebase +
			   ">, file <" + tok + ">");
		 }
		 // Check which is the codebase to be used for loading the jar file.
		 // If we are using the base MLet implementation then it will be
		 // always the remote server but if the service has been extended in
		 // order to support caching and versioning then this method will
		 // return the appropriate one.
		 //
		 try {
		     codebase = check(version, codebase, tok, elmt);
		 } catch (Exception ex) {
		     if (isDebugOn()) {
			 debug(mth, "check returned exception: " + ex);
		     }
		     mbeans.add(ex);
		     continue;
		 }

		 // Appends the specified JAR file URL to the list of
		 // URLs to search for classes and resources.
		 try {
		     if (!Arrays.asList(getURLs())
			 .contains(new URL(codebase.toString() + tok))) {
			 addURL(codebase + tok);
		     }
		 } catch (MalformedURLException me) {
		     // OK : Ignore jar file if its name provokes the
		     // URL to be an invalid one.
		 }

	     }
	     // Instantiate the class specified in the
	     // CODE or OBJECT section of the MLet tag
	     //
	     Object o = null;
	     ObjectInstance objInst = null;

	     if (code != null && serName != null) {
		 final String msg =
		     "CODE and OBJECT parameters cannot be specified at the " +
		     "same time in tag MLET";
		 if (isTraceOn()) {
		     trace(mth, msg);
		 }
		 mbeans.add(new Error(msg));
		 continue;
	     }
	     if (code == null && serName == null) {
		 final String msg =
		     "Either CODE or OBJECT parameter must be specified in " +
		     "tag MLET";
		 if (isTraceOn()) {
		     trace(mth, msg);
		 }
		 mbeans.add(new Error(msg));
		 continue;
	     }
	     try {
		 if (code != null) {

		     List<String> signat = elmt.getParameterTypes();
		     List<String> stringPars = elmt.getParameterValues();
		     List<Object> objectPars = new ArrayList<Object>();

		     for (int i = 0; i < signat.size(); i++) {
			 objectPars.add(constructParameter(stringPars.get(i),
							   signat.get(i)));
		     }
		     if (signat.isEmpty()) {
			 if (name == null) {
			     objInst = server.createMBean(code, null,
							  mletObjectName);
			 } else {
			     objInst = server.createMBean(code,
							  new ObjectName(name),
							  mletObjectName);
			 }
		     } else {
			 Object[] parms = objectPars.toArray();
			 String[] signature = new String[signat.size()];
			 signat.toArray(signature);
			 if (isDebugOn()) {
			     for (int i=0;i<signature.length;i++) {
				 debug(mth, "Signature     = " + signature[i]);
				 debug(mth, "Params     = " + parms[i]);
			     }
			 }
			 if (name == null) {
			     objInst =
				 server.createMBean(code, null, mletObjectName,
						    parms, signature);
			 } else {
			     objInst =
				 server.createMBean(code, new ObjectName(name),
						    mletObjectName, parms,
						    signature);
			 }
		     }
		 } else {
		     o = loadSerializedObject(codebase,serName);
		     if (name == null) {
			 server.registerMBean(o, null);
		     } else {
			 server.registerMBean(o,  new ObjectName(name));
		     }
		     objInst = new ObjectInstance(name, o.getClass().getName());
		 }
	     } catch (ReflectionException  ex) {
		 if (isTraceOn()) {
		     trace(mth, "ReflectionException: " + ex.getMessage());
		 }
		 mbeans.add(ex);
		 continue;
	     } catch (InstanceAlreadyExistsException  ex) {
		 if (isTraceOn()) {
		     trace(mth, "InstanceAlreadyExistsException: " + ex.getMessage());
		 }
		 mbeans.add(ex);
		 continue;
	     } catch (MBeanRegistrationException ex) {
		 if (isTraceOn()) {
		     trace(mth, "MBeanRegistrationException: " + ex.getMessage());
		 }
		 mbeans.add(ex);
		 continue;
	     } catch (MBeanException  ex) {
		 if (isTraceOn()) {
		     trace(mth, "MBeanException: " + ex.getMessage());
		 }
		 mbeans.add(ex);
		 continue;
	     } catch (NotCompliantMBeanException  ex) {
		 if (isTraceOn()) {
		     trace(mth, "NotCompliantMBeanException: " + ex.getMessage());
		 }
		 mbeans.add(ex);
		 continue;
	     } catch (InstanceNotFoundException   ex) {
		 if (isTraceOn()) {
		     trace(mth, "InstanceNotFoundException: " + ex.getMessage());
		 }
		 mbeans.add(ex);
		 continue;
	     } catch (IOException ex) {
		 if (isTraceOn()) {
		     trace(mth, "IOException: " + ex.getMessage());
		 }
		 mbeans.add(ex);
		 continue;
	     } catch (SecurityException ex) {
		 if (isTraceOn()) {
		     trace(mth, "SecurityException: " + ex.getMessage());
		 }
		 mbeans.add(ex);
		 continue;
	     } catch (Exception ex) {
		 if (isTraceOn()) {
		     trace(mth, "Exception: " + ex.getClass().getName() + ex.getMessage());
		 }
		 mbeans.add(ex);
		 continue;
	     } catch (Error ex) {
		 if (isTraceOn()) {
		     trace(mth, "Error: " + ex.getMessage());
		 }
		 mbeans.add(ex);
		 continue;
	     }
	     mbeans.add(objInst);
	 }
	 return mbeans;
     }

     /**
      * Gets the current directory used by the library loader for
      * storing native libraries before they are loaded into memory.
      *
      * @return The current directory used by the library loader.
      *
      * @see #setLibraryDirectory
      *
      * @throws UnsupportedOperationException if this implementation
      * does not support storing native libraries in this way.
      */
     public synchronized String getLibraryDirectory() {
	 return libraryDirectory;
     }

     /**
      * Sets the directory used by the library loader for storing
      * native libraries before they are loaded into memory.
      *
      * @param libdir The directory used by the library loader.
      *
      * @see #getLibraryDirectory
      *
      * @throws UnsupportedOperationException if this implementation
      * does not support storing native libraries in this way.
      */
     public synchronized void setLibraryDirectory(String libdir) {
	 libraryDirectory = libdir;
     }

     /**
      * Allows the m-let to perform any operations it needs before
      * being registered in the MBean server. If the ObjectName is
      * null, the m-let provides a default name for its registration
      * &lt;defaultDomain&gt;:type=MLet
      *
      * @param server The MBean server in which the m-let will be registered.
      * @param name The object name of the m-let.
      *
      * @return  The name of the m-let registered.
      *
      * @exception java.lang.Exception This exception should be caught by the MBean server and re-thrown
      *as an MBeanRegistrationException.
      */
     public ObjectName preRegister(MBeanServer server, ObjectName name)
	     throws Exception {

	 // Initialize local pointer to the MBean server
	 setMBeanServer(server);

	 // If no name is specified return a default name for the MLet
	 if (name == null) {
	     name = new ObjectName(server.getDefaultDomain() + ":" + ServiceName.MLET);
	 }

	this.mletObjectName = name;
	return this.mletObjectName;
     }

     /**
      * Allows the m-let to perform any operations needed after having been
      * registered in the MBean server or after the registration has failed.
      *
      * @param registrationDone Indicates whether or not the m-let has
      * been successfully registered in the MBean server. The value
      * false means that either the registration phase has failed.
      *
      */
     public void postRegister (Boolean registrationDone) {
     }

     /**
      * Allows the m-let to perform any operations it needs before being unregistered
      * by the MBean server.
      *
      * @exception java.langException This exception should be caught
      * by the MBean server and re-thrown as an
      * MBeanRegistrationException.
      */
     public void preDeregister() throws java.lang.Exception {
     }


     /**
      * Allows the m-let to perform any operations needed after having been
      * unregistered in the MBean server.
      */
     public void postDeregister() {
     }

     /**
      * <p>Save this MLet's contents to the given {@link ObjectOutput}.
      * Not all implementations support this method.  Those that do not
      * throw {@link UnsupportedOperationException}.  A subclass may
      * override this method to support it or to change the format of
      * the written data.</p>
      *
      * <p>The format of the written data is not specified, but if
      * an implementation supports {@link #writeExternal} it must
      * also support {@link #readExternal} in such a way that what is
      * written by the former can be read by the latter.</p>
      *
      * @param out The object output stream to write to.
      *
      * @exception IOException If a problem occurred while writing.
      * @exception UnsupportedOperationException If this
      * implementation does not support this operation.
      */
     public void writeExternal(ObjectOutput out)
	     throws IOException, UnsupportedOperationException {
	 throw new UnsupportedOperationException("MLet.writeExternal");
     }

     /**
      * <p>Restore this MLet's contents from the given {@link ObjectInput}.
      * Not all implementations support this method.  Those that do not
      * throw {@link UnsupportedOperationException}.  A subclass may
      * override this method to support it or to change the format of
      * the read data.</p>
      *
      * <p>The format of the read data is not specified, but if an
      * implementation supports {@link #readExternal} it must also
      * support {@link #writeExternal} in such a way that what is
      * written by the latter can be read by the former.</p>
      *
      * @param in The object input stream to read from.
      *
      * @exception IOException if a problem occurred while reading.
      * @exception ClassNotFoundException if the class for the object
      * being restored cannot be found.
      * @exception UnsupportedOperationException if this
      * implementation does not support this operation.
      */
     public void readExternal(ObjectInput in)
	     throws IOException, ClassNotFoundException,
		    UnsupportedOperationException {
	 throw new UnsupportedOperationException("MLet.readExternal");
     }

     /*
      * ------------------------------------------
      *  PACKAGE METHODS
      * ------------------------------------------
      */

     /**
      * <p>Load a class, using the given {@link ClassLoaderRepository} if
      * the class is not found in this MLet's URLs.  The given
      * ClassLoaderRepository can be null, in which case a {@link
      * ClassNotFoundException} occurs immediately if the class is not
      * found in this MLet's URLs.</p>
      *
      * @param name The name of the class we want to load.
      * @param clr  The ClassLoaderRepository that will be used to search
      *             for the given class, if it is not found in this
      *             ClassLoader.  May be null.
      * @return The resulting Class object.
      * @exception ClassNotFoundException The specified class could not be
      *            found in this ClassLoader nor in the given
      *            ClassLoaderRepository.
      *
      * @since.unbundled JMX 1.1
      */
     public synchronized Class<?> loadClass(String name,
					    ClassLoaderRepository clr)
	      throws ClassNotFoundException {
	 final ClassLoaderRepository before=currentClr;
	 try {
	     currentClr = clr;
	     return loadClass(name);
	 } finally {
	     currentClr = before;
	 }
     }

     /*
      * ------------------------------------------
      *  PROTECTED METHODS
      * ------------------------------------------
      */

     /**
      * This is the main method for class loaders that is being redefined.
      *
      * @param name The name of the class.
      *
      * @return The resulting Class object.
      *
      * @exception ClassNotFoundException The specified class could not be
      *            found.
      */
     protected Class<?> findClass(String name) throws ClassNotFoundException {
	 /* currentClr is context sensitive - used to avoid recursion
	    in the class loader repository.  (This is no longer
	    necessary with the new CLR semantics but is kept for
	    compatibility with code that might have called the
	    two-parameter loadClass explicitly.)  */
	 return findClass(name, currentClr);
     }

     /**
      * Called by {@link MLet#findClass(java.lang.String)}.
      *
      * @param name The name of the class that we want to load/find.
      * @param clr The ClassLoaderRepository that can be used to search
      *            for the given class. This parameter is
      *            <code>null</code> when called from within the
      *            {@link javax.management.MBeanServerFactory#getClassLoaderRepository(javax.management.MBeanServer) Class Loader Repository}.
      * @exception ClassNotFoundException The specified class could not be
      *            found.
      *
      **/
     Class<?> findClass(String name, ClassLoaderRepository clr)
	 throws ClassNotFoundException {
	 Class<?> c = null;
	 if (isTraceOn()) {
	     trace("findClass", name);
	 }
	 // Try looking in the JAR:
	 try {
	     c = super.findClass(name);
	     if (isTraceOn()) {
		 trace("findClass", "Class "+name+
		       " loaded through mlet classloader");
	     }
	 } catch (ClassNotFoundException e) {
	     // Drop through
	     debug("findClass", "Class "+name+ " not found locally.");
	 }
	 // if we are not called from the ClassLoaderRepository
	 if (c == null && delegateToCLR && clr != null) {
	     // Try the classloader repository:
	     //
	     try {
		 debug("findClass", "Class "+name+": looking in CLR");
		 c = clr.loadClassBefore(this, name);
		 // The loadClassBefore method never returns null.
		 // If the class is not found we get an exception.
		 if (isTraceOn()) {
		     trace("findClass", "Class "+name+
			   " loaded through the default classloader repository");
		 }
	     } catch (ClassNotFoundException e) {
		 debug("findClass", "Class "+name+ " not found in CLR.");
		 // Drop through
	     }
	 }
	 if (c == null) {
	     debug("findClass","Failed to load class " + name);
	     throw new ClassNotFoundException(name);
         }
	 return c;
     }

     /**
      * Returns the absolute path name of a native library. The VM
      * invokes this method to locate the native libraries that belong
      * to classes loaded with this class loader. Libraries are
      * searched in the JAR files using first just the native library
      * name and if not found the native library name together with
      * the architecture-specific path name
      * (<code>OSName/OSArch/OSVersion/lib/nativelibname</code>), i.e.
      * <p>
      * the library stat on Solaris SPARC 5.7 will be searched in the JAR file as:
      * <OL>
      * <LI>libstat.so
      * <LI>SunOS/sparc/5.7/lib/libstat.so
      * </OL>
      * the library stat on Windows NT 4.0 will be searched in the JAR file as:
      * <OL>
      * <LI>stat.dll
      * <LI>WindowsNT/x86/4.0/lib/stat.dll
      * </OL>
      *
      * <p>More specifically, let <em>{@code nativelibname}</em> be the result of
      * {@link System#mapLibraryName(java.lang.String)
      * System.mapLibraryName}{@code (libname)}.  Then the following names are
      * searched in the JAR files, in order:<br>
      * <em>{@code nativelibname}</em><br>
      * {@code <os.name>/<os.arch>/<os.version>/lib/}<em>{@code nativelibname}</em><br>
      * where {@code <X>} means {@code System.getProperty(X)} with any
      * spaces in the result removed, and {@code /} stands for the
      * file separator character ({@link File#separator}).
      * <p>
      * If this method returns <code>null</code>, i.e. the libraries
      * were not found in any of the JAR files loaded with this class
      * loader, the VM searches the library along the path specified
      * as the <code>java.library.path</code> property.
      *
      * @param libname The library name.
      *
      * @return The absolute path of the native library.
      */
     protected String findLibrary(String libname) {

	 String abs_path;
	 String mth = "findLibrary";

	 // Get the platform-specific string representing a native library.
	 //
	 String nativelibname = System.mapLibraryName(libname);

	 //
	 // See if the native library is accessible as a resource through the JAR file.
	 //
	 if (isTraceOn()) {
	     trace(mth, "Search " + libname + " in all JAR files.");
	 }

	 // First try to locate the library in the JAR file using only
	 // the native library name.  e.g. if user requested a load
	 // for "foo" on Solaris SPARC 5.7 we try to load "libfoo.so"
	 // from the JAR file.
	 //
	 if (isTraceOn()) {
	     trace(mth, "loadLibraryAsResource(" + nativelibname + ")");
	 }
	 abs_path = loadLibraryAsResource(nativelibname);
	 if (abs_path != null) {
	     if (isTraceOn()) {
		 trace(mth, nativelibname + " loaded " + "absolute path = " + abs_path);
	     }
	     return abs_path;
	 }

	 // Next try to locate it using the native library name and
	 // the architecture-specific path name.  e.g. if user
	 // requested a load for "foo" on Solaris SPARC 5.7 we try to
	 // load "SunOS/sparc/5.7/lib/libfoo.so" from the JAR file.
	 //
	 nativelibname = removeSpace(System.getProperty("os.name")) + File.separator +
	     removeSpace(System.getProperty("os.arch")) + File.separator +
	     removeSpace(System.getProperty("os.version")) + File.separator +
	     "lib" + File.separator + nativelibname;
	 if (isTraceOn()) {
	     trace(mth, "loadLibraryAsResource(" + nativelibname + ")");
	 }

	 abs_path = loadLibraryAsResource(nativelibname);
	 if (abs_path != null) {
	     if (isTraceOn()) {
		 trace(mth, nativelibname + " loaded " + "absolute path = " + abs_path);
	     }
	     return abs_path;
	 }

	 //
	 // All paths exhausted, library not found in JAR file.
	 //

	 if (isTraceOn()) {
	     trace(mth, libname + " not found in any JAR file.");
	     trace(mth, "Search " + libname + " along the path specified as the java.library.path property.");
	 }


	 // Let the VM search the library along the path
	 // specified as the java.library.path property.
	 //
	 return null;
     }


     /*
      * ------------------------------------------
      *  PRIVATE METHODS
      * ------------------------------------------
      */

     private String getTmpDir() {
	 // JDK 1.4
	 String tmpDir = System.getProperty("java.io.tmpdir");
	 if (tmpDir != null) return tmpDir;

	 // JDK < 1.4
	 File tmpFile = null;
	 try {
	     // Try to guess the system temporary dir...
	     tmpFile = File.createTempFile("tmp","jmx");
	     if (tmpFile == null) return null;
	     final File tmpDirFile = tmpFile.getParentFile();
	     if (tmpDirFile == null) return null;
	     return tmpDirFile.getAbsolutePath();
	 } catch (Exception x) {
	     debug("getTmpDir","Failed to determine system temporary dir.");
	     return null;
	 } finally {
	     // Cleanup ...
	     if (tmpFile!=null) try {
		 tmpFile.delete();
	     } catch (Exception x) {
		 debug("getTmpDir","Failed to delete temporary file: " + x.getMessage());
	 }
     }
     }

     /**
      * Search the specified native library in any of the JAR files
      * loaded by this classloader.  If the library is found copy it
      * into the library directory and return the absolute path.  If
      * the library is not found then return null.
      */
     private synchronized String loadLibraryAsResource(String libname) {
	 try {
	     InputStream is = getResourceAsStream(libname.replace(File.separatorChar,'/'));
	     if (is != null) {
		 File directory = new File(libraryDirectory);
		 directory.mkdirs();
		 File file = File.createTempFile(libname + ".", null, directory);
		 file.deleteOnExit();
		 FileOutputStream fileOutput = new FileOutputStream(file);
		 int c;
		 while ((c = is.read()) != -1) {
		     fileOutput.write(c);
		 }
		 is.close();
		 fileOutput.close();
		 if (file.exists()) {
		     return file.getAbsolutePath();
		 }
	     }
	 } catch (Exception e) {
	     debug("loadLibraryAsResource",libname+
		   ": Failed to load library. " + e);
	     return null;
	 }
	 return null;
     }

   /**
    * Removes any white space from a string. This is used to
    * convert strings such as "Windows NT" to "WindowsNT".
    */
     private String removeSpace(String s) {
	 s = s.trim();
	 int j = s.indexOf(' ');
	 if (j == -1) {
	     return s;
	 }
	 String temp = "";
	 int k = 0;
	 while (j != -1) {
	     s = s.substring(k);
	     j = s.indexOf(' ');
	     if (j != -1) {
		 temp = temp + s.substring(0, j);
	     } else {
		 temp = temp + s.substring(0);
	     }
	     k = j + 1;
	 }
	 return temp;
     }

     /**
      * <p>This method is to be overridden when extending this service to
      * support caching and versioning.  It is called from {@link
      * #getMBeansFromURL getMBeansFromURL} when the version,
      * codebase, and jarfile have been extracted from the MLet file,
      * and can be used to verify that it is all right to load the
      * given MBean, or to replace the given URL with a different one.</p>
      *
      * <p>The default implementation of this method returns
      * <code>codebase</code> unchanged.</p>
      *
      * @param version The version number of the <CODE>.jar</CODE>
      * file stored locally.
      * @param codebase The base URL of the remote <CODE>.jar</CODE> file.
      * @param jarfile The name of the <CODE>.jar</CODE> file to be loaded.
      * @param mlet The <CODE>MLetContent</CODE> instance that
      * represents the <CODE>MLET</CODE> tag.
      *
      * @return the codebase to use for the loaded MBean.  The returned
      * value should not be null.
      *
      * @exception Exception if the MBean is not to be loaded for some
      * reason.  The exception will be added to the set returned by
      * {@link #getMBeansFromURL getMBeansFromURL}.
      *
      * @since.unbundled JMX 1.2
      */
     protected URL check(String version, URL codebase, String jarfile,
			 MLetContent mlet)
	     throws Exception {
	 return codebase;
     }

    /**
     * Loads the serialized object specified by the <CODE>OBJECT</CODE>
     * attribute of the <CODE>MLET</CODE> tag.
     *
     * @param codebase The <CODE>codebase</CODE>.
     * @param filename The name of the file containing the serialized object.
     * @return The serialized object.
     * @exception ClassNotFoundException The specified serialized
     * object could not be found.
     * @exception IOException An I/O error occurred while loading
     * serialized object.
     */
     private Object loadSerializedObject(URL codebase, String filename)
	     throws IOException, ClassNotFoundException {
        if (filename != null) {
            filename = filename.replace(File.separatorChar,'/');
        }
	if (isTraceOn()) {
	    trace("loadSerializedObject", codebase.toString() + filename);
	}
        InputStream is = getResourceAsStream(filename);
        if (is != null) {
            try {
                ObjectInputStream ois = new MLetObjectInputStream(is, this);
                Object serObject = ois.readObject();
                ois.close();
                return serObject;
            } catch (IOException e) {
		if (isDebugOn()) {
		    debug("loadSerializedObject", "Exception while deserializing " + filename + ", " + e.getMessage());
		}
                throw e;
            } catch (ClassNotFoundException e) {
		if (isDebugOn()) {
		    debug("loadSerializedObject", "Exception while deserializing " + filename + ", " + e.getMessage());
		}
                throw e;
            }
        } else {
	    if (isDebugOn()) {
		debug("loadSerializedObject", "Error: File " + filename + " containing serialized object not found");
	    }
            throw new Error("File " + filename + " containing serialized object not found");
        }
     }

     /**
      * Converts the String value of the constructor's parameter to
      * a basic Java object with the type of the parameter.
      */
     private  Object constructParameter(String param, String type) {
	 // check if it is a primitive type
	 Class<?> c = primitiveClasses.get(type);
	 if (c != null) {
	    try {
		Constructor<?> cons =
		    c.getConstructor(new Class[] {String.class});
		Object[] oo = new Object[1];
		oo[0]=param;
		return(cons.newInstance(oo));

	    } catch (Exception  e) {
		if (isDebugOn()) {
		    debug(dbgTag, "constructParameter",
			  "Unexpected Exception" + e.getClass().getName() +
			  " occurred");
		}
	    }
	}
	if (type.compareTo("java.lang.Boolean") == 0)
	     return new Boolean(param);
	if (type.compareTo("java.lang.Byte") == 0)
	     return new Byte(param);
	if (type.compareTo("java.lang.Short") == 0)
	     return new Short(param);
	if (type.compareTo("java.lang.Long") == 0)
	     return new Long(param);
	if (type.compareTo("java.lang.Integer") == 0)
	     return new Integer(param);
	if (type.compareTo("java.lang.Float") == 0)
	     return new Float(param);
	if (type.compareTo("java.lang.Double") == 0)
	     return new Double(param);
	if (type.compareTo("java.lang.String") == 0)
	     return param;

	return param;
     }

    private synchronized void setMBeanServer(final MBeanServer server) {
	this.server = server;
	PrivilegedAction<ClassLoaderRepository> act =
            new PrivilegedAction<ClassLoaderRepository>() {
		public ClassLoaderRepository run() {
		    return server.getClassLoaderRepository();
		}
	    };
        currentClr = AccessController.doPrivileged(act);
    }

    // TRACES & DEBUG
    //---------------

    private boolean isTraceOn() {
        return Trace.isSelected(Trace.LEVEL_TRACE, Trace.INFO_MLET);
    }

    private void trace(String clz, String func, String info) {
	Trace.send(Trace.LEVEL_TRACE, Trace.INFO_MLET, clz, func, info);
    }

    private void trace(String func, String info) {
	trace(dbgTag, func, info);
    }

    private boolean isDebugOn() {
	return Trace.isSelected(Trace.LEVEL_DEBUG, Trace.INFO_MLET);
    }

    private void debug(String clz, String func, String info) {
	Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_MLET, clz, func, info);
    }

    private void debug(String func, String info) {
	debug(dbgTag, func, info);
    }
}

Generated By: JavaOnTracks Doclet 0.1.4     ©Thibaut Colar