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.util.Enumeration;
020    import java.io.IOException;
021    
022    
023    /**
024     * @author Richard A. Sitze
025     */
026    public abstract class JDKHooks {
027        private static final JDKHooks jdkHooks;
028        
029        static {
030            jdkHooks = new JDK12Hooks();
031        }
032        
033        protected JDKHooks() { }
034        
035        /**
036         * Return singleton object representing JVM hooks/tools.
037         * 
038         * TODO: add logic to detect JDK level.
039         */
040        public static final JDKHooks getJDKHooks() {
041            return jdkHooks;
042        }
043    
044        /**
045         * Get the system property
046         *
047         * @param propName name of the property
048         * @return value of the property
049         */
050        public abstract String getSystemProperty(final String propName);
051    
052        /**
053         * The thread context class loader is available for JDK 1.2
054         * or later, if certain security conditions are met.
055         * 
056         * @return The thread context class loader, if available.
057         *         Otherwise return null.
058         */
059        public abstract ClassLoader getThreadContextClassLoader();
060    
061        /**
062         * The system class loader is available for JDK 1.2
063         * or later, if certain security conditions are met.
064         * 
065         * @return The system class loader, if available.
066         *         Otherwise return null.
067         */
068        public abstract ClassLoader getSystemClassLoader();
069        
070        public abstract Enumeration getResources(ClassLoader loader,
071                                                 String resourceName)
072            throws IOException;
073    }