示例#1
0
  private final void loadExtension(Extension ext) {
    final String id = ext.getDeclaringPluginDescriptor().getId();
    final URL url;
    try {
      // note: ".../-" match everything starting with "plugin:" + id + "!/"
      url = new URL("plugin:" + id + "!/-");
      final ClassLoader cl = ext.getDeclaringPluginDescriptor().getPluginClassLoader();
      final CodeSource cs = new CodeSource(url, (Certificate[]) null);
      final Permissions perms = new Permissions();
      codeSource2Permissions.put(cs, perms);
      // BootLogInstance.get().debug("Adding permissions for " + cs);
      final ConfigurationElement[] elems = ext.getConfigurationElements();
      final int count = elems.length;
      for (int i = 0; i < count; i++) {
        final ConfigurationElement elem = elems[i];
        final String type = elem.getAttribute("class");
        final String name = elem.getAttribute("name");
        final String actions = elem.getAttribute("actions");

        if (type != null) {
          final Object perm;
          try {
            final Class permClass = cl.loadClass(type);
            if ((name != null) && (actions != null)) {
              final Constructor c = permClass.getConstructor(NAME_ACTIONS_ARGS);
              perm = c.newInstance(new Object[] {name, actions});
            } else if (name != null) {
              final Constructor c = permClass.getConstructor(NAME_ARGS);
              perm = c.newInstance(new Object[] {name});
            } else {
              perm = permClass.newInstance();
            }
            final Permission p = (Permission) perm;
            perms.add(p);
          } catch (ClassNotFoundException ex) {
            BootLogInstance.get().error("Permission class " + type + " not found");
          } catch (InstantiationException ex) {
            BootLogInstance.get().error("Cannot instantiate permission class " + type);
          } catch (IllegalAccessException ex) {
            BootLogInstance.get().error("Illegal access to permission class " + type);
          } catch (NoSuchMethodException ex) {
            BootLogInstance.get()
                .error("Constructor not found on permission class " + type + " in plugin " + id);
          } catch (InvocationTargetException ex) {
            BootLogInstance.get().error("Error constructing permission class " + type, ex);
          } catch (ClassCastException ex) {
            BootLogInstance.get().error("Permission class " + type + " not instance of Permission");
          }
        }
      }
    } catch (MalformedURLException ex) {
      BootLogInstance.get().error("Cannot create plugin codesource", ex);
    }
  }
示例#2
0
 public LanceFlags(ConfigurationElement config) {
   this(config.getAttribute("name"));
 }