50 import java.util.ArrayList; |
50 import java.util.ArrayList; |
51 import java.util.Arrays; |
51 import java.util.Arrays; |
52 import java.util.HashMap; |
52 import java.util.HashMap; |
53 import java.util.HashSet; |
53 import java.util.HashSet; |
54 import java.util.List; |
54 import java.util.List; |
55 import java.util.logging.Level; |
55 import java.lang.System.Logger.Level; |
56 import java.util.Map; |
56 import java.util.Map; |
57 import java.util.Set; |
57 import java.util.Set; |
58 import java.util.StringTokenizer; |
58 import java.util.StringTokenizer; |
59 |
59 |
60 import javax.management.InstanceAlreadyExistsException; |
60 import javax.management.InstanceAlreadyExistsException; |
410 try { |
410 try { |
411 URL ur = new URL(url); |
411 URL ur = new URL(url); |
412 if (!Arrays.asList(getURLs()).contains(ur)) |
412 if (!Arrays.asList(getURLs()).contains(ur)) |
413 super.addURL(ur); |
413 super.addURL(ur); |
414 } catch (MalformedURLException e) { |
414 } catch (MalformedURLException e) { |
415 if (MLET_LOGGER.isLoggable(Level.FINEST)) { |
415 if (MLET_LOGGER.isLoggable(Level.DEBUG)) { |
416 MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(), |
416 MLET_LOGGER.log(Level.DEBUG, "Malformed URL: " + url, e); |
417 "addUrl", "Malformed URL: " + url, e); |
|
418 } |
417 } |
419 throw new |
418 throw new |
420 ServiceNotFoundException("The specified URL is malformed"); |
419 ServiceNotFoundException("The specified URL is malformed"); |
421 } |
420 } |
422 } |
421 } |
479 * |
478 * |
480 */ |
479 */ |
481 public Set<Object> getMBeansFromURL(String url) |
480 public Set<Object> getMBeansFromURL(String url) |
482 throws ServiceNotFoundException { |
481 throws ServiceNotFoundException { |
483 |
482 |
484 String mth = "getMBeansFromURL"; |
|
485 |
|
486 if (server == null) { |
483 if (server == null) { |
487 throw new IllegalStateException("This MLet MBean is not " + |
484 throw new IllegalStateException("This MLet MBean is not " + |
488 "registered with an MBeanServer."); |
485 "registered with an MBeanServer."); |
489 } |
486 } |
490 // Parse arguments |
487 // Parse arguments |
491 if (url == null) { |
488 if (url == null) { |
492 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), |
489 MLET_LOGGER.log(Level.TRACE, "URL is null"); |
493 mth, "URL is null"); |
|
494 throw new ServiceNotFoundException("The specified URL is null"); |
490 throw new ServiceNotFoundException("The specified URL is null"); |
495 } else { |
491 } else { |
496 url = url.replace(File.separatorChar,'/'); |
492 url = url.replace(File.separatorChar,'/'); |
497 } |
493 } |
498 if (MLET_LOGGER.isLoggable(Level.FINER)) { |
494 if (MLET_LOGGER.isLoggable(Level.TRACE)) { |
499 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), |
495 MLET_LOGGER.log(Level.TRACE, "<URL = " + url + ">"); |
500 mth, "<URL = " + url + ">"); |
|
501 } |
496 } |
502 |
497 |
503 // Parse URL |
498 // Parse URL |
504 try { |
499 try { |
505 MLetParser parser = new MLetParser(); |
500 MLetParser parser = new MLetParser(); |
506 mletList = parser.parseURL(url); |
501 mletList = parser.parseURL(url); |
507 } catch (Exception e) { |
502 } catch (Exception e) { |
508 final String msg = |
503 final String msg = |
509 "Problems while parsing URL [" + url + |
504 "Problems while parsing URL [" + url + |
510 "], got exception [" + e.toString() + "]"; |
505 "], got exception [" + e.toString() + "]"; |
511 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, msg); |
506 MLET_LOGGER.log(Level.TRACE, msg); |
512 throw EnvHelp.initCause(new ServiceNotFoundException(msg), e); |
507 throw EnvHelp.initCause(new ServiceNotFoundException(msg), e); |
513 } |
508 } |
514 |
509 |
515 // Check that the list of MLets is not empty |
510 // Check that the list of MLets is not empty |
516 if (mletList.size() == 0) { |
511 if (mletList.size() == 0) { |
517 final String msg = |
512 final String msg = |
518 "File " + url + " not found or MLET tag not defined in file"; |
513 "File " + url + " not found or MLET tag not defined in file"; |
519 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, msg); |
514 MLET_LOGGER.log(Level.TRACE, msg); |
520 throw new ServiceNotFoundException(msg); |
515 throw new ServiceNotFoundException(msg); |
521 } |
516 } |
522 |
517 |
523 // Walk through the list of MLets |
518 // Walk through the list of MLets |
524 Set<Object> mbeans = new HashSet<Object>(); |
519 Set<Object> mbeans = new HashSet<Object>(); |
536 String serName = elmt.getSerializedObject(); |
531 String serName = elmt.getSerializedObject(); |
537 String jarFiles = elmt.getJarFiles(); |
532 String jarFiles = elmt.getJarFiles(); |
538 URL documentBase = elmt.getDocumentBase(); |
533 URL documentBase = elmt.getDocumentBase(); |
539 |
534 |
540 // Display debug information |
535 // Display debug information |
541 if (MLET_LOGGER.isLoggable(Level.FINER)) { |
536 if (MLET_LOGGER.isLoggable(Level.TRACE)) { |
542 final StringBuilder strb = new StringBuilder() |
537 final StringBuilder strb = new StringBuilder() |
543 .append("\n\tMLET TAG = ").append(elmt.getAttributes()) |
538 .append("\n\tMLET TAG = ").append(elmt.getAttributes()) |
544 .append("\n\tCODEBASE = ").append(codebase) |
539 .append("\n\tCODEBASE = ").append(codebase) |
545 .append("\n\tARCHIVE = ").append(jarFiles) |
540 .append("\n\tARCHIVE = ").append(jarFiles) |
546 .append("\n\tCODE = ").append(code) |
541 .append("\n\tCODE = ").append(code) |
547 .append("\n\tOBJECT = ").append(serName) |
542 .append("\n\tOBJECT = ").append(serName) |
548 .append("\n\tNAME = ").append(name) |
543 .append("\n\tNAME = ").append(name) |
549 .append("\n\tVERSION = ").append(version) |
544 .append("\n\tVERSION = ").append(version) |
550 .append("\n\tDOCUMENT URL = ").append(documentBase); |
545 .append("\n\tDOCUMENT URL = ").append(documentBase); |
551 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), |
546 MLET_LOGGER.log(Level.TRACE, strb::toString); |
552 mth, strb.toString()); |
|
553 } |
547 } |
554 |
548 |
555 // Load classes from JAR files |
549 // Load classes from JAR files |
556 StringTokenizer st = new StringTokenizer(jarFiles, ",", false); |
550 StringTokenizer st = new StringTokenizer(jarFiles, ",", false); |
557 while (st.hasMoreTokens()) { |
551 while (st.hasMoreTokens()) { |
558 String tok = st.nextToken().trim(); |
552 String tok = st.nextToken().trim(); |
559 if (MLET_LOGGER.isLoggable(Level.FINER)) { |
553 if (MLET_LOGGER.isLoggable(Level.TRACE)) { |
560 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, |
554 MLET_LOGGER.log(Level.TRACE, |
561 "Load archive for codebase <" + codebase + |
555 "Load archive for codebase <" + codebase + |
562 ">, file <" + tok + ">"); |
556 ">, file <" + tok + ">"); |
563 } |
557 } |
564 // Check which is the codebase to be used for loading the jar file. |
558 // Check which is the codebase to be used for loading the jar file. |
565 // If we are using the base MLet implementation then it will be |
559 // If we are using the base MLet implementation then it will be |
568 // return the appropriate one. |
562 // return the appropriate one. |
569 // |
563 // |
570 try { |
564 try { |
571 codebase = check(version, codebase, tok, elmt); |
565 codebase = check(version, codebase, tok, elmt); |
572 } catch (Exception ex) { |
566 } catch (Exception ex) { |
573 MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(), |
567 MLET_LOGGER.log(Level.DEBUG, |
574 mth, "Got unexpected exception", ex); |
568 "Got unexpected exception", ex); |
575 mbeans.add(ex); |
569 mbeans.add(ex); |
576 continue; |
570 continue; |
577 } |
571 } |
578 |
572 |
579 // Appends the specified JAR file URL to the list of |
573 // Appends the specified JAR file URL to the list of |
597 |
591 |
598 if (code != null && serName != null) { |
592 if (code != null && serName != null) { |
599 final String msg = |
593 final String msg = |
600 "CODE and OBJECT parameters cannot be specified at the " + |
594 "CODE and OBJECT parameters cannot be specified at the " + |
601 "same time in tag MLET"; |
595 "same time in tag MLET"; |
602 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, msg); |
596 MLET_LOGGER.log(Level.TRACE, msg); |
603 mbeans.add(new Error(msg)); |
597 mbeans.add(new Error(msg)); |
604 continue; |
598 continue; |
605 } |
599 } |
606 if (code == null && serName == null) { |
600 if (code == null && serName == null) { |
607 final String msg = |
601 final String msg = |
608 "Either CODE or OBJECT parameter must be specified in " + |
602 "Either CODE or OBJECT parameter must be specified in " + |
609 "tag MLET"; |
603 "tag MLET"; |
610 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, msg); |
604 MLET_LOGGER.log(Level.TRACE, msg); |
611 mbeans.add(new Error(msg)); |
605 mbeans.add(new Error(msg)); |
612 continue; |
606 continue; |
613 } |
607 } |
614 try { |
608 try { |
615 if (code != null) { |
609 if (code != null) { |
633 } |
627 } |
634 } else { |
628 } else { |
635 Object[] parms = objectPars.toArray(); |
629 Object[] parms = objectPars.toArray(); |
636 String[] signature = new String[signat.size()]; |
630 String[] signature = new String[signat.size()]; |
637 signat.toArray(signature); |
631 signat.toArray(signature); |
638 if (MLET_LOGGER.isLoggable(Level.FINEST)) { |
632 if (MLET_LOGGER.isLoggable(Level.TRACE)) { |
639 final StringBuilder strb = new StringBuilder(); |
633 final StringBuilder strb = new StringBuilder(); |
640 for (int i = 0; i < signature.length; i++) { |
634 for (int i = 0; i < signature.length; i++) { |
641 strb.append("\n\tSignature = ") |
635 strb.append("\n\tSignature = ") |
642 .append(signature[i]) |
636 .append(signature[i]) |
643 .append("\t\nParams = ") |
637 .append("\t\nParams = ") |
644 .append(parms[i]); |
638 .append(parms[i]); |
645 } |
639 } |
646 MLET_LOGGER.logp(Level.FINEST, |
640 MLET_LOGGER.log(Level.TRACE, strb::toString); |
647 MLet.class.getName(), |
|
648 mth, strb.toString()); |
|
649 } |
641 } |
650 if (name == null) { |
642 if (name == null) { |
651 objInst = |
643 objInst = |
652 server.createMBean(code, null, mletObjectName, |
644 server.createMBean(code, null, mletObjectName, |
653 parms, signature); |
645 parms, signature); |
666 server.registerMBean(o, new ObjectName(name)); |
658 server.registerMBean(o, new ObjectName(name)); |
667 } |
659 } |
668 objInst = new ObjectInstance(name, o.getClass().getName()); |
660 objInst = new ObjectInstance(name, o.getClass().getName()); |
669 } |
661 } |
670 } catch (ReflectionException ex) { |
662 } catch (ReflectionException ex) { |
671 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, |
663 MLET_LOGGER.log(Level.TRACE, "ReflectionException", ex); |
672 "ReflectionException", ex); |
|
673 mbeans.add(ex); |
664 mbeans.add(ex); |
674 continue; |
665 continue; |
675 } catch (InstanceAlreadyExistsException ex) { |
666 } catch (InstanceAlreadyExistsException ex) { |
676 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, |
667 MLET_LOGGER.log(Level.TRACE, |
677 "InstanceAlreadyExistsException", ex); |
668 "InstanceAlreadyExistsException", ex); |
678 mbeans.add(ex); |
669 mbeans.add(ex); |
679 continue; |
670 continue; |
680 } catch (MBeanRegistrationException ex) { |
671 } catch (MBeanRegistrationException ex) { |
681 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, |
672 MLET_LOGGER.log(Level.TRACE, "MBeanRegistrationException", ex); |
682 "MBeanRegistrationException", ex); |
|
683 mbeans.add(ex); |
673 mbeans.add(ex); |
684 continue; |
674 continue; |
685 } catch (MBeanException ex) { |
675 } catch (MBeanException ex) { |
686 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, |
676 MLET_LOGGER.log(Level.TRACE, "MBeanException", ex); |
687 "MBeanException", ex); |
|
688 mbeans.add(ex); |
677 mbeans.add(ex); |
689 continue; |
678 continue; |
690 } catch (NotCompliantMBeanException ex) { |
679 } catch (NotCompliantMBeanException ex) { |
691 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, |
680 MLET_LOGGER.log(Level.TRACE, |
692 "NotCompliantMBeanException", ex); |
681 "NotCompliantMBeanException", ex); |
693 mbeans.add(ex); |
682 mbeans.add(ex); |
694 continue; |
683 continue; |
695 } catch (InstanceNotFoundException ex) { |
684 } catch (InstanceNotFoundException ex) { |
696 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, |
685 MLET_LOGGER.log(Level.TRACE, |
697 "InstanceNotFoundException", ex); |
686 "InstanceNotFoundException", ex); |
698 mbeans.add(ex); |
687 mbeans.add(ex); |
699 continue; |
688 continue; |
700 } catch (IOException ex) { |
689 } catch (IOException ex) { |
701 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, |
690 MLET_LOGGER.log(Level.TRACE, "IOException", ex); |
702 "IOException", ex); |
|
703 mbeans.add(ex); |
691 mbeans.add(ex); |
704 continue; |
692 continue; |
705 } catch (SecurityException ex) { |
693 } catch (SecurityException ex) { |
706 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, |
694 MLET_LOGGER.log(Level.TRACE, "SecurityException", ex); |
707 "SecurityException", ex); |
|
708 mbeans.add(ex); |
695 mbeans.add(ex); |
709 continue; |
696 continue; |
710 } catch (Exception ex) { |
697 } catch (Exception ex) { |
711 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, |
698 MLET_LOGGER.log(Level.TRACE, "Exception", ex); |
712 "Exception", ex); |
|
713 mbeans.add(ex); |
699 mbeans.add(ex); |
714 continue; |
700 continue; |
715 } catch (Error ex) { |
701 } catch (Error ex) { |
716 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, |
702 MLET_LOGGER.log(Level.TRACE, "Error", ex); |
717 "Error", ex); |
|
718 mbeans.add(ex); |
703 mbeans.add(ex); |
719 continue; |
704 continue; |
720 } |
705 } |
721 mbeans.add(objInst); |
706 mbeans.add(objInst); |
722 } |
707 } |
935 * |
920 * |
936 **/ |
921 **/ |
937 Class<?> findClass(String name, ClassLoaderRepository clr) |
922 Class<?> findClass(String name, ClassLoaderRepository clr) |
938 throws ClassNotFoundException { |
923 throws ClassNotFoundException { |
939 Class<?> c = null; |
924 Class<?> c = null; |
940 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), "findClass", name); |
925 MLET_LOGGER.log(Level.TRACE, name); |
941 // Try looking in the JAR: |
926 // Try looking in the JAR: |
942 try { |
927 try { |
943 c = super.findClass(name); |
928 c = super.findClass(name); |
944 if (MLET_LOGGER.isLoggable(Level.FINER)) { |
929 if (MLET_LOGGER.isLoggable(Level.TRACE)) { |
945 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), |
930 MLET_LOGGER.log(Level.TRACE, |
946 "findClass", |
|
947 "Class " + name + " loaded through MLet classloader"); |
931 "Class " + name + " loaded through MLet classloader"); |
948 } |
932 } |
949 } catch (ClassNotFoundException e) { |
933 } catch (ClassNotFoundException e) { |
950 // Drop through |
934 // Drop through |
951 if (MLET_LOGGER.isLoggable(Level.FINEST)) { |
935 if (MLET_LOGGER.isLoggable(Level.TRACE)) { |
952 MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(), |
936 MLET_LOGGER.log(Level.TRACE, |
953 "findClass", |
|
954 "Class " + name + " not found locally"); |
937 "Class " + name + " not found locally"); |
955 } |
938 } |
956 } |
939 } |
957 // if we are not called from the ClassLoaderRepository |
940 // if we are not called from the ClassLoaderRepository |
958 if (c == null && delegateToCLR && clr != null) { |
941 if (c == null && delegateToCLR && clr != null) { |
959 // Try the classloader repository: |
942 // Try the classloader repository: |
960 // |
943 // |
961 try { |
944 try { |
962 if (MLET_LOGGER.isLoggable(Level.FINEST)) { |
945 if (MLET_LOGGER.isLoggable(Level.TRACE)) { |
963 MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(), |
946 MLET_LOGGER.log(Level.TRACE, |
964 "findClass", |
|
965 "Class " + name + " : looking in CLR"); |
947 "Class " + name + " : looking in CLR"); |
966 } |
948 } |
967 c = clr.loadClassBefore(this, name); |
949 c = clr.loadClassBefore(this, name); |
968 // The loadClassBefore method never returns null. |
950 // The loadClassBefore method never returns null. |
969 // If the class is not found we get an exception. |
951 // If the class is not found we get an exception. |
970 if (MLET_LOGGER.isLoggable(Level.FINER)) { |
952 if (MLET_LOGGER.isLoggable(Level.TRACE)) { |
971 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), |
953 MLET_LOGGER.log(Level.TRACE, |
972 "findClass", |
|
973 "Class " + name + " loaded through " + |
954 "Class " + name + " loaded through " + |
974 "the default classloader repository"); |
955 "the default classloader repository"); |
975 } |
956 } |
976 } catch (ClassNotFoundException e) { |
957 } catch (ClassNotFoundException e) { |
977 // Drop through |
958 // Drop through |
978 if (MLET_LOGGER.isLoggable(Level.FINEST)) { |
959 if (MLET_LOGGER.isLoggable(Level.TRACE)) { |
979 MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(), |
960 MLET_LOGGER.log(Level.TRACE, |
980 "findClass", |
|
981 "Class " + name + " not found in CLR"); |
961 "Class " + name + " not found in CLR"); |
982 } |
962 } |
983 } |
963 } |
984 } |
964 } |
985 if (c == null) { |
965 if (c == null) { |
986 MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(), |
966 MLET_LOGGER.log(Level.TRACE, "Failed to load class " + name); |
987 "findClass", "Failed to load class " + name); |
|
988 throw new ClassNotFoundException(name); |
967 throw new ClassNotFoundException(name); |
989 } |
968 } |
990 return c; |
969 return c; |
991 } |
970 } |
992 |
971 |
1039 String nativelibname = System.mapLibraryName(libname); |
1018 String nativelibname = System.mapLibraryName(libname); |
1040 |
1019 |
1041 // |
1020 // |
1042 // See if the native library is accessible as a resource through the JAR file. |
1021 // See if the native library is accessible as a resource through the JAR file. |
1043 // |
1022 // |
1044 if (MLET_LOGGER.isLoggable(Level.FINER)) { |
1023 if (MLET_LOGGER.isLoggable(Level.TRACE)) { |
1045 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, |
1024 MLET_LOGGER.log(Level.TRACE, |
1046 "Search " + libname + " in all JAR files"); |
1025 "Search " + libname + " in all JAR files"); |
1047 } |
1026 } |
1048 |
1027 |
1049 // First try to locate the library in the JAR file using only |
1028 // First try to locate the library in the JAR file using only |
1050 // the native library name. e.g. if user requested a load |
1029 // the native library name. e.g. if user requested a load |
1051 // for "foo" on Solaris SPARC 5.7 we try to load "libfoo.so" |
1030 // for "foo" on Solaris SPARC 5.7 we try to load "libfoo.so" |
1052 // from the JAR file. |
1031 // from the JAR file. |
1053 // |
1032 // |
1054 if (MLET_LOGGER.isLoggable(Level.FINER)) { |
1033 if (MLET_LOGGER.isLoggable(Level.TRACE)) { |
1055 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, |
1034 MLET_LOGGER.log(Level.TRACE, |
1056 "loadLibraryAsResource(" + nativelibname + ")"); |
1035 "loadLibraryAsResource(" + nativelibname + ")"); |
1057 } |
1036 } |
1058 abs_path = loadLibraryAsResource(nativelibname); |
1037 abs_path = loadLibraryAsResource(nativelibname); |
1059 if (abs_path != null) { |
1038 if (abs_path != null) { |
1060 if (MLET_LOGGER.isLoggable(Level.FINER)) { |
1039 if (MLET_LOGGER.isLoggable(Level.TRACE)) { |
1061 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, |
1040 MLET_LOGGER.log(Level.TRACE, |
1062 nativelibname + " loaded, absolute path = " + abs_path); |
1041 nativelibname + " loaded, absolute path = " + abs_path); |
1063 } |
1042 } |
1064 return abs_path; |
1043 return abs_path; |
1065 } |
1044 } |
1066 |
1045 |
1071 // |
1050 // |
1072 nativelibname = removeSpace(System.getProperty("os.name")) + File.separator + |
1051 nativelibname = removeSpace(System.getProperty("os.name")) + File.separator + |
1073 removeSpace(System.getProperty("os.arch")) + File.separator + |
1052 removeSpace(System.getProperty("os.arch")) + File.separator + |
1074 removeSpace(System.getProperty("os.version")) + File.separator + |
1053 removeSpace(System.getProperty("os.version")) + File.separator + |
1075 "lib" + File.separator + nativelibname; |
1054 "lib" + File.separator + nativelibname; |
1076 if (MLET_LOGGER.isLoggable(Level.FINER)) { |
1055 if (MLET_LOGGER.isLoggable(Level.TRACE)) { |
1077 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, |
1056 MLET_LOGGER.log(Level.TRACE, |
1078 "loadLibraryAsResource(" + nativelibname + ")"); |
1057 "loadLibraryAsResource(" + nativelibname + ")"); |
1079 } |
1058 } |
1080 |
1059 |
1081 abs_path = loadLibraryAsResource(nativelibname); |
1060 abs_path = loadLibraryAsResource(nativelibname); |
1082 if (abs_path != null) { |
1061 if (abs_path != null) { |
1083 if (MLET_LOGGER.isLoggable(Level.FINER)) { |
1062 if (MLET_LOGGER.isLoggable(Level.TRACE)) { |
1084 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, |
1063 MLET_LOGGER.log(Level.TRACE, |
1085 nativelibname + " loaded, absolute path = " + abs_path); |
1064 nativelibname + " loaded, absolute path = " + abs_path); |
1086 } |
1065 } |
1087 return abs_path; |
1066 return abs_path; |
1088 } |
1067 } |
1089 |
1068 |
1090 // |
1069 // |
1091 // All paths exhausted, library not found in JAR file. |
1070 // All paths exhausted, library not found in JAR file. |
1092 // |
1071 // |
1093 |
1072 |
1094 if (MLET_LOGGER.isLoggable(Level.FINER)) { |
1073 if (MLET_LOGGER.isLoggable(Level.TRACE)) { |
1095 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, |
1074 MLET_LOGGER.log(Level.TRACE, |
1096 libname + " not found in any JAR file"); |
1075 libname + " not found in any JAR file"); |
1097 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), mth, |
1076 MLET_LOGGER.log(Level.TRACE, |
1098 "Search " + libname + " along the path " + |
1077 "Search " + libname + " along the path " + |
1099 "specified as the java.library.path property"); |
1078 "specified as the java.library.path property"); |
1100 } |
1079 } |
1101 |
1080 |
1102 // Let the VM search the library along the path |
1081 // Let the VM search the library along the path |
1125 if (tmpFile == null) return null; |
1104 if (tmpFile == null) return null; |
1126 final File tmpDirFile = tmpFile.getParentFile(); |
1105 final File tmpDirFile = tmpFile.getParentFile(); |
1127 if (tmpDirFile == null) return null; |
1106 if (tmpDirFile == null) return null; |
1128 return tmpDirFile.getAbsolutePath(); |
1107 return tmpDirFile.getAbsolutePath(); |
1129 } catch (Exception x) { |
1108 } catch (Exception x) { |
1130 MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(), |
1109 MLET_LOGGER.log(Level.DEBUG, |
1131 "getTmpDir", "Failed to determine system temporary dir"); |
1110 "Failed to determine system temporary dir"); |
1132 return null; |
1111 return null; |
1133 } finally { |
1112 } finally { |
1134 // Cleanup ... |
1113 // Cleanup ... |
1135 if (tmpFile!=null) { |
1114 if (tmpFile!=null) { |
1136 try { |
1115 try { |
1137 boolean deleted = tmpFile.delete(); |
1116 boolean deleted = tmpFile.delete(); |
1138 if (!deleted) { |
1117 if (!deleted) { |
1139 MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(), |
1118 MLET_LOGGER.log(Level.DEBUG, |
1140 "getTmpDir", "Failed to delete temp file"); |
1119 "Failed to delete temp file"); |
1141 } |
1120 } |
1142 } catch (Exception x) { |
1121 } catch (Exception x) { |
1143 MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(), |
1122 MLET_LOGGER.log(Level.DEBUG, |
1144 "getTmpDir", "Failed to delete temporary file", x); |
1123 "Failed to delete temporary file", x); |
1145 } |
1124 } |
1146 } |
1125 } |
1147 } |
1126 } |
1148 } |
1127 } |
1149 |
1128 |
1246 private Object loadSerializedObject(URL codebase, String filename) |
1224 private Object loadSerializedObject(URL codebase, String filename) |
1247 throws IOException, ClassNotFoundException { |
1225 throws IOException, ClassNotFoundException { |
1248 if (filename != null) { |
1226 if (filename != null) { |
1249 filename = filename.replace(File.separatorChar,'/'); |
1227 filename = filename.replace(File.separatorChar,'/'); |
1250 } |
1228 } |
1251 if (MLET_LOGGER.isLoggable(Level.FINER)) { |
1229 if (MLET_LOGGER.isLoggable(Level.TRACE)) { |
1252 MLET_LOGGER.logp(Level.FINER, MLet.class.getName(), |
1230 MLET_LOGGER.log(Level.TRACE, codebase.toString() + filename); |
1253 "loadSerializedObject", codebase.toString() + filename); |
|
1254 } |
1231 } |
1255 InputStream is = getResourceAsStream(filename); |
1232 InputStream is = getResourceAsStream(filename); |
1256 if (is != null) { |
1233 if (is != null) { |
1257 try { |
1234 try { |
1258 ObjectInputStream ois = new MLetObjectInputStream(is, this); |
1235 ObjectInputStream ois = new MLetObjectInputStream(is, this); |
1259 Object serObject = ois.readObject(); |
1236 Object serObject = ois.readObject(); |
1260 ois.close(); |
1237 ois.close(); |
1261 return serObject; |
1238 return serObject; |
1262 } catch (IOException e) { |
1239 } catch (IOException e) { |
1263 if (MLET_LOGGER.isLoggable(Level.FINEST)) { |
1240 if (MLET_LOGGER.isLoggable(Level.DEBUG)) { |
1264 MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(), |
1241 MLET_LOGGER.log(Level.DEBUG, |
1265 "loadSerializedObject", |
|
1266 "Exception while deserializing " + filename, e); |
1242 "Exception while deserializing " + filename, e); |
1267 } |
1243 } |
1268 throw e; |
1244 throw e; |
1269 } catch (ClassNotFoundException e) { |
1245 } catch (ClassNotFoundException e) { |
1270 if (MLET_LOGGER.isLoggable(Level.FINEST)) { |
1246 if (MLET_LOGGER.isLoggable(Level.DEBUG)) { |
1271 MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(), |
1247 MLET_LOGGER.log(Level.DEBUG, |
1272 "loadSerializedObject", |
|
1273 "Exception while deserializing " + filename, e); |
1248 "Exception while deserializing " + filename, e); |
1274 } |
1249 } |
1275 throw e; |
1250 throw e; |
1276 } |
1251 } |
1277 } else { |
1252 } else { |
1278 if (MLET_LOGGER.isLoggable(Level.FINEST)) { |
1253 if (MLET_LOGGER.isLoggable(Level.DEBUG)) { |
1279 MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(), |
1254 MLET_LOGGER.log(Level.DEBUG, "Error: File " + filename + |
1280 "loadSerializedObject", "Error: File " + filename + |
|
1281 " containing serialized object not found"); |
1255 " containing serialized object not found"); |
1282 } |
1256 } |
1283 throw new Error("File " + filename + " containing serialized object not found"); |
1257 throw new Error("File " + filename + " containing serialized object not found"); |
1284 } |
1258 } |
1285 } |
1259 } |
1298 Object[] oo = new Object[1]; |
1272 Object[] oo = new Object[1]; |
1299 oo[0]=param; |
1273 oo[0]=param; |
1300 return(cons.newInstance(oo)); |
1274 return(cons.newInstance(oo)); |
1301 |
1275 |
1302 } catch (Exception e) { |
1276 } catch (Exception e) { |
1303 MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(), |
1277 MLET_LOGGER.log(Level.DEBUG, "Got unexpected exception", e); |
1304 "constructParameter", "Got unexpected exception", e); |
|
1305 } |
1278 } |
1306 } |
1279 } |
1307 if (type.compareTo("java.lang.Boolean") == 0) |
1280 if (type.compareTo("java.lang.Boolean") == 0) |
1308 return Boolean.valueOf(param); |
1281 return Boolean.valueOf(param); |
1309 if (type.compareTo("java.lang.Byte") == 0) |
1282 if (type.compareTo("java.lang.Byte") == 0) |