ApiFactory.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */



  20. package org.openspcoop2.utils.rest;

  21. import org.openspcoop2.utils.resources.Loader;
  22. /**
  23.  * ApiFactory
  24.  *
  25.  * @author Poli Andrea (apoli@link.it)
  26.  * @author $Author$
  27.  * @version $Rev$, $Date$
  28.  */


  29. public class ApiFactory {
  30.    

  31.     public static IApiReader newApiReader(ApiFormats format) throws ProcessingException{
  32.         if(format==null) {
  33.             throw new ProcessingException("ApiFormat undefined");
  34.         }
  35.         Loader loader = new Loader();
  36.         try{
  37.             switch (format) {
  38.             case WADL:
  39.                 return (IApiReader) loader.newInstance("org.openspcoop2.utils.wadl.WADLApiReader");
  40.             case SWAGGER_2:
  41.                 return (IApiReader) loader.newInstance("org.openspcoop2.utils.openapi.SwaggerApiReader");
  42.             case OPEN_API_3:
  43.                 return (IApiReader) loader.newInstance("org.openspcoop2.utils.openapi.OpenapiApiReader");
  44.             }
  45.         }
  46.         catch(Throwable t){
  47.             throw new ProcessingException(t.getMessage(),t);
  48.         }
  49.         throw new ProcessingException("ApiFormat ["+format+"] unsupported");
  50.     }
  51.    
  52.     public static IApiValidator newApiValidator(ApiFormats format) throws ProcessingException{
  53.         if(format==null) {
  54.             throw new ProcessingException("ApiFormat undefined");
  55.         }
  56.         Loader loader = new Loader();
  57.         try{
  58.             switch (format) {
  59.             case WADL:
  60.                 return (IApiValidator) loader.newInstance("org.openspcoop2.utils.wadl.validator.Validator");
  61.             case SWAGGER_2:
  62.                 return (IApiValidator) loader.newInstance("org.openspcoop2.utils.openapi.validator.Validator");
  63.             case OPEN_API_3:
  64.                 return (IApiValidator) loader.newInstance("org.openspcoop2.utils.openapi.validator.Validator");
  65.             }
  66.         }
  67.         catch(Throwable t){
  68.             throw new ProcessingException(t.getMessage(),t);
  69.         }
  70.         throw new ProcessingException("ApiFormat ["+format+"] unsupported");
  71.     }

  72. }