001: /*
002:
003: Derby - Class org.apache.derby.client.am.GetResourceInputStreamAction
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to You under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.client.am;
023:
024: /**
025: * Java 2 PrivilegedAction encapsulation of attempting to acquire driver-general properties as a System resource.
026: */
027: public class GetResourceInputStreamAction implements
028: java.security.PrivilegedAction {
029: // Name for loading the resource.
030: private String resourceName_ = null;
031: // Path of the resource being loaded.
032: private String resourcePath_ = null;
033: // Class loader being used to load the resource.
034: private String resourceLoaderId_ = null;
035:
036: //-------------------- Constructors --------------------
037:
038: public GetResourceInputStreamAction(String resourceName) {
039: resourceName_ = resourceName;
040: }
041:
042: //-------------------- methods --------------------
043:
044: public Object run() {
045: try {
046: ClassLoader contextLoader = Thread.currentThread()
047: .getContextClassLoader();
048: if (contextLoader != null) {
049: java.net.URL resourceUrl = contextLoader
050: .getResource(resourceName_);
051: if (resourceUrl != null) {
052: resourcePath_ = resourceUrl.getPath();
053: resourceLoaderId_ = "Context ClassLoader: "
054: + contextLoader;
055: return contextLoader
056: .getResourceAsStream(resourceName_);
057: }
058: }
059: ClassLoader this Loader = getClass().getClassLoader();
060: if (this Loader != contextLoader) {
061: java.net.URL resourceUrl = this Loader
062: .getResource(resourceName_);
063: if (resourceUrl != null) {
064: resourcePath_ = resourceUrl.getPath();
065: resourceLoaderId_ = "Driver ClassLoader: "
066: + this Loader;
067: return this Loader
068: .getResourceAsStream(resourceName_);
069: }
070: }
071: ClassLoader systemLoader = ClassLoader
072: .getSystemClassLoader();
073: if (systemLoader != contextLoader
074: && systemLoader != this Loader) {
075: java.net.URL resourceUrl = systemLoader
076: .getResource(resourceName_);
077: if (resourceUrl != null) {
078: resourcePath_ = resourceUrl.getPath();
079: resourceLoaderId_ = "System ClassLoader: "
080: + systemLoader;
081: return systemLoader
082: .getResourceAsStream(resourceName_);
083: }
084: }
085: return null;
086: } catch (java.security.AccessControlException ace) {
087: // This happens in an Applet environment,
088: // so return with null.
089: return null;
090: }
091: }
092:
093: public void setResourceName(String resourceName) {
094: resourceName_ = resourceName;
095: }
096:
097: public String getResourcePath() {
098: return resourcePath_;
099: }
100:
101: public String getResourceLoaderId() {
102: return resourceLoaderId_;
103: }
104:
105: }
|