1 28 29 package com.caucho.jca; 30 31 import com.caucho.jca.cfg.ResourceAdapterConfig; 32 import com.caucho.loader.EnvironmentClassLoader; 33 import com.caucho.loader.EnvironmentLocal; 34 import com.caucho.log.Log; 35 import com.caucho.util.L10N; 36 37 import java.util.ArrayList ; 38 import java.util.logging.Logger ; 39 40 43 public class ResourceArchiveManager { 44 static final L10N L = new L10N(ResourceArchiveManager.class); 45 static final Logger log = Log.open(ResourceArchiveManager.class); 46 47 private static final EnvironmentLocal<ResourceArchiveManager> _localManager = 48 new EnvironmentLocal<ResourceArchiveManager>(); 49 50 private ArrayList <ResourceArchive> _resources = 51 new ArrayList <ResourceArchive>(); 52 53 56 private ResourceArchiveManager() 57 { 58 } 59 60 63 static void addResourceArchive(ResourceArchive rar) 64 { 65 ResourceArchiveManager raManager = _localManager.getLevel(); 66 67 if (raManager == null) { 68 raManager = new ResourceArchiveManager(); 69 _localManager.set(raManager); 70 } 71 72 raManager._resources.add(rar); 73 } 74 75 78 static ResourceArchive findResourceArchive(String name) 79 { 80 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 81 82 for (; loader != null; loader = loader.getParent()) { 83 if (loader instanceof EnvironmentClassLoader) { 84 EnvironmentClassLoader envLoader = (EnvironmentClassLoader) loader; 85 86 ResourceArchiveManager manager = _localManager.getLevel(envLoader); 87 88 if (manager != null) { 89 ResourceArchive ra = manager.getResourceArchive(name); 90 91 if (ra != null) 92 return ra; 93 } 94 } 95 } 96 97 return null; 98 } 99 100 103 private ResourceArchive getResourceArchive(String type) 104 { 105 for (int i = 0; i < _resources.size(); i++) { 106 ResourceArchive ra = _resources.get(i); 107 108 if (type.equals(ra.getDisplayName())) 109 return ra; 110 } 111 112 for (int i = 0; i < _resources.size(); i++) { 113 ResourceArchive ra = _resources.get(i); 114 115 ResourceAdapterConfig raConfig = ra.getResourceAdapter(); 116 if (raConfig == null) 117 continue; 118 119 Class resourceAdapterClass = raConfig.getResourceadapterClass(); 120 121 if (resourceAdapterClass != null && 122 type.equals(resourceAdapterClass.getName())) 123 return ra; 124 } 125 126 for (int i = 0; i < _resources.size(); i++) { 127 ResourceArchive ra = _resources.get(i); 128 if (ra.getConnectionDefinition(type) != null) 129 return ra; 130 } 131 132 return null; 133 } 134 } 135 | Popular Tags |