-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ResourcesLoader to wrap loading resources from classpath, remove …
…or deprecate direct usage of class loaders from the engine
- Loading branch information
1 parent
177f7d3
commit d5b3c4b
Showing
21 changed files
with
302 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
jme3-core/src/main/java/com/jme3/util/res/ResourcesLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Copyright (c) 2009-2023 jMonkeyEngine | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are | ||
* met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* | ||
* * Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors | ||
* may be used to endorse or promote products derived from this software | ||
* without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package com.jme3.util.res; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.URL; | ||
import java.util.Enumeration; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
|
||
|
||
/** | ||
* This class is used to load resources from the default location | ||
* usually the classpath. | ||
*/ | ||
public class ResourcesLoader { | ||
public static final String PROPERTY_RESOURCES_LOADER_IMPLEMENTATION = "com.jme3.ResourcesLoaderImplementation"; | ||
private static final String DEFAULT_IMPL = "com.jme3.util.res.ResourcesLoaderJImpl"; | ||
|
||
private static final Logger LOGGER = Logger.getLogger(ResourcesLoader.class.getName()); | ||
private static ResourcesLoaderImpl impl = null; | ||
|
||
private static ResourcesLoaderImpl getImpl() { | ||
if (impl != null) return impl; | ||
String className = System.getProperty(PROPERTY_RESOURCES_LOADER_IMPLEMENTATION, DEFAULT_IMPL); | ||
try { | ||
impl = (ResourcesLoaderImpl) Class.forName(className).getDeclaredConstructor().newInstance(); | ||
} catch (final Throwable e) { | ||
LOGGER.log(Level.WARNING, "Unable to access {0}", className); | ||
try { | ||
impl = (ResourcesLoaderImpl) Class.forName(DEFAULT_IMPL).getDeclaredConstructor().newInstance(); | ||
} catch (final Throwable e1) { | ||
throw new RuntimeException("Unable to access default resources loader implementation", e1); | ||
} | ||
} | ||
return impl; | ||
} | ||
|
||
public static void setImpl(ResourcesLoaderImpl impl) { | ||
ResourcesLoader.impl = impl; | ||
} | ||
|
||
|
||
public static URL getResource(String path) { | ||
return getImpl().getResource(path, null); | ||
} | ||
|
||
|
||
public static URL getResource(String path, Class<?> parent) { | ||
return getImpl().getResource(path, parent); | ||
} | ||
|
||
public static InputStream getResourceAsStream(String path) { | ||
return getImpl().getResourceAsStream(path, null); | ||
} | ||
|
||
public static InputStream getResourceAsStream(String path,Class<?> clazz) { | ||
return getImpl().getResourceAsStream(path,clazz); | ||
} | ||
|
||
|
||
public static Enumeration<URL> getResources(String path ) throws IOException { | ||
return getImpl().getResources(path,null); | ||
} | ||
|
||
|
||
public static Enumeration<URL> getResources(String path,Class<?> clazz) throws IOException { | ||
return getImpl().getResources(path,clazz); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
jme3-core/src/main/java/com/jme3/util/res/ResourcesLoaderImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (c) 2009-2023 jMonkeyEngine | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are | ||
* met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* | ||
* * Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors | ||
* may be used to endorse or promote products derived from this software | ||
* without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package com.jme3.util.res; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.URL; | ||
import java.util.Enumeration; | ||
|
||
public interface ResourcesLoaderImpl { | ||
public URL getResource(String path, Class<?> clazz); | ||
public InputStream getResourceAsStream(String path, Class<?> clazz); | ||
public Enumeration<URL> getResources(String path, Class<?> clazz) throws IOException; | ||
} |
Oops, something went wrong.