Пример #1
0
 public synchronized List<ProviderIdent> listProviders() {
   final ArrayList<ProviderIdent> providerIdents = new ArrayList<ProviderIdent>();
   final String[] strings = getClassnames();
   for (final String classname : strings) {
     try {
       providerIdents.add(getProviderDeclaration(loadClass(classname)));
     } catch (PluginException e) {
       e.printStackTrace();
     }
   }
   return providerIdents;
 }
Пример #2
0
 /** Return true if the file has a class that provides the ident. */
 public synchronized boolean isLoaderFor(final ProviderIdent ident) {
   final String[] strings = getClassnames();
   for (final String classname : strings) {
     try {
       if (matchesProviderDeclaration(ident, loadClass(classname))) {
         return true;
       }
     } catch (PluginException e) {
       e.printStackTrace();
     }
   }
   return false;
 }
Пример #3
0
  /** Load provider instance for the service */
  @SuppressWarnings("unchecked")
  public synchronized <T> T load(final PluggableService<T> service, final String providerName)
      throws ProviderLoaderException {
    final ProviderIdent ident = new ProviderIdent(service.getName(), providerName);
    debug("loadInstance for " + ident + ": " + pluginJar);

    if (null == pluginProviderDefs.get(ident)) {
      final String[] strings = getClassnames();
      for (final String classname : strings) {
        final Class<?> cls;
        try {
          cls = loadClass(classname);
          if (matchesProviderDeclaration(ident, cls)) {
            pluginProviderDefs.put(ident, cls);
          }
        } catch (PluginException e) {
          log.error(
              "Failed to load class from "
                  + pluginJar
                  + ": classname: "
                  + classname
                  + ": "
                  + e.getMessage());
        }
      }
    }
    final Class<T> cls = pluginProviderDefs.get(ident);
    if (null != cls) {
      try {
        return createProviderForClass(service, cls);
      } catch (PluginException e) {
        throw new ProviderLoaderException(e, service.getName(), providerName);
      }
    }
    return null;
  }