You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:46:59 UTC
[sling-org-apache-sling-jcr-classloader] 11/18: SLING-1316 -
Include jackrabbit classloader code to adjust it for Sling needs - code
import with first changes. Update to Java 5 code.
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.jcr.classloader-3.1.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-classloader.git
commit 631f9f957b45ce5ab833f5852ce497f135acec1b
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Mon Jan 25 12:52:10 2010 +0000
SLING-1316 - Include jackrabbit classloader code to adjust it for Sling needs - code import with first changes. Update to Java 5 code.
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/classloader@902799 13f79535-47bb-0310-9956-ffa450edef68
---
.../internal/DynamicRepositoryClassLoader.java | 12 ++++----
.../internal/URLRepositoryClassLoader.java | 33 +++++++++++-----------
.../classloader/internal/net/JCRURLConnection.java | 23 +++++++--------
3 files changed, 32 insertions(+), 36 deletions(-)
diff --git a/src/main/java/org/apache/sling/jcr/classloader/internal/DynamicRepositoryClassLoader.java b/src/main/java/org/apache/sling/jcr/classloader/internal/DynamicRepositoryClassLoader.java
index 35df60a..34cfc5f 100644
--- a/src/main/java/org/apache/sling/jcr/classloader/internal/DynamicRepositoryClassLoader.java
+++ b/src/main/java/org/apache/sling/jcr/classloader/internal/DynamicRepositoryClassLoader.java
@@ -83,7 +83,7 @@ public class DynamicRepositoryClassLoader
* @see #onEvent(EventIterator)
* @see #findClassLoaderResource(String)
*/
- private Map modTimeCache;
+ private Map<String, ClassLoaderResource> modTimeCache;
/**
* Flag indicating whether there are loaded classes which have later been
@@ -122,7 +122,7 @@ public class DynamicRepositoryClassLoader
// set fields
dirty = false;
- modTimeCache = new HashMap();
+ modTimeCache = new HashMap<String, ClassLoaderResource>();
// register with observation service and path pattern list
registerModificationListener();
@@ -152,7 +152,7 @@ public class DynamicRepositoryClassLoader
// set the configuration and fields
dirty = false;
- modTimeCache = new HashMap();
+ modTimeCache = new HashMap<String, ClassLoaderResource>();
// create a repository from the handles - might get a different one
setRepository(resetClassPathEntries(old.getRepository()));
@@ -277,8 +277,8 @@ public class DynamicRepositoryClassLoader
}
// Check whether any class has changed
- for (Iterator iter = getCachedResources(); iter.hasNext();) {
- if (expireResource((ClassLoaderResource) iter.next())) {
+ for (Iterator<ClassLoaderResource> iter = getCachedResources(); iter.hasNext();) {
+ if (expireResource(iter.next())) {
log.debug("shouldReload: Found expired resource, need reload");
return true;
}
@@ -475,7 +475,7 @@ public class DynamicRepositoryClassLoader
log.debug(
"onEvent: Item {} has been modified, checking with cache", path);
- ClassLoaderResource resource = (ClassLoaderResource) modTimeCache.get(path);
+ ClassLoaderResource resource = modTimeCache.get(path);
if (resource != null) {
log.debug("pageModified: Expiring cache entry {}", resource);
expireResource(resource);
diff --git a/src/main/java/org/apache/sling/jcr/classloader/internal/URLRepositoryClassLoader.java b/src/main/java/org/apache/sling/jcr/classloader/internal/URLRepositoryClassLoader.java
index 7755fd9..fddfcb9 100644
--- a/src/main/java/org/apache/sling/jcr/classloader/internal/URLRepositoryClassLoader.java
+++ b/src/main/java/org/apache/sling/jcr/classloader/internal/URLRepositoryClassLoader.java
@@ -229,7 +229,7 @@ public class URLRepositoryClassLoader extends URLClassLoader {
* @throws ClassNotFoundException If the named class could not be found or
* if this class loader has already been destroyed.
*/
- protected Class findClass(final String name) throws ClassNotFoundException {
+ protected Class<?> findClass(final String name) throws ClassNotFoundException {
if (isDestroyed()) {
throw new ClassNotFoundException(name + " (Classloader destroyed)");
@@ -238,10 +238,10 @@ public class URLRepositoryClassLoader extends URLClassLoader {
log.debug("findClass: Try to find class {}", name);
try {
- return (Class) AccessController
- .doPrivileged(new PrivilegedExceptionAction() {
+ return AccessController.doPrivileged(
+ new PrivilegedExceptionAction<Class<?>>() {
- public Object run() throws ClassNotFoundException {
+ public Class<?> run() throws ClassNotFoundException {
return findClassPrivileged(name);
}
});
@@ -288,15 +288,15 @@ public class URLRepositoryClassLoader extends URLClassLoader {
* empty enumeration if no resources are found by this class loader
* or if this class loader has already been destroyed.
*/
- public Enumeration findResources(String name) {
+ public Enumeration<URL> findResources(String name) {
if (isDestroyed()) {
log.warn("Destroyed class loader cannot find resources");
- return new Enumeration() {
+ return new Enumeration<URL>() {
public boolean hasMoreElements() {
return false;
}
- public Object nextElement() {
+ public URL nextElement() {
throw new NoSuchElementException("No Entries");
}
};
@@ -304,7 +304,7 @@ public class URLRepositoryClassLoader extends URLClassLoader {
log.debug("findResources: Try to find resources for {}", name);
- List list = new LinkedList();
+ List<URL> list = new LinkedList<URL>();
for (int i=0; i < repository.length; i++) {
final ClassPathEntry cp = repository[i];
log.debug("findResources: Trying {}", cp);
@@ -328,8 +328,7 @@ public class URLRepositoryClassLoader extends URLClassLoader {
/**
* Returns the search path of URLs for loading classes and resources.
* This includes the original list of URLs specified to the constructor,
- * along with any URLs subsequently appended by the {@link #addURL(URL)}
- * and {@link #addHandle(String)} methods.
+ * along with any URLs subsequently appended by the {@link #addURL(URL)}.
*
* @return the search path of URLs for loading classes and resources. The
* list is empty, if this class loader has already been destroyed.
@@ -341,14 +340,14 @@ public class URLRepositoryClassLoader extends URLClassLoader {
return new URL[0];
}
- List urls = new ArrayList();
+ List<URL> urls = new ArrayList<URL>();
for (int i=0; i < repository.length; i++) {
URL url = repository[i].toURL();
if (url != null) {
urls.add(url);
}
}
- return (URL[]) urls.toArray(new URL[urls.size()]);
+ return urls.toArray(new URL[urls.size()]);
}
/**
@@ -423,7 +422,7 @@ public class URLRepositoryClassLoader extends URLClassLoader {
* @throws NullPointerException If this class loader has already been
* destroyed.
*/
- /* package */ Iterator getCachedResources() {
+ /* package */ Iterator<ClassLoaderResource> getCachedResources() {
return cache.values().iterator();
}
@@ -607,7 +606,7 @@ public class URLRepositoryClassLoader extends URLClassLoader {
* @throws NullPointerException If this class loader has already been
* destroyed.
*/
- private Class findClassPrivileged(String name) throws ClassNotFoundException {
+ private Class<?> findClassPrivileged(String name) throws ClassNotFoundException {
// prepare the name of the class
final String path = name.replace('.', '/').concat(".class");
@@ -623,7 +622,7 @@ public class URLRepositoryClassLoader extends URLClassLoader {
"findClassPrivileged: Loading class from {}, created {}",
res, new Date(res.getLastModificationTime()));
- Class c = defineClass(name, res);
+ Class<?> c = defineClass(name, res);
if (c == null) {
log.warn("defineClass returned null for class {}", name);
throw new ClassNotFoundException(name);
@@ -703,12 +702,12 @@ public class URLRepositoryClassLoader extends URLClassLoader {
* @throws ClassFormatError If the class bytes read from the resource are
* not a valid class.
*/
- private Class defineClass(String name, ClassLoaderResource res)
+ private Class<?> defineClass(String name, ClassLoaderResource res)
throws IOException, RepositoryException {
log.debug("defineClass({}, {})", name, res);
- Class clazz = res.getLoadedClass();
+ Class<?> clazz = res.getLoadedClass();
if (clazz == null) {
/**
diff --git a/src/main/java/org/apache/sling/jcr/classloader/internal/net/JCRURLConnection.java b/src/main/java/org/apache/sling/jcr/classloader/internal/net/JCRURLConnection.java
index 9e1471a..1cf7509 100644
--- a/src/main/java/org/apache/sling/jcr/classloader/internal/net/JCRURLConnection.java
+++ b/src/main/java/org/apache/sling/jcr/classloader/internal/net/JCRURLConnection.java
@@ -37,7 +37,6 @@ import org.apache.sling.jcr.classloader.internal.Util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
/**
* The <code>JCRURLConnection</code> is the <code>URLConnection</code>
* implementation to access the data addressed by a JCR Repository URL.
@@ -194,7 +193,7 @@ public class JCRURLConnection extends URLConnection {
* atom.
* <p>
* Implementations are free to decide, how to define the content type. But
- * they are required to set the type in the {@link #connect(Ticket)}method.
+ * they are required to set the type in the {@link #connect()}method.
*
* @see #getContentType()
* @see #connect()
@@ -207,7 +206,7 @@ public class JCRURLConnection extends URLConnection {
* atom.
* <p>
* Implementations are free to decide, how to define the content type. But
- * they are required to set the type in the {@link #connect(Ticket)}method.
+ * they are required to set the type in the {@link #connect()}method.
*
* @see #getContentEncoding()
* @see #connect()
@@ -219,7 +218,7 @@ public class JCRURLConnection extends URLConnection {
* status information of the base atom.
* <p>
* Implementations are free to decide, how to define the content length. But
- * they are required to set the type in the {@link #connect(Ticket)}method.
+ * they are required to set the type in the {@link #connect()}method.
*
* @see #getContentLength()
* @see #connect()
@@ -231,7 +230,7 @@ public class JCRURLConnection extends URLConnection {
* <p>
* Implementations are free to decide, how to define the last modification
* time. But they are required to set the type in the
- * {@link #connect(Ticket)}method.
+ * {@link #connect()}method.
*
* @see #getLastModified()
* @see #connect()
@@ -378,7 +377,7 @@ public class JCRURLConnection extends URLConnection {
} else {
lastModified = 0;
}
-
+
if (parent.hasProperty("jcr:mimeType")) {
contentType = parent.getProperty("jcr:mimeType").getString();
} else {
@@ -389,11 +388,9 @@ public class JCRURLConnection extends URLConnection {
: TEXT_PLAIN;
}
}
-
+
if (parent.hasProperty("jcr:encoding")) {
contentEncoding = parent.getProperty("jcr:encoding").getString();
- } else {
- contentEncoding = null;
}
log.debug(
@@ -567,8 +564,8 @@ public class JCRURLConnection extends URLConnection {
*
* @see #connect()
*/
- public Map getHeaderFields() {
- Map fieldMap = new HashMap();
+ public Map<String, List<String>> getHeaderFields() {
+ Map<String, List<String>> fieldMap = new HashMap<String, List<String>>();
try {
connect();
@@ -770,9 +767,9 @@ public class JCRURLConnection extends URLConnection {
/**
* Returns an unmodifiable list containing just the given string value.
*/
- private List toList(String value) {
+ private List<String> toList(String value) {
String[] values = { value };
- List valueList = Arrays.asList(values);
+ List<String> valueList = Arrays.asList(values);
return Collections.unmodifiableList(valueList);
}
}
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.