Esempio n. 1
0
  private static final StoreManager getStorageManager(Configuration storageConfig) {
    String clazzname =
        storageConfig.getString(
            GraphDatabaseConfiguration.STORAGE_BACKEND_KEY,
            GraphDatabaseConfiguration.STORAGE_BACKEND_DEFAULT);
    if (preregisteredStorageManagers.containsKey(clazzname.toLowerCase())) {
      clazzname = preregisteredStorageManagers.get(clazzname.toLowerCase()).getCanonicalName();
    }

    try {
      Class clazz = Class.forName(clazzname);
      Constructor constructor = clazz.getConstructor(Configuration.class);
      StoreManager storage = (StoreManager) constructor.newInstance(storageConfig);
      return storage;
    } catch (ClassNotFoundException e) {
      throw new IllegalArgumentException("Could not find storage manager class" + clazzname);
    } catch (NoSuchMethodException e) {
      throw new IllegalArgumentException(
          "Configured storage manager does not have required constructor: " + clazzname);
    } catch (InstantiationException e) {
      throw new IllegalArgumentException(
          "Could not instantiate storage manager class " + clazzname, e);
    } catch (IllegalAccessException e) {
      throw new IllegalArgumentException(
          "Could not instantiate storage manager class " + clazzname, e);
    } catch (InvocationTargetException e) {
      throw new IllegalArgumentException(
          "Could not instantiate storage manager class " + clazzname, e);
    } catch (ClassCastException e) {
      throw new IllegalArgumentException(
          "Could not instantiate storage manager class " + clazzname, e);
    }
  }
Esempio n. 2
0
  public static final <T> T instantiate(String clazzname, Object... constructorArgs) {

    try {
      Class clazz = Class.forName(clazzname);
      Constructor constructor = clazz.getConstructor(Configuration.class);
      T instance = (T) constructor.newInstance(constructorArgs);
      return instance;
    } catch (ClassNotFoundException e) {
      throw new IllegalArgumentException("Could not find implementation class: " + clazzname);
    } catch (NoSuchMethodException e) {
      throw new IllegalArgumentException(
          "Configured backend implementation does not have required constructor: " + clazzname);
    } catch (InstantiationException e) {
      throw new IllegalArgumentException("Could not instantiate implementation: " + clazzname, e);
    } catch (IllegalAccessException e) {
      throw new IllegalArgumentException("Could not instantiate implementation: " + clazzname, e);
    } catch (InvocationTargetException e) {
      throw new IllegalArgumentException("Could not instantiate implementation: " + clazzname, e);
    } catch (ClassCastException e) {
      throw new IllegalArgumentException("Could not instantiate implementation: " + clazzname, e);
    }
  }