You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2014/04/27 09:00:26 UTC
svn commit: r1590352 - in
/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/helpers/lang:
./ BundleResourceLoader.java ClassLoaderResourceLoader.java
ResourceLoader.java
Author: mattsicker
Date: Sun Apr 27 07:00:26 2014
New Revision: 1590352
URL: http://svn.apache.org/r1590352
Log:
Add resource loader abstraction.
Added:
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/helpers/lang/
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/helpers/lang/BundleResourceLoader.java (with props)
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/helpers/lang/ClassLoaderResourceLoader.java (with props)
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/helpers/lang/ResourceLoader.java (with props)
Added: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/helpers/lang/BundleResourceLoader.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/helpers/lang/BundleResourceLoader.java?rev=1590352&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/helpers/lang/BundleResourceLoader.java (added)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/helpers/lang/BundleResourceLoader.java Sun Apr 27 07:00:26 2014
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.logging.log4j.core.helpers.lang;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Enumeration;
+import org.osgi.framework.Bundle;
+
+/**
+ * Bundle-based ResourceLoader.
+ */
+public class BundleResourceLoader implements ResourceLoader {
+
+ private final Bundle bundle;
+
+ public BundleResourceLoader(final Bundle bundle) {
+ this.bundle = bundle;
+ }
+
+ @Override
+ public Class<?> loadClass(final String name) throws ClassNotFoundException {
+ return bundle.loadClass(name);
+ }
+
+ @Override
+ public URL getResource(final String name) {
+ return bundle.getResource(name);
+ }
+
+ @Override
+ public Enumeration<URL> getResources(final String name) throws IOException {
+ return bundle.getResources(name);
+ }
+}
Propchange: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/helpers/lang/BundleResourceLoader.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/helpers/lang/ClassLoaderResourceLoader.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/helpers/lang/ClassLoaderResourceLoader.java?rev=1590352&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/helpers/lang/ClassLoaderResourceLoader.java (added)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/helpers/lang/ClassLoaderResourceLoader.java Sun Apr 27 07:00:26 2014
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.logging.log4j.core.helpers.lang;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Enumeration;
+
+/**
+ * ClassLoader-based ResourceLoader.
+ */
+public class ClassLoaderResourceLoader implements ResourceLoader {
+
+ private final ClassLoader loader;
+
+ public ClassLoaderResourceLoader(final ClassLoader loader) {
+ this.loader = loader != null ? loader : this.getClass().getClassLoader();
+ }
+
+ @Override
+ public Class<?> loadClass(final String name) throws ClassNotFoundException {
+ return loader.loadClass(name);
+ }
+
+ @Override
+ public URL getResource(final String name) {
+ return loader.getResource(name);
+ }
+
+ @Override
+ public Enumeration<URL> getResources(final String name) throws IOException {
+ return loader.getResources(name);
+ }
+}
Propchange: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/helpers/lang/ClassLoaderResourceLoader.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/helpers/lang/ResourceLoader.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/helpers/lang/ResourceLoader.java?rev=1590352&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/helpers/lang/ResourceLoader.java (added)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/helpers/lang/ResourceLoader.java Sun Apr 27 07:00:26 2014
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.logging.log4j.core.helpers.lang;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Enumeration;
+
+/**
+ * Abstract interface for a ClassLoader or similar object.
+ */
+public interface ResourceLoader {
+ Class<?> loadClass(String name) throws ClassNotFoundException;
+ URL getResource(String name);
+ Enumeration<URL> getResources(String name) throws IOException;
+}
Propchange: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/helpers/lang/ResourceLoader.java
------------------------------------------------------------------------------
svn:eol-style = native