Changeset 4233


Ignore:
Timestamp:
Apr 17, 2008, 3:05:50 PM (15 years ago)
Author:
Nicklas Nordborg
Message:

References #436: Create extension system for the web application

Improved error handling.

Location:
trunk/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/clients/web/net/sf/basedb/clients/web/extensions/ExtensionsControl.java

    r4221 r4233  
    216216  }
    217217 
     218  public static String getHomeUrl(String extensionId)
     219  {
     220    ExtensionsFile file = extensionsDir.getFileByExtensionId(extensionId);
     221    return file == null ? null : extensionsDir.getResourcesUrl(file);
     222  }
     223 
    218224  private final Set<Permission> permissions;
    219225  private ExtensionsControl(Set<Permission> permissions)
  • trunk/src/clients/web/net/sf/basedb/clients/web/extensions/ExtensionsDirectory.java

    r4221 r4233  
    584584    for (ExtensionsFile extFile : installedFiles.values())
    585585    {
    586       // Update the last modified information
    587       extFile.resetModified();
    588 
    589586      // Do not register extensions that has an error
    590587      if (extFile.hasError()) continue;
     
    610607    for (ExtensionsFile extFile : installedFiles.values())
    611608    {
    612       // Do not register extensions that has an error
    613       if (extFile.hasError()) continue;
    614 
    615609      try
    616610      {
    617         int num = extFile.registerExtensions(registry, forceUpdate);
    618         results.addMessage(extFile, num + " extensions registered.");
    619       }
    620       catch (Throwable ex)
    621       {
    622         extFile.setError(true);
    623         results.addErrorMessage(extFile,
    624           "Could not register extensions: " + ex.getMessage());
    625         log.error("Could not register extensions from " + extFile.getName(), ex);
     611        // Do not register extensions that has an error
     612        if (extFile.hasError()) continue;
     613 
     614        try
     615        {
     616          int num = extFile.registerExtensions(registry, forceUpdate);
     617          results.addMessage(extFile, num + " extensions registered.");
     618        }
     619        catch (Throwable ex)
     620        {
     621          extFile.setError(true);
     622          results.addErrorMessage(extFile,
     623            "Could not register extensions: " + ex.getMessage());
     624          log.error("Could not register extensions from " + extFile.getName(), ex);
     625        }
     626      }
     627      finally
     628      {
     629        // Update the last modified information
     630        extFile.resetModified();
    626631      }
    627632    }
  • trunk/src/clients/web/net/sf/basedb/clients/web/extensions/menu/PermissionMenuItemFactory.java

    r4207 r4233  
    129129  {
    130130    SessionControl sc = context.getClientContext().getSessionControl();
    131     boolean isEnabled = hasPermission(sc, visiblePermission);
    132     return isEnabled && super.prepareContext(context);
     131    boolean isVisible = hasPermission(sc, visiblePermission);
     132    return isVisible && super.prepareContext(context);
    133133  }
    134134  // ------------------------------------
  • trunk/src/core/net/sf/basedb/util/ClassUtil.java

    r3820 r4233  
    2727
    2828import java.lang.reflect.Constructor;
     29import java.lang.reflect.Method;
    2930import java.util.Set;
    3031import java.util.HashSet;
     
    145146    return clazz;
    146147  }
     148 
     149  /**
     150    Find a method in a <code>clazz</code> with the given <code>name</code>
     151    that takes the given list of <code>arguments</code>. This method is
     152    just calling {@link Class#getMethod(String, Class...)} but returns
     153    null instead of throwing an exception in case the method is not found.
     154
     155    @param clazz The class to look for the method in
     156    @param name The name of the method
     157    @param arguments The class types of the arguments
     158    @return The method or null if not found
     159    @since 2.7
     160  */
     161  public static Method findMethod(Class<?> clazz, String name, Class<?>... arguments)
     162  {
     163    Method m = null;
     164    try
     165    {
     166      m = clazz.getMethod(name, arguments);
     167    }
     168    catch (NoSuchMethodException ex)
     169    {}
     170    return m;
     171  }
    147172
    148173}
  • trunk/src/core/net/sf/basedb/util/extensions/ExtensionsInvoker.java

    r4207 r4233  
    5757{
    5858
     59  private static final org.apache.log4j.Logger log =
     60    org.apache.log4j.LogManager.getLogger("net.sf.basedb.util.extensions.ExtensionsInvoker");
     61 
    5962  final Collection<InvokationContext<A>> contexts;
    6063 
     
    9093    while (it.hasNext())
    9194    {
    92       A action = it.next();
    93       Renderer<? super A> renderer = it.getRenderer();
    94       if (renderer == null)
     95      A action = null;
     96      Renderer<? super A> renderer = null;
     97      try
    9598      {
    96         throw new NullPointerException("No renderer for extension: " + it.getExtension());
     99        action = it.next();
     100        renderer = it.getRenderer();
     101        if (renderer == null)
     102        {
     103          throw new NullPointerException("No renderer for extension: " + it.getExtension());
     104        }
     105        renderer.render(action);
    97106      }
    98       renderer.render(action);
     107      catch (RuntimeException ex)
     108      {
     109        log.error("Could not render action '" + action + "' with renderer '" +
     110            renderer + "'", ex);
     111      }
    99112    }
    100113  }
     
    113126    while (it.hasNext())
    114127    {
    115       renderer.render(it.next());
     128      A action = null;
     129      try
     130      {
     131        action = it.next();
     132        renderer.render(action);
     133      }
     134      catch (RuntimeException ex)
     135      {
     136        log.error("Could not render action '" + action + "' with renderer '" +
     137            renderer + "'", ex);
     138      }
    116139    }
    117140  }
  • trunk/src/core/net/sf/basedb/util/extensions/Registry.java

    r4208 r4233  
    151151      throw new InvalidUseOfNullException("extensionPoint.id of " + extensionPoint);
    152152    }
    153     Class<A> ac = extensionPoint.getActionClass();
    154     if (ac == null)
     153    Class<A> actionClass = extensionPoint.getActionClass();
     154    if (actionClass == null)
    155155    {
    156156      throw new InvalidUseOfNullException("Action class of extensionPoint[id=" + id + "]");
    157157    }
    158     if (!Action.class.isAssignableFrom(ac))
    159     {
    160       throw new ClassCastException("Action class '" + ac.getName() +
     158    if (!Action.class.isAssignableFrom(actionClass))
     159    {
     160      throw new ClassCastException("Action class '" + actionClass.getName() +
    161161        "' of extensionPoint[id=" + id + "] doesn't implement the 'Action' class");
    162162    }
     
    254254      throw new InvalidUseOfNullException("extension.id of " + extension);
    255255    }
    256     if (extension.getActionFactory() == null)
    257     {
    258       throw new InvalidUseOfNullException("Action factory of extension[id=" + id + "]");
     256    ActionFactory<?> actionFactory = extension.getActionFactory();
     257    if (actionFactory == null)
     258    {
     259      throw new InvalidUseOfNullException("Action factory for extension '" + id + "' is null.");
    259260    }
    260261
  • trunk/src/core/net/sf/basedb/util/extensions/xml/VariableConverter.java

    r4198 r4233  
    9090      String variable = m.group(1);
    9191      String value = variables.get(variable);
    92       m.appendReplacement(sb, value == null ? m.group() : value);
     92      if (value == null) value = m.group();
     93      m.appendReplacement(sb, Matcher.quoteReplacement(value));
    9394    }
    9495    m.appendTail(sb);
Note: See TracChangeset for help on using the changeset viewer.