/*
 * Copyright 2015 Red Hat, Inc.
 *
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License v1.0
 *  and Apache License v2.0 which accompanies this distribution.
 *
 *  The Eclipse Public License is available at
 *  http://www.eclipse.org/legal/epl-v10.html
 *
 *  The Apache License v2.0 is available at
 *  http://www.opensource.org/licenses/apache2.0.php
 *
 *  You may elect to redistribute this code under either of these licenses.
 */
package io.vertx.ext.auth;

import io.vertx.codegen.annotations.DataObject;
import io.vertx.core.Vertx;
import io.vertx.core.VertxException;
import io.vertx.core.json.JsonObject;

import java.lang.reflect.Constructor;

/**
 * A common base object for authentication options.<p>
 *
 * @author <a href="mailto:julien@julienviet.com">Julien Viet</a>
 */
@DataObject
public interface AuthOptions {

  /**
   * Create the auth options from a json value, the implementation makes a lookup on the {@literal provider}
   * property of the json object and returns the corresponding class.
   *
   * @param json the json value
   * @return the auth provider
   */
  static AuthOptions create(JsonObject json) {

    String provider = json.getString("provider", "");
    String impl;
    switch (provider) {
      case "shiro":
        impl = "io.vertx.ext.auth.shiro.ShiroAuthOptions";
        break;
      case "jdbc":
        impl = "io.vertx.ext.auth.jdbc.JDBCAuthOptions";
        break;
      case "mongo":
        impl = "io.vertx.ext.auth.mongo.MongoAuthOptions";
        break;
      default:
        throw new IllegalArgumentException("Invalid auth provider: " + provider);
    }

    try {
      ClassLoader cl = Thread.currentThread().getContextClassLoader();
      Class<?> optionsClass = cl.loadClass(impl);
      Constructor<?> ctor = optionsClass.getConstructor(JsonObject.class);
      return (AuthOptions) ctor.newInstance(json);
    } catch (ClassNotFoundException e) {
      throw new VertxException("Provider class not found " + impl + " / check your classpath");
    } catch(InstantiationException e) {
      throw new VertxException("Cannot create " + provider +" options", e.getCause());
    } catch (Exception e) {
      throw new VertxException("Cannot create " + provider + " options" + provider, e);
    }
  }

  AuthOptions clone();

  /**
   * Create the suitable provider for this option.
   *
   * @param vertx the vertx instance
   * @return the auth provider
   */
  AuthProvider createProvider(Vertx vertx);
}
@@ -625,122 +625,8 @@
 rtx;
-%0Aimport io.vertx.core.VertxException;%0Aimport io.vertx.core.json.JsonObject;%0A%0Aimport java.lang.reflect.Constructor;
 %0A%0A/*
@@ -803,1441 +803,8 @@
  %7B%0A%0A
-  /**%0A   * Create the auth options from a json value, the implementation makes a lookup on the %7B@literal provider%7D%0A   * property of the json object and returns the corresponding class.%0A   *%0A   * @param json the json value%0A   * @return the auth provider%0A   */%0A  static AuthOptions create(JsonObject json) %7B%0A%0A    String provider = json.getString(%22provider%22, %22%22);%0A    String impl;%0A    switch (provider) %7B%0A      case %22shiro%22:%0A        impl = %22io.vertx.ext.auth.shiro.ShiroAuthOptions%22;%0A        break;%0A      case %22jdbc%22:%0A        impl = %22io.vertx.ext.auth.jdbc.JDBCAuthOptions%22;%0A        break;%0A      case %22mongo%22:%0A        impl = %22io.vertx.ext.auth.mongo.MongoAuthOptions%22;%0A        break;%0A      default:%0A        throw new IllegalArgumentException(%22Invalid auth provider: %22 + provider);%0A    %7D%0A%0A    try %7B%0A      ClassLoader cl = Thread.currentThread().getContextClassLoader();%0A      Class%3C?%3E optionsClass = cl.loadClass(impl);%0A      Constructor%3C?%3E ctor = optionsClass.getConstructor(JsonObject.class);%0A      return (AuthOptions) ctor.newInstance(json);%0A    %7D catch (ClassNotFoundException e) %7B%0A      throw new VertxException(%22Provider class not found %22 + impl + %22 / check your classpath%22);%0A    %7D catch(InstantiationException e) %7B%0A      throw new VertxException(%22Cannot create %22 + provider +%22 options%22, e.getCause());%0A    %7D catch (Exception e) %7B%0A      throw new VertxException(%22Cannot create %22 + provider + %22 options%22 + provider, e);%0A    %7D%0A  %7D%0A%0A
   Au

Remove AuthOptions create static method