Package com.azwul.api.service.helper

Source Code of com.azwul.api.service.helper.HelperFactory

/**
*
*/
package com.azwul.api.service.helper;

import java.util.HashMap;
import java.util.Map;

import com.azwul.api.exception.AzwulApiException;

/**
* @author Theotime Jurzak
*
*/
public final class HelperFactory {

  protected static Map<Class<? extends Object>, Object> pool = new HashMap<Class<? extends Object>, Object>();

  public static HttpHelper getHttpHelper() {
    return (HttpHelper) getObject(HttpHelper.class);
  }

  protected static Object getObject(Class<? extends Object> clazz) {
    synchronized (pool) {
      if (pool.get(clazz) == null) {
        Object o;
        try {
          o = clazz.newInstance();
        } catch (Exception e) {
          throw new AzwulApiException("Error instantiating service "
              + clazz, e);
        }

        pool.put(clazz, o);
      }
    }

    return pool.get(clazz);
  }

}
TOP

Related Classes of com.azwul.api.service.helper.HelperFactory

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.