1 29 30 package com.caucho.jca; 31 32 import com.caucho.config.BuilderProgram; 33 import com.caucho.loader.EnvironmentClassLoader; 34 import com.caucho.loader.EnvironmentLocal; 35 import com.caucho.util.L10N; 36 37 import javax.annotation.PostConstruct; 38 import java.util.ArrayList ; 39 import java.util.logging.Logger ; 40 41 44 public class ResourceDefault { 45 private static final L10N L = new L10N(ResourceDefault.class); 46 private static final Logger log 47 = Logger.getLogger(ResourceDefault.class.getName()); 48 49 private static EnvironmentLocal<ArrayList <ResourceConfig>> _localConfig 50 = new EnvironmentLocal<ArrayList <ResourceConfig>>(); 51 52 private ResourceConfig _config = new ResourceConfig(); 53 54 55 58 public void addBuilderProgram(BuilderProgram program) 59 { 60 _config.addBuilderProgram(program); 61 } 62 63 @PostConstruct 64 public void init() 65 { 66 ArrayList <ResourceConfig> defaultList = _localConfig.getLevel(); 67 68 if (defaultList == null) { 69 defaultList = new ArrayList <ResourceConfig>(); 70 _localConfig.set(defaultList); 71 } 72 73 defaultList.add(_config); 74 } 75 76 public static ArrayList <ResourceConfig> getDefaultList() 77 { 78 return getDefaultList(Thread.currentThread().getContextClassLoader()); 79 } 80 81 public static ArrayList <ResourceConfig> getDefaultList(ClassLoader loader) 82 { 83 ArrayList <ResourceConfig> defaultList = new ArrayList <ResourceConfig>(); 84 85 getDefaultList(defaultList, loader); 86 87 return defaultList; 88 } 89 90 private static void getDefaultList(ArrayList <ResourceConfig> list, 91 ClassLoader loader) 92 { 93 for (; loader != null; loader = loader.getParent()) { 94 if (loader instanceof EnvironmentClassLoader) { 95 getDefaultList(list, loader.getParent()); 96 97 ArrayList <ResourceConfig> defaultList = _localConfig.getLevel(loader); 98 99 if (defaultList != null) 100 list.addAll(defaultList); 101 } 102 } 103 } 104 } 105 | Popular Tags |