From: <jt...@hy...> - 2007-10-24 20:45:35
|
Author: jtravis Date: 2007-10-24 13:45:19 -0700 (Wed, 24 Oct 2007) New Revision: 6433 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=6433 Added: trunk/src/org/hyperic/hq/hqu/rendit/IDispatcher.java trunk/src/org/hyperic/hq/hqu/rendit/IHQUPlugin.java trunk/src/org/hyperic/hq/hqu/rendit_sys/HQUPlugin.groovy Log: Add interfaces and classes for use by HQU to communicate with groovy-land Added: trunk/src/org/hyperic/hq/hqu/rendit/IDispatcher.java =================================================================== --- trunk/src/org/hyperic/hq/hqu/rendit/IDispatcher.java (rev 0) +++ trunk/src/org/hyperic/hq/hqu/rendit/IDispatcher.java 2007-10-24 20:45:19 UTC (rev 6433) @@ -0,0 +1,52 @@ +/* + * NOTE: This copyright does *not* cover user programs that use HQ + * program services by normal system calls through the application + * program interfaces provided as part of the Hyperic Plug-in Development + * Kit or the Hyperic Client Development Kit - this is merely considered + * normal use of the program, and does *not* fall under the heading of + * "derived work". + * + * Copyright (C) [2004, 2005, 2006], Hyperic, Inc. + * This file is part of HQ. + * + * HQ is free software; you can redistribute it and/or modify + * it under the terms version 2 of the GNU General Public License as + * published by the Free Software Foundation. This program is distributed + * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + */ +package org.hyperic.hq.hqu.rendit; + +import java.io.File; +import java.util.Properties; + +import org.hyperic.hq.hqu.server.session.UIPlugin; + +/** + * This interface is implemented by the Groovy HQU dispatcher + * (dispatcher.groovy) and acts as a recipient of messages sent from HQ. + * + * Many of these methods correlate to things going on in {@link IHQUPlugin} + */ +public interface IDispatcher { + /** + * Called when HQ wants to load a plugin + */ + Properties loadPlugin(File pluginDir); + + /** + * Called when a plugin is to be deployedn + */ + void deploy(UIPlugin p); + + void handleRequest(RequestInvocationBindings b); + + void invokeMethod(InvokeMethodInvocationBindings invokeArgs); +} Added: trunk/src/org/hyperic/hq/hqu/rendit/IHQUPlugin.java =================================================================== --- trunk/src/org/hyperic/hq/hqu/rendit/IHQUPlugin.java (rev 0) +++ trunk/src/org/hyperic/hq/hqu/rendit/IHQUPlugin.java 2007-10-24 20:45:19 UTC (rev 6433) @@ -0,0 +1,67 @@ +/* + * NOTE: This copyright does *not* cover user programs that use HQ + * program services by normal system calls through the application + * program interfaces provided as part of the Hyperic Plug-in Development + * Kit or the Hyperic Client Development Kit - this is merely considered + * normal use of the program, and does *not* fall under the heading of + * "derived work". + * + * Copyright (C) [2004-2007], Hyperic, Inc. + * This file is part of HQ. + * + * HQ is free software; you can redistribute it and/or modify + * it under the terms version 2 of the GNU General Public License as + * published by the Free Software Foundation. This program is distributed + * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + */ +package org.hyperic.hq.hqu.rendit; + +import java.io.File; +import java.util.Properties; + +import org.hyperic.hq.hqu.server.session.UIPlugin; + +/** + * Implementors of this interface (notably, HQUPlugin) are able to be + * dispatched by the HQU {@link RenditServer}. + */ +public interface IHQUPlugin { + /** + * Called before anything else, to inform the plugin where it is + * located on disk. + */ + void initialize(File pluginDir); + + /** + * Returns information about the plugin. The properties here are + * from RenditServer.PROP_* + */ + Properties getDescriptor(); + + /** + * Get the name of the plugin. This is a unique, short-name (such as + * live_exec, or auditcenter), which likely apply to a directory on + * disk. + */ + String getName(); + + /** + * Returns a localized string, containing the description of the plugin. + */ + String getDescription(); + + /** + * Called when HQ deploys a plugin. + * + * @param me HQ's internal representation of the plugin + */ + void deploy(UIPlugin me); +} Added: trunk/src/org/hyperic/hq/hqu/rendit_sys/HQUPlugin.groovy =================================================================== --- trunk/src/org/hyperic/hq/hqu/rendit_sys/HQUPlugin.groovy (rev 0) +++ trunk/src/org/hyperic/hq/hqu/rendit_sys/HQUPlugin.groovy 2007-10-24 20:45:19 UTC (rev 6433) @@ -0,0 +1,122 @@ +package org.hyperic.hq.hqu.rendit + +import org.apache.commons.logging.Log +import org.apache.commons.logging.LogFactory + +import org.hyperic.hq.hqu.server.session.UIPlugin + +import org.hyperic.hq.hqu.ViewDescriptor +import org.hyperic.hq.hqu.server.session.UIPluginManagerEJBImpl as uiManImpl +import org.hyperic.hq.hqu.server.session.AttachType +import org.hyperic.hq.hqu.server.session.View +import org.hyperic.hq.hqu.server.session.ViewResource +import org.hyperic.hq.hqu.server.session.ViewMasthead +import org.hyperic.hq.hqu.server.session.ViewResourceCategory +import org.hyperic.hq.hqu.server.session.ViewMastheadCategory + + +/** + * The plugin's deployer is a class which deals with requests from the + * hosting application (HQ). + * + * It is able to answer many questions, such as: + * - What is your name? + * - Describe yourself + * - Do you work with version X of HQ? + * + * And also able to process HQ actions, such as: + * - You have been deployed, what do you want to do? + * - You are being undeployed. + */ +class HQUPlugin implements IHQUPlugin { + private Map views = [:] + Log log + File pluginDir + + HQUPlugin() { + } + + void initialize(File pluginDir) { + this.pluginDir = pluginDir + this.log = LogFactory.getLog("hqu.plugin.${name}") + } + + protected void addMastheadView(boolean autoAttach, String path, + String description, String category) + { + views[description] = [type: 'masthead', autoAttach: autoAttach, + path: path, description: description, + category: category] + } + + void deploy(UIPlugin me) { + for (e in views) { + def name = e.key + def parms = e.value + + if (!parms.autoAttach) + continue + + if (me.views.empty) { + createAndAttachMasthead(me, name, parms) + } + } + } + + private void createAndAttachMasthead(UIPlugin me, String name, Map parms) { + def uiMan = uiManImpl.one + ViewMasthead view + + boolean foundView = false + for (v in me.views) { + if (v.path == parms.path) { + foundView = true + view = v + break + } + } + + if (!foundView) { + AttachType atype = AttachType.findByDescription(parms.type) + ViewDescriptor vd = new ViewDescriptor(parms.path, + parms.description, atype) + view = uiMan.createMastheadView(me, vd) + } + + if (view.attachments.empty) { + ViewMastheadCategory cat = + ViewMastheadCategory.findByDescription(parms.category) + uiMan.attachView(view, cat) + } + } + + Properties getDescriptor() { + Properties res = new Properties() + new File(pluginDir, 'plugin.properties').withInputStream { s -> + res.load(s) + } + res + } + + String getName() { + descriptor.getProperty('plugin.name') + } + + String getDescription() { + def loader = this.class.classLoader + def subloader = new URLClassLoader([new File(pluginDir, 'etc').toURL()], + loader) + + def file = "${name}_i18n" + try { + def b = ResourceBundle.getBundle(file, Locale.getDefault(), + subloader) + return b.getString("${name}.description") + } catch(MissingResourceException e) { + log.warn("Unable to find resource bundle at " + + "${pluginDir}/etc/${file}.properties or unable " + + "to find ${name}.description property inside it", e) + } + return "Error getting description" + } +} |