package com.asksunny.jbdstudio;

import java.util.HashMap;

import com.asksunny.jbdstudio.util.CLIOptions;

public class JBDStudioContext extends HashMap<String, Object>
{

	
	JBDStudionConfiguration configuration;
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	public JBDStudioContext(CLIOptions options)
	{
		configuration = new JBDStudionConfiguration(options);
	}

	public JBDStudionConfiguration getConfiguration() {
		return configuration;
	}

	public void setConfiguration(JBDStudionConfiguration configuration) {
		this.configuration = configuration;
	}
	
	
	
	
	

}

@@ -42,137 +42,486 @@
 ava.
-util.HashMap;%0A%0Aimport com.asksunny.jbdstudio.util.CLIOptions;%0A%0Apublic class JBDStudioContext extends HashMap%3CString, Object%3E%0A%7B%0A%0A%09
+io.File;%0Aimport java.io.FilenameFilter;%0Aimport java.net.MalformedURLException;%0Aimport java.net.URL;%0Aimport java.net.URLClassLoader;%0Aimport java.util.HashMap;%0A%0Aimport com.asksunny.jbdstudio.util.CLIOptions;%0A%0Apublic class JBDStudioContext extends HashMap%3CString, Object%3E%0A%7B%0A%0A%09public final static String SUFFIX = %22.class%22;%0A%09public final static String JAR_SUFFIX = %22.class%22;%0A%09public final static String PLUGIN_DIR = %22jbdstudio.plugin.dir%22;%0A%09%0A%09URLClassLoader pluginClassloader = null;
 %0A%09JB
@@ -559,16 +559,18 @@
 tion;%0A%09%0A
+%09%0A
 %09/**%0A%09 *
@@ -733,17 +733,35 @@
 ions);%0A%09
-%7D
+%09initPlugin();%0A%09%7D%0A%09
 %0A%0A%09publi
@@ -948,20 +948,1173 @@
 on;%0A%09%7D%0A%09%0A%09%0A%09
+protected void initPlugin()%0A%09%7B%0A%09%09String pluginDir  = this.configuration.getOption(PLUGIN_DIR);%0A%09%09if(pluginDir!=null)%7B%09%09%09%0A%09%09%09File dir = new File(pluginDir);%0A%09%09%09File%5B%5D  fs = dir.listFiles(new FilenameFilter() %7B%09%09%09%09%0A%09%09%09%09public boolean accept(File dir, String name) %7B%09%09%09%09%09%0A%09%09%09%09%09return name.endsWith(JAR_SUFFIX);%0A%09%09%09%09%7D%0A%09%09%09%7D);%0A%09%09%09URL%5B%5D jars = new URL%5Bfs.length%5D;%0A%09%09%09try %7B%0A%09%09%09%09for (int i = 0; i %3C jars.length; i++) %7B%0A%09%09%09%09%09jars%5Bi%5D = fs%5Bi%5D.toURI().toURL();%0A%09%09%09%09%7D%0A%09%09%09%09pluginClassloader = new URLClassLoader(jars, getClass().getClassLoader());%0A%09%09%09%7D catch (MalformedURLException e) %7B%09%09%09%09%0A%09%09%09%09e.printStackTrace();%0A%09%09%09%7D%09%09%09%0A%09%09%7D%0A%09%09%0A%09%7D%0A%09%0A%09%0A%09%0A%09%0A%09public JBDStudioService loadService(String name)%0A%09%7B%0A%09%09String key = name + SUFFIX;%0A%09%09String className = this.configuration.getOption(key);%0A%09%09try %7B%09%09%09%0A%09%09%09Class%3C?%3E clazz = this.pluginClassloader!=null?Class.forName(className, true, this.pluginClassloader)%0A%09%09%09%09%09:Class.forName(className);%0A%09%09%09JBDStudioService service = (JBDStudioService) clazz.newInstance();%09%09%0A%09%09%09return service;%0A%09%09%7D  catch (Exception e) %7B%0A%09%09%09throw new RuntimeException(String.format(%22Failed to load JBDStudioService %25s:class name: %25s%22, name, className));%0A%09%09%7D%0A%09%7D
 %0A%09%0A%09%0A%0A%7D%0A

add plugin service