1 21 22 package org.apache.derby.client.am; 23 24 27 public class GetResourceInputStreamAction implements java.security.PrivilegedAction { 28 private String resourceName_ = null; 30 private String resourcePath_ = null; 32 private String resourceLoaderId_ = null; 34 35 37 public GetResourceInputStreamAction(String resourceName) { 38 resourceName_ = resourceName; 39 } 40 41 43 public Object run() { 44 try { 45 ClassLoader contextLoader = Thread.currentThread().getContextClassLoader(); 46 if (contextLoader != null) { 47 java.net.URL resourceUrl = contextLoader.getResource(resourceName_); 48 if (resourceUrl != null) { 49 resourcePath_ = resourceUrl.getPath(); 50 resourceLoaderId_ = "Context ClassLoader: " + contextLoader; 51 return contextLoader.getResourceAsStream(resourceName_); 52 } 53 } 54 ClassLoader thisLoader = getClass().getClassLoader(); 55 if (thisLoader != contextLoader) { 56 java.net.URL resourceUrl = thisLoader.getResource(resourceName_); 57 if (resourceUrl != null) { 58 resourcePath_ = resourceUrl.getPath(); 59 resourceLoaderId_ = "Driver ClassLoader: " + thisLoader; 60 return thisLoader.getResourceAsStream(resourceName_); 61 } 62 } 63 ClassLoader systemLoader = ClassLoader.getSystemClassLoader(); 64 if (systemLoader != contextLoader && 65 systemLoader != thisLoader) { 66 java.net.URL resourceUrl = systemLoader.getResource(resourceName_); 67 if (resourceUrl != null) { 68 resourcePath_ = resourceUrl.getPath(); 69 resourceLoaderId_ = "System ClassLoader: " + systemLoader; 70 return systemLoader.getResourceAsStream(resourceName_); 71 } 72 } 73 return null; 74 } catch (java.security.AccessControlException ace) { 75 return null; 78 } 79 } 80 81 public void setResourceName(String resourceName) { 82 resourceName_ = resourceName; 83 } 84 85 public String getResourcePath() { 86 return resourcePath_; 87 } 88 89 public String getResourceLoaderId() { 90 return resourceLoaderId_; 91 } 92 93 } 94 | Popular Tags |