
com.luoshu.open.id.IdContext Maven / Gradle / Ivy
package com.luoshu.open.id;
import com.luoshu.open.id.exception.IdException;
import java.util.HashMap;
import java.util.Map;
/**
* id 的上下文
* @author inme
*/
public class IdContext {
public static final String DEFAULT = "default";
private static final Map cache = new HashMap<>();
private static IdFactory defaultFactory = null;
protected synchronized static void addIdFactory(IdFactory idFactory){
String name = idFactory.getName();
if(cache.containsKey(name)){
throw new IdException("IdFactory name is repeat : " + name);
}
if(DEFAULT.equals(name)){
defaultFactory = idFactory;
}
cache.put(name , idFactory);
}
/**
* 返回默认的
* @return
*/
public static IdFactory getIdFactory(){
return defaultFactory;
}
/**
* 根据工厂名称,来获取 id 工厂
* @param name
* @return
*/
public static IdFactory getIdFactory(String name){
return cache.get(name);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy