String ver = split[1];
return "tizen" + "-" + ver + File.separator + profile;
}
- EMLogger.getLogger().warning("Failed to get platformpath from platform name : " + platformName);
+ EMLogger.getLogger().warning("Failed to get platform path from platform name : " + platformName);
return "";
}
public List<IOption> loadOptionList(ItemList itemTemplate) {
if (plugin != null) {
ExtensionItem exItem = getPlugin().getExtensionItem(PluginStringResources.OptionFactory);
- IOptionFactory f = (IOptionFactory)(exItem.createClass());
+ IOptionFactory f = (IOptionFactory)(exItem.createInstance());
if (f != null) {
return f.makeOptionList(itemTemplate);
}
if (customOptionList == null) {
if (plugin != null) {
ExtensionItem exItem = getPlugin().getExtensionItem(PluginStringResources.OptionFactory);
- IOptionFactory f = (IOptionFactory)(exItem.createClass());
+ IOptionFactory f = (IOptionFactory)(exItem.createInstance());
if (f != null) {
customOptionList = f.makeOptionList(getCustomItemList());
}
}
if (pluginJar != null && pluginJar.exists()) {
- plugin = EMPluginLoader.makePlugin(pluginJar);
- if (plugin != null) {
- plugin.setPlatform(this);
+ plugin = EMPluginLoader.makePlugin(pluginJar, this);
+ if (plugin == null) {
+ EMLogger.getLogger().warning("Making plug-in is failed." +
+ StringResources.NEW_LINE + "Plug-in file: " + pluginJar.getAbsolutePath());
}
+ } else {
+ EMLogger.getLogger().warning("Plug-in file does not exist." +
+ StringResources.NEW_LINE + "Plug-in file: " + pluginJar.getAbsolutePath());
}
}
package org.tizen.emulator.manager.plugin;
import java.io.IOException;
+import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.jar.Attributes;
import org.tizen.emulator.manager.platform.Platform;
public class EMPlugin {
- private ArrayList<ExtensionItem> exItemList
- = new ArrayList<ExtensionItem>();
- private Platform platform;
private String profile;
private String version;
+ private URLClassLoader loader;
+ private ArrayList<ExtensionItem> exItemList
+ = new ArrayList<ExtensionItem>();
- public EMPlugin(Attributes attr) throws IOException {
+ public EMPlugin(Attributes attr, URLClassLoader loader, Platform platform) throws IOException {
profile = attr.getValue(PluginStringResources.PlatformProfile);
version = attr.getValue(PluginStringResources.PlatformVersion);
+
if (profile == null) {
- throw new IOException("Not found " + "Platform-profile"+ " attribute.");
+ throw new IOException("Can not found " + PluginStringResources.PlatformProfile + " attribute.");
}
if (version == null) {
- throw new IOException("Not found " + "Platform-version"+ " attribute.");
+ throw new IOException("Can not found " + PluginStringResources.PlatformVersion + " attribute.");
+ }
+
+ if (!platform.getProfile().equals(profile)) {
+ throw new IOException("Profile of plug-in does not correspond with profile of platform.");
+ }
+ if (!platform.getVersion().equals(version)) {
+ throw new IOException("Version of plug-in does not correspond with version of platform.");
}
+ this.loader = loader;
+
for (String ex : EMPluginLoader.getExtensionList()) {
try {
exItemList.add(new ExtensionItem(ex, attr, this));
+ " extension point.");
}
}
+
}
public ArrayList<ExtensionItem> getExItemList() {
return null;
}
- public Platform getPlatform() {
- return platform;
- }
-
- public void setPlatform(Platform platform) {
- this.platform = platform;
- }
-
public String getProfile() {
return profile;
}
- public void setProfile(String profile) {
- this.profile = profile;
- }
-
public String getVersion() {
return version;
}
- public void setVersion(String version) {
- this.version = version;
+ public URLClassLoader getLoader() {
+ return loader;
}
}
import java.util.jar.Attributes;
import java.util.jar.JarFile;
-import org.tizen.emulator.manager.EmulatorManager;
import org.tizen.emulator.manager.logging.EMLogger;
+import org.tizen.emulator.manager.platform.Platform;
import org.tizen.emulator.manager.resources.StringResources;
public class EMPluginLoader {
return exPonitList;
}
- private static URLClassLoader loader;
- private static ArrayList<URL> urlList = new ArrayList<URL>();
-
- public static void completeLoadPlugin() throws Exception {
- URL[] urls = new URL[urlList.size()];
- loader = URLClassLoader.newInstance(urlList.toArray(urls));
- if (loader == null) {
- EMLogger.getLogger().warning("URLClassLoader is null");
- throw new Exception("Can not use plugins file..");
- }
- if (!EmulatorManager.isConsoleMode()) {
- ImageRegistry.setLoader(loader);
- }
- }
-
- public static EMPlugin makePlugin(File plugin) {
+ private static URLClassLoader makeLoader(File plugin) {
URL url = null;
- EMPlugin emPlugin = null;
- // add URL
+ URLClassLoader loader;
try {
url = plugin.toURI().toURL();
} catch (MalformedURLException e) {
return null;
}
- if (url != null) {
- urlList.add(url);
+ if (url == null) {
+ EMLogger.getLogger().warning("Failed to load url from jar file." +
+ StringResources.NEW_LINE + plugin.getAbsolutePath());
+ return null;
+ }
+
+ URL[] urls = new URL[1];
+ urls[0] = url;
+ loader = URLClassLoader.newInstance(urls);
+ if (loader == null) {
+ EMLogger.getLogger().warning("Failed to create instance of URLClassLoader.");
+ return null;
+ }
+
+ return loader;
+ }
+
+ private static Attributes makeAttribute(JarFile jarFile) {
+ Attributes attr = null;
+ try {
+ if (jarFile.getManifest() != null) {
+ attr = jarFile.getManifest().getMainAttributes();
+ }
+ } catch (IOException e) {
+ EMLogger.addStaticLog("Failed to load Manifest file: " + e.getMessage());
+ return null;
}
+ return attr;
+ }
+
+ public static EMPlugin makePlugin(File plugin, Platform platform) {
+ EMPlugin emPlugin = null;
JarFile jarFile = null;
if (plugin.isFile()) {
}
if (jarFile != null) {
- Attributes attr = null;
+ Attributes attr = EMPluginLoader.makeAttribute(jarFile);
+ if (attr == null) {
+ return null;
+ }
+
+ URLClassLoader loader = EMPluginLoader.makeLoader(plugin);
+ if (loader == null) {
+ return null;
+ }
+
try {
- if (jarFile.getManifest() != null) {
- attr = jarFile.getManifest().getMainAttributes();
- }
+ emPlugin = new EMPlugin (attr, loader, platform);
} catch (IOException e) {
- EMLogger.addStaticLog("Failed to load Manifest file: " + e.getMessage());
- }
- if (attr != null) {
- try {
- emPlugin = new EMPlugin (attr);
- } catch (IOException e) {
- EMLogger.getLogger().warning("Failed to load em-plugin"
- + StringResources.NEW_LINE + "Path: " + plugin.getAbsolutePath()
- + StringResources.NEW_LINE + "Error: " + e.getMessage());
- }
+ EMLogger.getLogger().warning("Failed to load em-plugin"
+ + StringResources.NEW_LINE + "Path: " + plugin.getAbsolutePath()
+ + StringResources.NEW_LINE + "Error: " + e.getMessage());
}
+
}
}
return emPlugin;
}
-
- public static Object createClass(String pointClass) {
- if (loader == null) {
- try {
- completeLoadPlugin();
- } catch (Exception e) {
- EMLogger.getLogger().warning(e.getMessage());
- }
- }
-
- @SuppressWarnings("rawtypes")
- Class classToLoad = null;
-
- try {
- classToLoad = Class.forName(pointClass, true, loader);
- } catch (ClassNotFoundException e) {
- EMLogger.getLogger().warning("Failed to load point class jar file: " + e.getMessage());
- return null;
- }
-
- try {
- return classToLoad.newInstance();
- } catch (InstantiationException e) {
- EMLogger.getLogger().warning("Failed to create new instance from class: " + e.getMessage());
- } catch (IllegalAccessException e) {
- EMLogger.getLogger().warning("Failed to create new instance from class: " + e.getMessage());
- }
-
- return null;
- }
-
}
import java.io.IOException;
import java.util.jar.Attributes;
+import org.tizen.emulator.manager.logging.EMLogger;
+
public class ExtensionItem {
private String exPoint;
private String pointClass;
private EMPlugin plugin;
+ private Object instance;
public ExtensionItem(String ex, Attributes attr, EMPlugin plugin) throws IOException {
this.exPoint = ex;
return exPoint;
}
- public String getPointClass() {
- return pointClass;
- }
-
- private Object clazz;
- public Object createClass() {
- if (clazz == null) {
- clazz = EMPluginLoader.createClass(pointClass);
+ public Object createInstance() {
+ if (instance == null) {
+ instance = loadingClass();
}
- return clazz;
+ return instance;
}
- public Object createInstance() {
- return EMPluginLoader.createClass(pointClass);
- }
+ private Object loadingClass() {
+ @SuppressWarnings("rawtypes")
+ Class classToLoad = null;
- public EMPlugin getPlugin() {
- return plugin;
- }
+ try {
+ classToLoad = Class.forName(pointClass, true, plugin.getLoader());
+ } catch (ClassNotFoundException e) {
+ EMLogger.getLogger().warning("Failed to load point class jar file: " + e.getMessage());
+ return null;
+ }
- public void setPlugin(EMPlugin plugin) {
- this.plugin = plugin;
+ try {
+ return classToLoad.newInstance();
+ } catch (InstantiationException e) {
+ EMLogger.getLogger().warning("Failed to create new instance from class: " + e.getMessage());
+ } catch (IllegalAccessException e) {
+ EMLogger.getLogger().warning("Failed to create new instance from class: " + e.getMessage());
+ }
+
+ return null;
}
}
import org.eclipse.swt.graphics.ImageLoader;
import org.eclipse.swt.widgets.Display;
import org.tizen.emulator.manager.logging.EMLogger;
+import org.tizen.emulator.manager.platform.Platform;
+import org.tizen.emulator.manager.platform.Profile;
+import org.tizen.emulator.manager.platform.ProfileList;
import org.tizen.emulator.manager.resources.ImageResources;
import org.tizen.emulator.manager.resources.ImageType;
return getImage(name, platformName, "gif");
}
+ private static URLClassLoader findLoader(String platformName) {
+ for (Profile p : ProfileList.getProfileList()) {
+ for (Platform pl : p.getPlatformList()) {
+ if (pl.getName().equals(platformName)) {
+ return pl.getPlugin().getLoader();
+ }
+ }
+ }
+ return null;
+ }
public static Image getImage(String name, String platformName, String extension) {
Image i = map.get(name+platformName);
+ loader = findLoader(platformName);
if (i == null && loader != null) {
InputStream is = loader.getResourceAsStream("res/" + platformName + "_" + name + "." + extension);
if (is != null) {
public static ImageData[] getImageData(String name, String platformName, String extension) {
ImageData[] frames = null;
+ loader = findLoader(platformName);
if (loader != null) {
InputStream is = loader.getResourceAsStream("res/" + platformName + "_" + name + "." + extension);
if (is != null) {
}
return frames;
}
-
- public static ClassLoader getLoader() {
- return loader;
- }
-
- public static void setLoader(URLClassLoader loader) {
- ImageRegistry.loader = loader;
- }
}
}
private void makeItemList(Composite parent, ItemList templateList, boolean isCustom) {
- IItemListFactory f = (IItemListFactory)(exItem.createClass());
+ IItemListFactory f = (IItemListFactory)(exItem.createInstance());
itemList = new ArrayList<IInfoViewItem>();
if (f != null) {
f.makeItemList(itemList, templateList, isCustom);
}
private void makeItemList(PModifyViewPage page, ItemList deviceItemList, boolean isCustom) {
- IItemListFactory f = (IItemListFactory)(exItem.createClass());
+ IItemListFactory f = (IItemListFactory)(exItem.createInstance());
itemList = new ArrayList<IModifyViewItem>();
// itemList = f.getModifyItemList(deviceItemList);
if (f != null) {
}
if (item != null) {
- this.setPainListener((PaintListener)item.createClass());
- launchButtonLeftOffset = ((IVMButtonPainter)item.createClass()).getLaunchButtonLeftOffset();
- launchButtonBottomOffset = ((IVMButtonPainter)item.createClass()).getLaunchButtonBottomOffset();
+ this.setPainListener((PaintListener)item.createInstance());
+ launchButtonLeftOffset = ((IVMButtonPainter)item.createInstance()).getLaunchButtonLeftOffset();
+ launchButtonBottomOffset = ((IVMButtonPainter)item.createInstance()).getLaunchButtonBottomOffset();
} else {
this.setPainListener(VMButtonPaintListener);
launchButtonLeftOffset = 13;