001package systems.dmx.core.impl; 002 003import systems.dmx.core.service.PluginInfo; 004import org.codehaus.jettison.json.JSONObject; 005import org.osgi.framework.Bundle; 006 007 008 009class PluginInfoImpl implements PluginInfo { 010 011 // ------------------------------------------------------------------------------------------------------- Constants 012 013 private static final String PLUGIN_FILE = "/web/plugin.js"; 014 015 // ---------------------------------------------------------------------------------------------- Instance Variables 016 017 private Bundle pluginBundle; 018 private JSONObject pluginInfo = new JSONObject(); 019 020 // ---------------------------------------------------------------------------------------------------- Constructors 021 022 PluginInfoImpl(String pluginUri, Bundle pluginBundle) { 023 this.pluginBundle = pluginBundle; 024 try { 025 pluginInfo.put("pluginUri", pluginUri); 026 pluginInfo.put("hasPluginFile", hasPluginFile()); 027 } catch (Exception e) { 028 throw new RuntimeException("Serialization failed", e); 029 } 030 } 031 032 // -------------------------------------------------------------------------------------------------- Public Methods 033 034 @Override 035 public JSONObject toJSON() { 036 return pluginInfo; 037 } 038 039 // ------------------------------------------------------------------------------------------------- Private Methods 040 041 private boolean hasPluginFile() { 042 return pluginBundle.getEntry(PLUGIN_FILE) != null; 043 } 044}