| | |
| | | */ |
| | | public final class ClassLoaderProvider { |
| | | |
| | | private static final LocalizedLogger adminLogger = LocalizedLogger.getLocalizedLogger(AdminMessages.resourceName()); |
| | | private static final LocalizedLogger adminLogger = LocalizedLogger.getLocalizedLogger(AdminMessages |
| | | .resourceName()); |
| | | private static final Logger debugLogger = LoggerFactory.getLogger(ClassLoaderProvider.class); |
| | | |
| | | /** |
| | |
| | | * @throws SecurityException |
| | | * If a required system property value cannot be accessed. |
| | | */ |
| | | public void addJarFile(File jarFile) throws SecurityException, MalformedURLException { |
| | | public void addJarFile(File jarFile) throws MalformedURLException { |
| | | addURL(jarFile.toURI().toURL()); |
| | | } |
| | | |
| | |
| | | |
| | | // The attribute names for build information is name, version and revision |
| | | // number |
| | | private static final String[] BUILD_INFORMATION_ATTRIBUTE_NAMES = new String[] { |
| | | Attributes.Name.EXTENSION_NAME.toString(), Attributes.Name.IMPLEMENTATION_VERSION.toString(), |
| | | private static final String[] BUILD_INFORMATION_ATTRIBUTE_NAMES = |
| | | new String[] { Attributes.Name.EXTENSION_NAME.toString(), Attributes.Name.IMPLEMENTATION_VERSION.toString(), |
| | | REVISION_NUMBER }; |
| | | |
| | | /** |
| | |
| | | * If one of the extension names was not a single relative path |
| | | * name element or was an absolute path. |
| | | */ |
| | | public synchronized void addExtension(String... extensions) throws InitializationException, IllegalStateException, |
| | | IllegalArgumentException { |
| | | public synchronized void addExtension(String... extensions) throws InitializationException { |
| | | Reject.ifNull(extensions); |
| | | |
| | | if (loader == null) { |
| | |
| | | * @throws IllegalStateException |
| | | * If this class loader provider is already disabled. |
| | | */ |
| | | public synchronized void disable() throws IllegalStateException { |
| | | public synchronized void disable() { |
| | | if (loader == null) { |
| | | throw new IllegalStateException("Class loader provider already disabled."); |
| | | } |
| | |
| | | * @throws IllegalStateException |
| | | * If this class loader provider is already enabled. |
| | | */ |
| | | public synchronized void enable() throws InitializationException, IllegalStateException { |
| | | public synchronized void enable() throws InitializationException { |
| | | enable(RootCfgDefn.class.getClassLoader()); |
| | | } |
| | | |
| | |
| | | * @throws IllegalStateException |
| | | * If this class loader provider is already enabled. |
| | | */ |
| | | public synchronized void enable(ClassLoader parent) throws InitializationException, IllegalStateException { |
| | | public synchronized void enable(ClassLoader parent) throws InitializationException { |
| | | if (loader != null) { |
| | | throw new IllegalStateException("Class loader provider already enabled."); |
| | | } |
| | |
| | | loader.addJarFile(extension); |
| | | } catch (Exception e) { |
| | | debugLogger.trace("Unable to register the jar file with the class loader", e); |
| | | LocalizableMessage message = ERR_ADMIN_CANNOT_OPEN_JAR_FILE.get(extension.getName(), |
| | | extension.getParent(), stackTraceToSingleLineString(e, DynamicConstants.DEBUG_BUILD)); |
| | | LocalizableMessage message = |
| | | ERR_ADMIN_CANNOT_OPEN_JAR_FILE.get(extension.getName(), extension.getParent(), |
| | | stackTraceToSingleLineString(e, DynamicConstants.DEBUG_BUILD)); |
| | | throw new InitializationException(message); |
| | | } |
| | | jarFiles.add(extension); |
| | |
| | | * <code>null</code> if there is no information available. |
| | | */ |
| | | public String printExtensionInformation() { |
| | | File extensionsPath = new File(new StringBuilder(DirectoryServer.getServerRoot()).append(File.separator) |
| | | .append(LIB_DIR).append(File.separator).append(EXTENSIONS_DIR).toString()); |
| | | File extensionsPath = |
| | | new File(new StringBuilder(DirectoryServer.getServerRoot()).append(File.separator).append(LIB_DIR) |
| | | .append(File.separator).append(EXTENSIONS_DIR).toString()); |
| | | |
| | | if (!extensionsPath.exists() || !extensionsPath.isDirectory()) { |
| | | // no extensions' directory |
| | |
| | | if (!extensionsPath.isDirectory()) { |
| | | // The extensions directory is not a directory. This is more |
| | | // critical. |
| | | LocalizableMessage message = ERR_ADMIN_EXTENSIONS_DIR_NOT_DIRECTORY.get(String.valueOf(extensionsPath)); |
| | | LocalizableMessage message = |
| | | ERR_ADMIN_EXTENSIONS_DIR_NOT_DIRECTORY.get(String.valueOf(extensionsPath)); |
| | | throw new InitializationException(message); |
| | | } |
| | | |
| | |
| | | throw e; |
| | | } catch (Exception e) { |
| | | debugLogger.trace("Unable to initialize all extensions", e); |
| | | LocalizableMessage message = ERR_ADMIN_EXTENSIONS_CANNOT_LIST_FILES.get(String.valueOf(extensionsPath), |
| | | LocalizableMessage message = |
| | | ERR_ADMIN_EXTENSIONS_CANNOT_LIST_FILES.get(String.valueOf(extensionsPath), |
| | | stackTraceToSingleLineString(e, DynamicConstants.DEBUG_BUILD)); |
| | | throw new InitializationException(message, e); |
| | | } |
| | |
| | | loadDefinitionClasses(is); |
| | | } catch (InitializationException e) { |
| | | debugLogger.trace("Unable to initialize core components", e); |
| | | LocalizableMessage message = ERR_CLASS_LOADER_CANNOT_LOAD_CORE.get(CORE_MANIFEST, |
| | | LocalizableMessage message = |
| | | ERR_CLASS_LOADER_CANNOT_LOAD_CORE.get(CORE_MANIFEST, |
| | | stackTraceToSingleLineString(e, DynamicConstants.DEBUG_BUILD)); |
| | | throw new InitializationException(message); |
| | | } |
| | |
| | | is = jarFile.getInputStream(entry); |
| | | } catch (Exception e) { |
| | | debugLogger.trace("Unable to get input stream from jar", e); |
| | | LocalizableMessage message = ERR_ADMIN_CANNOT_READ_EXTENSION_MANIFEST.get(EXTENSION_MANIFEST, |
| | | jarFile.getName(), stackTraceToSingleLineString(e, DynamicConstants.DEBUG_BUILD)); |
| | | LocalizableMessage message = |
| | | ERR_ADMIN_CANNOT_READ_EXTENSION_MANIFEST.get(EXTENSION_MANIFEST, jarFile.getName(), |
| | | stackTraceToSingleLineString(e, DynamicConstants.DEBUG_BUILD)); |
| | | throw new InitializationException(message); |
| | | } |
| | | |
| | |
| | | loadDefinitionClasses(is); |
| | | } catch (InitializationException e) { |
| | | debugLogger.trace("Unable to load classes from input stream", e); |
| | | LocalizableMessage message = ERR_CLASS_LOADER_CANNOT_LOAD_EXTENSION.get(jarFile.getName(), |
| | | EXTENSION_MANIFEST, stackTraceToSingleLineString(e, DynamicConstants.DEBUG_BUILD)); |
| | | LocalizableMessage message = |
| | | ERR_CLASS_LOADER_CANNOT_LOAD_EXTENSION.get(jarFile.getName(), EXTENSION_MANIFEST, |
| | | stackTraceToSingleLineString(e, DynamicConstants.DEBUG_BUILD)); |
| | | throw new InitializationException(message); |
| | | } |
| | | try { |
| | | // Log build information of extensions in the error log |
| | | String[] information = getBuildInformation(jarFile); |
| | | LocalizableMessage message = NOTE_LOG_EXTENSION_INFORMATION.get(jarFile.getName(), information[1], |
| | | information[2]); |
| | | LocalizableMessage message = |
| | | NOTE_LOG_EXTENSION_INFORMATION.get(jarFile.getName(), information[1], information[2]); |
| | | LocalizedLogger.getLocalizedLogger(message.resourceName()).error(message); |
| | | } catch (Exception e) { |
| | | // Do not log information for that extension |
| | |
| | | */ |
| | | private void loadDefinitionClasses(InputStream is) throws InitializationException { |
| | | BufferedReader reader = new BufferedReader(new InputStreamReader(is)); |
| | | List<AbstractManagedObjectDefinition<?, ?>> definitions = new LinkedList<AbstractManagedObjectDefinition<?, ?>>(); |
| | | List<AbstractManagedObjectDefinition<?, ?>> definitions = |
| | | new LinkedList<AbstractManagedObjectDefinition<?, ?>>(); |
| | | while (true) { |
| | | String className; |
| | | try { |
| | | className = reader.readLine(); |
| | | } catch (IOException e) { |
| | | LocalizableMessage msg = ERR_CLASS_LOADER_CANNOT_READ_MANIFEST_FILE.get(String.valueOf(e.getMessage())); |
| | | LocalizableMessage msg = |
| | | ERR_CLASS_LOADER_CANNOT_READ_MANIFEST_FILE.get(String.valueOf(e.getMessage())); |
| | | throw new InitializationException(msg, e); |
| | | } |
| | | |
| | |
| | | try { |
| | | theClass = Class.forName(className, true, loader); |
| | | } catch (Exception e) { |
| | | LocalizableMessage msg = ERR_CLASS_LOADER_CANNOT_LOAD_CLASS.get(className, |
| | | String.valueOf(e.getMessage())); |
| | | LocalizableMessage msg = |
| | | ERR_CLASS_LOADER_CANNOT_LOAD_CLASS.get(className, String.valueOf(e.getMessage())); |
| | | throw new InitializationException(msg, e); |
| | | } |
| | | if (AbstractManagedObjectDefinition.class.isAssignableFrom(theClass)) { |
| | |
| | | try { |
| | | method = theClass.getMethod("getInstance"); |
| | | } catch (Exception e) { |
| | | LocalizableMessage msg = ERR_CLASS_LOADER_CANNOT_FIND_GET_INSTANCE_METHOD.get(className, |
| | | LocalizableMessage msg = |
| | | ERR_CLASS_LOADER_CANNOT_FIND_GET_INSTANCE_METHOD.get(className, |
| | | String.valueOf(e.getMessage())); |
| | | throw new InitializationException(msg, e); |
| | | } |
| | |
| | | try { |
| | | d = (AbstractManagedObjectDefinition<?, ?>) method.invoke(null); |
| | | } catch (Exception e) { |
| | | LocalizableMessage msg = ERR_CLASS_LOADER_CANNOT_INVOKE_GET_INSTANCE_METHOD.get(className, |
| | | LocalizableMessage msg = |
| | | ERR_CLASS_LOADER_CANNOT_INVOKE_GET_INSTANCE_METHOD.get(className, |
| | | String.valueOf(e.getMessage())); |
| | | throw new InitializationException(msg, e); |
| | | } |
| | |
| | | try { |
| | | d.initialize(); |
| | | } catch (Exception e) { |
| | | LocalizableMessage msg = ERR_CLASS_LOADER_CANNOT_INITIALIZE_DEFN.get(d.getName(), d.getClass() |
| | | .getName(), String.valueOf(e.getMessage())); |
| | | LocalizableMessage msg = |
| | | ERR_CLASS_LOADER_CANNOT_INITIALIZE_DEFN.get(d.getName(), d.getClass().getName(), |
| | | String.valueOf(e.getMessage())); |
| | | throw new InitializationException(msg, e); |
| | | } |
| | | } |
| | |
| | | } catch (Exception e) { |
| | | debugLogger.trace("Unable to load jar file: " + jar, e); |
| | | |
| | | LocalizableMessage message = ERR_ADMIN_CANNOT_OPEN_JAR_FILE.get(jar.getName(), jar.getParent(), |
| | | LocalizableMessage message = |
| | | ERR_ADMIN_CANNOT_OPEN_JAR_FILE.get(jar.getName(), jar.getParent(), |
| | | stackTraceToSingleLineString(e, DynamicConstants.DEBUG_BUILD)); |
| | | throw new InitializationException(message); |
| | | } |