private Component getInstance(final Class<?> componentClass,
                                final Component enclosing,
                                final String id) throws NoSuchMethodException,
                                                 InstantiationException,
                                                 IllegalAccessException,
                                                 IllegalArgumentException,
                                                 InvocationTargetException {
    if (componentClass.getEnclosingClass() == null || Modifier.isStatic(componentClass.getModifiers())) {
      // -- Static inner class or normal class
      final Constructor<?> constructor = componentClass.getDeclaredConstructor(String.class);
      constructor.setAccessible(true);
      return (Component) constructor.newInstance(id);
    }
    else {
      if (enclosing != null && componentClass.getEnclosingClass().isAssignableFrom(enclosing.getClass())) {
        final Constructor<?> constructor = componentClass.getDeclaredConstructor(componentClass.getEnclosingClass(),
                                                                                 String.class);
        constructor.setAccessible(true);
        return (Component) constructor.newInstance(enclosing, id);
      }
      throw new RuntimeException("Unable to initialize inner class "
                                 + componentClass.getClass().getSimpleName() + " with id " + id
                                 + ". Enclosing class is not in the component hierarchy.");
    }
  }