View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.discovery.jdk;
18  
19  import java.io.IOException;
20  import java.net.URL;
21  import java.util.Enumeration;
22  
23  /**
24   * JDK Hooks to extract properties/resources.
25   */
26  public abstract class JDKHooks {
27  
28      private static final JDKHooks jdkHooks;
29  
30      static {
31          jdkHooks = new JDK12Hooks();
32      }
33  
34      /**
35       * Hidden constructor, this class can't be directly instantiated.
36       */
37      protected JDKHooks() { }
38  
39      /**
40       * Return singleton object representing JVM hooks/tools.
41       *
42       * TODO: add logic to detect JDK level.
43       *
44       * @return The detected {@code JDKHooks}
45       */
46      public static final JDKHooks getJDKHooks() {
47          return jdkHooks;
48      }
49  
50      /**
51       * Get the system property
52       *
53       * @param propName name of the property
54       * @return value of the property
55       */
56      public abstract String getSystemProperty(final String propName);
57  
58      /**
59       * The thread context class loader is available for JDK 1.2
60       * or later, if certain security conditions are met.
61       *
62       * @return The thread context class loader, if available.
63       *         Otherwise return null.
64       */
65      public abstract ClassLoader getThreadContextClassLoader();
66  
67      /**
68       * The system class loader is available for JDK 1.2
69       * or later, if certain security conditions are met.
70       *
71       * @return The system class loader, if available.
72       *         Otherwise return null.
73       */
74      public abstract ClassLoader getSystemClassLoader();
75  
76      /**
77       * Resolve resource with given names and make them available in
78       * the returned iterator.
79       *
80       * @param loader The class loader used to resolve resources
81       * @param resourceName The resource name to resolve
82       * @return The iterator over the URL resolved resources
83       * @throws IOException if any error occurs while loading the resource
84       */
85      public abstract Enumeration<URL> getResources(ClassLoader loader, String resourceName) throws IOException;
86  
87  }