1 23 24 37 38 package com.sun.appserv.server.util; 39 40 import java.util.Hashtable ; 41 import java.util.logging.Level ; 42 import java.util.logging.Logger ; 43 import com.sun.appserv.BytecodePreprocessor; 44 import com.sun.common.util.logging.LogDomains; 45 46 52 public class PreprocessorUtil { 53 54 private static boolean _preprocessorEnabled = false; 55 private static BytecodePreprocessor[] _preprocessor; 56 57 64 public static boolean init (String [] ppClassNames) { 65 if (ppClassNames != null) { 66 setupPreprocessor(ppClassNames); 67 } 68 return _preprocessorEnabled; 69 } 70 71 77 public static byte[] processClass (String className, byte[] classBytes) { 78 Logger _logger = LogDomains.getLogger(LogDomains.CMN_LOGGER); 79 byte[] goodBytes = classBytes; 80 if (_preprocessorEnabled) { 81 if (_preprocessor != null) { 82 for (int i=0; i < _preprocessor.length; i++) { 84 classBytes = 85 _preprocessor[i].preprocess(className, classBytes); 86 _logger.fine("[PreprocessorUtil.processClass] Preprocessor " 87 + i + " Processed Class: " + className); 88 if (classBytes != null){ 90 goodBytes = classBytes; 91 } 92 else{ 93 _logger.log(Level.SEVERE, 94 "bytecodepreprocessor.preprocess_failed", 95 new String [] {className, 96 _preprocessor[i].getClass().getName()}); 97 98 if (i == 0){ 100 _logger.log( 101 Level.SEVERE, 102 "bytecodepreprocessor.resetting_original", 103 className); 104 } 105 else{ 107 _logger.log( 108 Level.SEVERE, 109 "bytecodepreprocessor.resetting_last_good", 110 className); 111 } 112 } 113 } 114 } 115 } 116 return goodBytes; 117 } 118 119 private synchronized static void setupPreprocessor(String [] ppClassNames) { 120 Logger _logger = LogDomains.getLogger(LogDomains.CMN_LOGGER); 121 122 if (_preprocessor != null) 123 return; 125 126 try { 127 _preprocessor = new BytecodePreprocessor[ppClassNames.length]; 128 for (int i = 0; i < ppClassNames.length; i++) { 129 String ppClassName = ppClassNames[i].trim(); 130 Class ppClass = Class.forName(ppClassName); 131 if (ppClass != null){ 132 _preprocessor[i] = (BytecodePreprocessor) 133 ppClass.newInstance(); 134 if (_preprocessor[i] instanceof BytecodePreprocessor){ 135 _preprocessor[i] = 136 (BytecodePreprocessor)_preprocessor[i]; 137 _preprocessorEnabled = true; 138 } else { 139 _logger.log(Level.SEVERE, 140 "bytecodepreprocessor.invalid_type", 141 ppClassName); 142 _logger.log(Level.SEVERE, 143 "bytecodepreprocessor.disabled"); 144 _preprocessorEnabled = false; 145 } 146 } 147 if (_preprocessor[i] != null){ 148 if (!_preprocessor[i].initialize(new Hashtable ())) { 149 _logger.log(Level.SEVERE, 150 "bytecodepreprocessor.failed_init", 151 ppClassName); 152 _logger.log(Level.SEVERE, 153 "bytecodepreprocessor.disabled"); 154 _preprocessorEnabled = false; 155 } 156 } else { 157 _logger.log(Level.SEVERE, 158 "bytecodepreprocessor.failed_init", 159 ppClassName); 160 _logger.log(Level.SEVERE, 161 "bytecodepreprocessor.disabled"); 162 _preprocessorEnabled = false; 163 } 164 } 165 } catch (Throwable t) { 166 _logger.log(Level.SEVERE, "bytecodepreprocessor.setup_ex", t); 167 _logger.log(Level.SEVERE, "bytecodepreprocessor.disabled"); 168 _preprocessorEnabled = false; 169 return; 170 } 171 } 172 173 177 public static boolean isPreprocessorEnabled() { 178 return _preprocessorEnabled; 179 } 180 } 181 | Popular Tags |