FileDocCategorySizeDatePackage
AbstractPluginWrapper.javaAPI DocJBoss 4.2.116213Fri Jul 13 21:02:14 BST 2007org.jboss.console.plugins.helpers

AbstractPluginWrapper

public abstract class AbstractPluginWrapper extends Object implements PluginWrapper, org.jboss.console.manager.interfaces.ConsolePlugin
see
author
Sacha Labourey.
version
$Revision: 57191 $

Revisions:

2 janv. 2003 Sacha Labourey:

  • First implementation

Fields Summary
public static final String
OBJECT_NAME_PARAM
public static final String
FOLDER_NAME_PARAM
public static final String
MBEAN_CLASS_PARAM
public static final String
WRAPPER_CLASS_PARAM
public static final String
SCRIPT_NAME_PARAM
public static final String
IS_ROOT_NODE_PARAM
protected MBeanServer
mbeanServer
protected org.jboss.console.manager.PluginManager
pm
protected String
pluginName
protected String
pluginVersion
protected String
objectName
protected String
mbeanClass
protected String
folderName
protected String
rootContextName
protected Logger
log
protected InternalResourceChecker
checker
Constructors Summary
public AbstractPluginWrapper()

   
   // Static --------------------------------------------------------
   
   // Constructors --------------------------------------------------
      
      
Methods Summary
protected org.jboss.console.manager.interfaces.TreeNodeMenuEntry[]createMenus(java.lang.String[] content)

          
      TreeNodeMenuEntry[] menuEntries = null;
      
      if (content != null && content.length > 0)
      {
         menuEntries = new TreeNodeMenuEntry[content.length];
         int i=0;
         while (i< content.length)
         {
            if (content[i] == null)
            {
               menuEntries[i] = new SeparatorTreeNodeMenuEntry();
               i++;
            }
            else
            {
               String text = content[i];
               TreeAction action = new HttpLinkTreeAction(fixUrl(content[i+1]));
               menuEntries[i] = new SimpleTreeNodeMenuEntryImpl ( text, action );
               i+=2;
            }
         }         
      }
      else
      {
         menuEntries = new TreeNodeMenuEntry[0];
      }
      return menuEntries;
   
protected org.jboss.console.manager.interfaces.impl.SimpleResourceTreeNodecreateResourceNode(java.lang.String name, java.lang.String description, java.lang.String iconUrl, java.lang.String defaultUrl, org.jboss.console.manager.interfaces.TreeNodeMenuEntry[] menuEntries, org.jboss.console.manager.interfaces.TreeNode[] subNodes, org.jboss.console.manager.interfaces.ResourceTreeNode[] subResNodes, java.lang.String jmxObjectName, java.lang.String jmxClassName)

      TreeAction action = new HttpLinkTreeAction (fixUrl(defaultUrl));
      ManageableResource res = new MBeanResource (new ObjectName(jmxObjectName), jmxClassName);
      return new SimpleResourceTreeNode (name, description, fixUrl(iconUrl), action, menuEntries, subNodes, subResNodes, res);
   
protected org.jboss.console.manager.interfaces.impl.SimpleResourceTreeNodecreateResourceNode(java.lang.String name, java.lang.String description, java.lang.String iconUrl, java.lang.String defaultUrl, org.jboss.console.manager.interfaces.TreeNodeMenuEntry[] menuEntries, org.jboss.console.manager.interfaces.TreeNode[] subNodes, org.jboss.console.manager.interfaces.ResourceTreeNode[] subResNodes, org.jboss.console.manager.interfaces.ManageableResource resource)

      TreeAction action = new HttpLinkTreeAction (fixUrl(defaultUrl));
      return new SimpleResourceTreeNode (name, description, fixUrl(iconUrl), action, menuEntries, subNodes, subResNodes, resource);
   
protected org.jboss.console.manager.interfaces.impl.SimpleTreeNodecreateTreeNode(java.lang.String name, java.lang.String description, java.lang.String iconUrl, java.lang.String defaultUrl, org.jboss.console.manager.interfaces.TreeNodeMenuEntry[] menuEntries, org.jboss.console.manager.interfaces.TreeNode[] subNodes, org.jboss.console.manager.interfaces.ResourceTreeNode[] subResNodes)

      TreeAction action = new HttpLinkTreeAction (fixUrl(defaultUrl));
      return new SimpleTreeNode (name, description, fixUrl(iconUrl), action, menuEntries, subNodes, subResNodes);
   
public voiddestroy()

      if( pm != null )
         pm.unregisterPlugin(this);
   
protected java.lang.Stringencode(java.lang.String source)

      try
      {
         return java.net.URLEncoder.encode(source);
      }
      catch (Exception e)
      {
         return source;
      }
   
protected voidfindJBossMBeanServer()

      this.mbeanServer = MBeanServerLocator.locateJBoss();
   
protected voidfindPluginManager()

      this.pm = (PluginManager) Registry.lookup (PluginManager.PLUGIN_MANAGER_NAME);
   
protected java.lang.StringfixUrl(java.lang.String source)

      if (source == null)
      {
         return null;
      }         
      else if (source.toLowerCase().startsWith("http://") || 
          source.toLowerCase().startsWith("https://"))
      {
         return source;
      }
      else if (source.startsWith("/"))
      {
         return source; // already absolute
      }
      else
      {
         return this.rootContextName + "/" + source;
      }
   
public java.lang.StringgetIdentifier()

      if (this.pluginName != null)
      {
         return this.pluginName + " (Wrapped by ServletPluginHelper)";
      }
      else
      {
         return getPluginIdentifier();
      }
   
protected javax.management.MBeanServergetMBeanServer()

      return this.mbeanServer;
   
protected javax.management.ObjectInstance[]getMBeansForClass(java.lang.String scope, java.lang.String className)

      try
      {
         Set result = mbeanServer.queryMBeans(new ObjectName(scope), 
            Query.eq (Query.classattr(), Query.value(className)));
         
         return (ObjectInstance[])result.toArray(new ObjectInstance[result.size()]);
      }
      catch (MalformedObjectNameException e)
      {
         log.debug (e);
         return new ObjectInstance[0];
      }
         
   
protected javax.management.ObjectInstance[]getMBeansForQuery(java.lang.String scope, javax.management.QueryExp query)

      try
      {
         Set result = mbeanServer.queryMBeans(new ObjectName(scope), query);         
         return (ObjectInstance[])result.toArray(new ObjectInstance[result.size()]);
      }
      catch (MalformedObjectNameException e)
      {
         log.debug (e);
         return new ObjectInstance[0];
      }
         
   
protected java.lang.StringgetPluginIdentifier()

      return "AbstractPluginWrapper (" + this.getClass() + ")";
   
protected java.lang.StringgetPluginVersion()

      return "unknown version";
   
public org.jboss.console.manager.interfaces.TreeNodegetSubTreeForResource(org.jboss.console.manager.PluginManager master, java.lang.String profile, org.jboss.console.manager.interfaces.ManageableResource resource)

      if (!ConsolePlugin.WEB_PROFILE.equalsIgnoreCase(profile))
      {
         return null;
      }
      else
      {
         if (isResourceToBeManaged (resource))
         {
            return getTreeForResource(
               profile,
               resource);
         }
         else
         {
            return null;
         }
      }
   
public java.lang.String[]getSupportedProfiles()

      return new String[] {ConsolePlugin.WEB_PROFILE};
   
protected abstract org.jboss.console.manager.interfaces.TreeNodegetTreeForResource(java.lang.String profile, org.jboss.console.manager.interfaces.ManageableResource resource)

public java.lang.StringgetVersion()

      if (this.pluginVersion != null)
      {
         return this.pluginVersion;
      }
      else
      {
         return getPluginVersion ();
      }   
   
public voidinit(javax.servlet.ServletConfig servletConfig)

      
      findJBossMBeanServer ();      
      findPluginManager ();
      readConfigurationParameters (servletConfig);
            
      this.pm.registerPlugin(this);
   
protected booleanisResourceToBeManaged(org.jboss.console.manager.interfaces.ManageableResource resource)

      if (checker == null)
      {
         return false;
      }
      else
      {
         return checker.isResourceToBeManaged(resource);
      }
   
public voidreadConfigurationParameters(javax.servlet.ServletConfig config)

      
      this.pluginName = config.getInitParameter("PluginName");
      this.pluginVersion = config.getInitParameter("PluginVersion");
      
      this.folderName = config.getInitParameter(FOLDER_NAME_PARAM);
      this.objectName = config.getInitParameter(OBJECT_NAME_PARAM);
      this.mbeanClass = config.getInitParameter(MBEAN_CLASS_PARAM);
      this.rootContextName = config.getInitParameter("ContextName");      

      String tmp = this.objectName;
      if (tmp != null && !"".equals(tmp))
      {
         // this kind of plugin is associated with a single MBean
         // which has a give JMX ObjectName
         //
         checker = new SingleMBeanChecker ();
      }

      tmp = this.folderName;
      if (tmp != null && !"".equals(tmp))
      {
         // this kind of plugins is associated with one of the static folder of the tree
         //
         checker = new SubFolderChecker ();
      }
      
      tmp = config.getInitParameter(IS_ROOT_NODE_PARAM);
      if (tmp != null && !"".equals(tmp) && "true".equalsIgnoreCase(tmp))
      {
         // this kind of plugins is associated with the root of the tree
         //
         checker = new RootTreeChecker ();
      }
      
      tmp = this.mbeanClass;
      if (tmp != null && !"".equals(tmp))
      {
         // this kind of plugins is associated with all MBean
         // that share a given interface
         //
         checker = new StandardMBeanChecker ();
      }