r78 - in trunk: mapstoragemanagerarch/src/main/java/org/nuiton/mapstoragemanager/core src/site/doc/analyse
Author: gcrieloue Date: 2010-02-11 10:53:47 +0100 (Thu, 11 Feb 2010) New Revision: 78 Removed: trunk/mapstoragemanagerarch/src/main/java/org/nuiton/mapstoragemanager/core/Core.java trunk/mapstoragemanagerarch/src/main/java/org/nuiton/mapstoragemanager/core/MainTestCore.java trunk/mapstoragemanagerarch/src/main/java/org/nuiton/mapstoragemanager/core/PluginLoader.java Modified: trunk/src/site/doc/analyse/msm.zargo Log: Suppression de l'ancien prototype d'archi ?\195?\160 plugins; mise ?\195?\160 jour du diagramme uml. Deleted: trunk/mapstoragemanagerarch/src/main/java/org/nuiton/mapstoragemanager/core/Core.java =================================================================== --- trunk/mapstoragemanagerarch/src/main/java/org/nuiton/mapstoragemanager/core/Core.java 2010-02-11 09:48:35 UTC (rev 77) +++ trunk/mapstoragemanagerarch/src/main/java/org/nuiton/mapstoragemanager/core/Core.java 2010-02-11 09:53:47 UTC (rev 78) @@ -1,112 +0,0 @@ -package org.nuiton.mapstoragemanager.core; - -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.util.ArrayList; -import java.util.List; -import java.util.HashMap; -import java.util.Map; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.nuiton.mapstoragemanager.plugins.BigTable; - -/** - * Class Core. - * This class permit to manage plugins. - * @author Gilles Crieloue - * - */ -public class Core { - - /** - * Logger. - */ - private static final Log LOG = LogFactory.getLog(Core.class); - - /** - * A map "name of the plugin" - "plugin instance". - */ - private Map < String, BigTable > bases = - new HashMap < String, BigTable > (); - - /** - * The plugin loader. - */ - private PluginLoader pluginLoader = null; - - /** - * Class constructor. - */ - public Core() { - try { - File directory = new File( - Messages.getString("Config.url")); - pluginLoader = new PluginLoader( - new URL[]{directory.toURI().toURL()}, - this.getClass().getClassLoader()); - } catch (Exception e) { - //e.printStackTrace(); - LOG.error(e.toString(), e); - } - try { - loadAvailableBases(); - } catch (IOException e) { - //e.printStackTrace(); - LOG.error(e.toString(), e); - } - } - - /** - * Loads all the plugins (IBigTable implementations). - * @throws IOException if the classes are not loaded correctly - */ - private void loadAvailableBases() throws IOException { - for (Class < ? > tmpClass : pluginLoader.getPluginsClasses()) { - for (Class < ? > i : tmpClass.getInterfaces()) { - /* - * If the class implements the IBigTable - * interface, an instance is created - * and added to the list - */ - if (i.getName().equals("plugins.IBigTable")) { - try { - bases.put(tmpClass.getName(), - (BigTable) tmpClass.newInstance()); - } catch (InstantiationException e) { - //e.printStackTrace(); - LOG.error(e.toString(), e); - } catch (IllegalAccessException e) { - //e.printStackTrace(); - LOG.error(e.toString(), e); - } - } - } - } - } - - /** - * Returns an ArrayList of all the plugins instances. - * @return an ArrayList of all the plugins instances - */ - public final List < BigTable > getAvailableBases() { - ArrayList < BigTable > bigTables = new ArrayList < BigTable > (); - for (BigTable bigTable : bases.values()) { - bigTables.add(bigTable); - } - return bigTables; - } - - /** - * Returns an ArrayList of all the plugins class names. - * @return an ArrayList of all the plugins class names - */ - public final List < String > listPlugins() { - ArrayList < String > s = new ArrayList<String>(); - for (String plugin : this.bases.keySet()) { - s.add(plugin); - } - return s; - } -} Deleted: trunk/mapstoragemanagerarch/src/main/java/org/nuiton/mapstoragemanager/core/MainTestCore.java =================================================================== --- trunk/mapstoragemanagerarch/src/main/java/org/nuiton/mapstoragemanager/core/MainTestCore.java 2010-02-11 09:48:35 UTC (rev 77) +++ trunk/mapstoragemanagerarch/src/main/java/org/nuiton/mapstoragemanager/core/MainTestCore.java 2010-02-11 09:53:47 UTC (rev 78) @@ -1,35 +0,0 @@ -package org.nuiton.mapstoragemanager.core; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.mapstoragemanager.plugins.BigTable; - -public class MainTestCore { - - /** - * Logger. - */ - private static final Log LOG = LogFactory.getLog(MainTestCore.class); - - /** - * test for plugins loading and basic functions. - * @param args args - */ - public static void main(final String[] args) { - - Core core = new Core(); - - LOG.info("Plugins disponibles"); - for (String base : core.listPlugins()) { - LOG.info("* " + base); - } - - /* Test du plugins */ - - for (BigTable bigTable : core.getAvailableBases()) { - bigTable.put("clé", "valeur"); - LOG.info(bigTable.get("clé")); - } - - } -} Deleted: trunk/mapstoragemanagerarch/src/main/java/org/nuiton/mapstoragemanager/core/PluginLoader.java =================================================================== --- trunk/mapstoragemanagerarch/src/main/java/org/nuiton/mapstoragemanager/core/PluginLoader.java 2010-02-11 09:48:35 UTC (rev 77) +++ trunk/mapstoragemanagerarch/src/main/java/org/nuiton/mapstoragemanager/core/PluginLoader.java 2010-02-11 09:53:47 UTC (rev 78) @@ -1,208 +0,0 @@ -package org.nuiton.mapstoragemanager.core; - -import java.io.File; - -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.List; -import java.util.Enumeration; -import java.util.jar.JarEntry; -import java.util.jar.JarFile; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * This class loads the plugins. - * @author Crieloue Gilles - * - */ -public class PluginLoader extends URLClassLoader { - - /** - * Logger. - */ - private static final Log LOG = LogFactory.getLog(PluginLoader.class); - - /** - * The plugin classes. - */ - private List < Class < ? > > classes = - new ArrayList < Class < ? > > (); - - /** - * Class constructor. - * @param urls for the class loader - * @param classLoader the parent ClassLoader - * @throws Exception if the directory URL doesn't exist - */ - public PluginLoader(final URL[] urls, final ClassLoader classLoader) - throws Exception { - super(urls, classLoader); - - File directory = new File(urls[0].getFile()); - if (!directory.exists()) { - throw new Exception("No directory " + urls[0]); - } - - // adds all the directory jars to the ClassLoader -// for (File file : directory.listFiles()) { -// if (file.getAbsolutePath().endsWith(".jar")) { -// try { -// this.addURL(file.toURI().toURL()); -// } catch (MalformedURLException e) { -// //e.printStackTrace(); -// LOG.error(e.toString(), e); -// } -// } -// } - this.addDirectoryJarsToClassLoader(directory); - - -// File libs = new File("plugins/libs"); -// if (!libs.exists()) { -// throw new Exception("No directory " + libs.getAbsolutePath()); -// } -// -// // adds all the libs jars to the ClassLoader -// for (File file : libs.listFiles()) { -// if (file.getAbsolutePath().endsWith(".jar")) { -// try { -// LOG.info("== LIB " + file.getAbsolutePath() + "..."); -// this.addURL(file.toURI().toURL()); -// } catch (MalformedURLException e) { -// //e.printStackTrace(); -// LOG.error(e.toString(), e); -// } -// } -// } - this.addLibsJarsToClassLoader(); - - // loads the jars classes - for (File file : directory.listFiles()) { - if (file.getAbsolutePath().endsWith(".jar")) { - LOG.info("== JAR " + file.getAbsolutePath() + "..."); - loadJarClasses(file.getAbsolutePath()); - } - } - } - - /** - * Add directory jars to ClassLoader. - * adds all the directory jars to the ClassLoader. - * @param directory directory - */ - private void addDirectoryJarsToClassLoader(File directory) { - for (File file : directory.listFiles()) { - if (file.getAbsolutePath().endsWith(".jar")) { - try { - this.addURL(file.toURI().toURL()); - } catch (MalformedURLException e) { - LOG.error(e.toString(), e); - } - } - } - - } - - /** - * Add libs jars to ClassLoader. - * Adds all the libs jars to the ClassLoader. - */ - private void addLibsJarsToClassLoader() throws Exception { - - File libs = new File("plugins/libs"); - if (!libs.exists()) { - throw new Exception("No directory " + libs.getAbsolutePath()); - } - - // adds all the libs jars to the ClassLoader - for (File file : libs.listFiles()) { - if (file.getAbsolutePath().endsWith(".jar")) { - try { - LOG.info("== LIB " + file.getAbsolutePath() + "..."); - this.addURL(file.toURI().toURL()); - } catch (MalformedURLException e) { - LOG.error(e.toString(), e); - } - } - } - } - - /** - * Loads all the classes of a jar. - * (adds the path to the classLoader - * and adds the class to the classes list) - * @param jarPath the jar path - */ - private void loadJarClasses(final String jarPath) { - - File file = new File(jarPath); - LOG.info("Loading " + jarPath + "..."); - - JarFile jar = null; - try { - jar = new JarFile(file.getAbsolutePath()); - } catch (IOException e) { - //e.printStackTrace(); - LOG.error(e.toString(), e); - } - -// Enumeration < JarEntry > entries2 = jar.entries(); -// while (entries2.hasMoreElements()) { -// JarEntry entry = entries2.nextElement(); -// if (entry.getName().startsWith("libs/")) { -// try { -// String fileName = entry.getName(); -// String entryURL = "jar:jar:file:" -// + jarPath + "!/" + fileName + "!/"; -// logger.info("== LIB " + fileName -// + " (" + entryURL + ") ..."); -// this.addURL(new URL(entryURL)); -// } catch (MalformedURLException e) { -// e.printStackTrace(); -// } -// } -// } - - Enumeration < JarEntry > entries = jar.entries(); - - // adds the classes from the jar to the classes list - while (entries.hasMoreElements()) { - Class < ? > tmpClass = null; - JarEntry entry = entries.nextElement(); - String fileName = entry.toString(); - String extension = ".class"; - - if (fileName.endsWith(extension)) { - LOG.info("Loading " + fileName + "..."); - - // formating file name - fileName = fileName.substring(0, fileName.length() - - extension.length()); - fileName = fileName.replaceAll("/", "."); - - // loading class - try { - tmpClass = this.loadClass(fileName); - //Class.forName(fileName, true, this); - } catch (ClassNotFoundException e) { - LOG.error(e.toString(),e); - } - - classes.add(tmpClass); - } - } - } - - /** - * Returns the plugin classes. - * @return the plugin classes - */ - public final List < Class < ? > > getPluginsClasses() { - return classes; - } - -} Modified: trunk/src/site/doc/analyse/msm.zargo =================================================================== (Binary files differ)
participants (1)
-
gcrieloue@users.nuiton.org