001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.commons.discovery.jdk;
018
019 import java.io.IOException;
020 import java.net.URL;
021 import java.util.Enumeration;
022
023 /**
024 * JDK Hooks to extract properties/resources.
025 */
026 public abstract class JDKHooks {
027
028 private static final JDKHooks jdkHooks;
029
030 static {
031 jdkHooks = new JDK12Hooks();
032 }
033
034 /**
035 * Hidden constructor, this class can't be directly instantiated.
036 */
037 protected JDKHooks() { }
038
039 /**
040 * Return singleton object representing JVM hooks/tools.
041 *
042 * TODO: add logic to detect JDK level.
043 *
044 * @return The detected {@code JDKHooks}
045 */
046 public static final JDKHooks getJDKHooks() {
047 return jdkHooks;
048 }
049
050 /**
051 * Get the system property
052 *
053 * @param propName name of the property
054 * @return value of the property
055 */
056 public abstract String getSystemProperty(final String propName);
057
058 /**
059 * The thread context class loader is available for JDK 1.2
060 * or later, if certain security conditions are met.
061 *
062 * @return The thread context class loader, if available.
063 * Otherwise return null.
064 */
065 public abstract ClassLoader getThreadContextClassLoader();
066
067 /**
068 * The system class loader is available for JDK 1.2
069 * or later, if certain security conditions are met.
070 *
071 * @return The system class loader, if available.
072 * Otherwise return null.
073 */
074 public abstract ClassLoader getSystemClassLoader();
075
076 /**
077 * Resolve resource with given names and make them available in
078 * the returned iterator.
079 *
080 * @param loader The class loader used to resolve resources
081 * @param resourceName The resource name to resolve
082 * @return The iterator over the URL resolved resources
083 * @throws IOException if any error occurs while loading the resource
084 */
085 public abstract Enumeration<URL> getResources(ClassLoader loader, String resourceName) throws IOException;
086
087 }