Author: cziegeler Date: Mon Jan 25 12:52:10 2010 New Revision: 902799 URL: http://svn.apache.org/viewvc?rev=902799&view=rev Log: SLING-1316 - Include jackrabbit classloader code to adjust it for Sling needs - code import with first changes. Update to Java 5 code.
Modified: sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/DynamicRepositoryClassLoader.java sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/URLRepositoryClassLoader.java sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/net/JCRURLConnection.java Modified: sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/DynamicRepositoryClassLoader.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/DynamicRepositoryClassLoader.java?rev=902799&r1=902798&r2=902799&view=diff ============================================================================== --- sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/DynamicRepositoryClassLoader.java (original) +++ sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/DynamicRepositoryClassLoader.java Mon Jan 25 12:52:10 2010 @@ -83,7 +83,7 @@ * @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 @@ // 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 @@ // 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 @@ } // 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 @@ 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); Modified: sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/URLRepositoryClassLoader.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/URLRepositoryClassLoader.java?rev=902799&r1=902798&r2=902799&view=diff ============================================================================== --- sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/URLRepositoryClassLoader.java (original) +++ sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/URLRepositoryClassLoader.java Mon Jan 25 12:52:10 2010 @@ -229,7 +229,7 @@ * @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 @@ 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 @@ * 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 @@ 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 @@ /** * 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 @@ 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 @@ * @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 @@ * @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 @@ "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 @@ * @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) { /** Modified: sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/net/JCRURLConnection.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/net/JCRURLConnection.java?rev=902799&r1=902798&r2=902799&view=diff ============================================================================== --- sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/net/JCRURLConnection.java (original) +++ sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/net/JCRURLConnection.java Mon Jan 25 12:52:10 2010 @@ -37,7 +37,6 @@ 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 @@ * 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 @@ * 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 @@ * 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 @@ * <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 @@ } else { lastModified = 0; } - + if (parent.hasProperty("jcr:mimeType")) { contentType = parent.getProperty("jcr:mimeType").getString(); } else { @@ -389,11 +388,9 @@ : TEXT_PLAIN; } } - + if (parent.hasProperty("jcr:encoding")) { contentEncoding = parent.getProperty("jcr:encoding").getString(); - } else { - contentEncoding = null; } log.debug( @@ -567,8 +564,8 @@ * * @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 @@ /** * 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); } }