org.apache.sling.jcr.classloader.internal
Class DynamicClassLoaderProviderImpl

java.lang.Object
  extended by org.apache.sling.jcr.classloader.internal.DynamicClassLoaderProviderImpl
All Implemented Interfaces:
ClassLoaderWriter, DynamicClassLoaderProvider

public class DynamicClassLoaderProviderImpl
extends Object
implements DynamicClassLoaderProvider, ClassLoaderWriter

The DynamicClassLoaderProviderImpl provides a class loader which loads classes from configured paths in the repository. In addition it implements ClassLoaderWriter and supports writing class files to the repository.


Field Summary
static String CLASS_PATH_DEFAULT
           
static String CLASS_PATH_PROP
           
static String OWNER_DEFAULT
          Default class loader owner.
static String OWNER_PROP
           
 
Constructor Summary
DynamicClassLoaderProviderImpl()
           
 
Method Summary
protected  void activate(org.osgi.service.component.ComponentContext componentContext)
          Activate this component.
protected  void deactivate(org.osgi.service.component.ComponentContext componentContext)
          Deactivate this component
 boolean delete(String name)
          Delete the class/resource
 ClassLoader getClassLoader(ClassLoader parent)
          Return the class loader used for dynamic class loading.
protected  String[] getClassPaths()
          Return the configured class paths
 InputStream getInputStream(String fileName)
          Get the input stream for a class or resource handled by the underlying class loader.
 long getLastModified(String fileName)
          Return the last modified for the class or resource.
 OutputStream getOutputStream(String name)
          Get the output stream for a class or resource handled by the underlying class loader.
protected  String getOwnerId()
          Return the owner id
 javax.jcr.Session getReadSession()
          Return the read session.
 void release(ClassLoader classLoader)
          Release the provided class loader.
 boolean rename(String oldName, String newName)
          Rename a class/resource.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_PATH_PROP

public static final String CLASS_PATH_PROP
See Also:
Constant Field Values

CLASS_PATH_DEFAULT

public static final String CLASS_PATH_DEFAULT
See Also:
Constant Field Values

OWNER_PROP

public static final String OWNER_PROP
See Also:
Constant Field Values

OWNER_DEFAULT

public static final String OWNER_DEFAULT
Default class loader owner.

See Also:
Constant Field Values
Constructor Detail

DynamicClassLoaderProviderImpl

public DynamicClassLoaderProviderImpl()
Method Detail

getClassLoader

public ClassLoader getClassLoader(ClassLoader parent)
Description copied from interface: DynamicClassLoaderProvider
Return the class loader used for dynamic class loading. The returned class loader should use the provided parent class loader as one of its parent class loaders. This ensures that the returned class loader has access to all dynamically loaded classes that are not part of this class loader. When the class loader is not needed anymore, it is released by calling the DynamicClassLoaderProvider.release(ClassLoader) method.

Specified by:
getClassLoader in interface DynamicClassLoaderProvider
Parameters:
parent - The parent class loader for this dynamic class loader.
Returns:
The class loader.
See Also:
DynamicClassLoaderProvider.getClassLoader(ClassLoader)

release

public void release(ClassLoader classLoader)
Description copied from interface: DynamicClassLoaderProvider
Release the provided class loader. When the class loader is not needed anymore, e.g. when the dynamic class loader is shutdown, it is released with this method. The implementation can use this hook to free any allocated resources etc.

Specified by:
release in interface DynamicClassLoaderProvider
Parameters:
classLoader - The class loader.
See Also:
DynamicClassLoaderProvider.release(java.lang.ClassLoader)

delete

public boolean delete(String name)
Description copied from interface: ClassLoaderWriter
Delete the class/resource

Specified by:
delete in interface ClassLoaderWriter
Parameters:
name - The path of the class/resource.
Returns:
true if the resource exists and could be deleted, false otherwise.
See Also:
ClassLoaderWriter.delete(java.lang.String)

getOutputStream

public OutputStream getOutputStream(String name)
Description copied from interface: ClassLoaderWriter
Get the output stream for a class or resource handled by the underlying class loader. If the resource/class does not exists it should be created.

Specified by:
getOutputStream in interface ClassLoaderWriter
Parameters:
name - The path of the class/resource.
Returns:
The output stream.
See Also:
ClassLoaderWriter.getOutputStream(java.lang.String)

rename

public boolean rename(String oldName,
                      String newName)
Description copied from interface: ClassLoaderWriter
Rename a class/resource.

Specified by:
rename in interface ClassLoaderWriter
Parameters:
oldName - The path of the class/resource.
newName - The new path.
Returns:
true if the renaming has been successful.
See Also:
ClassLoaderWriter.rename(java.lang.String, java.lang.String)

getInputStream

public InputStream getInputStream(String fileName)
                           throws IOException
Description copied from interface: ClassLoaderWriter
Get the input stream for a class or resource handled by the underlying class loader.

Specified by:
getInputStream in interface ClassLoaderWriter
Parameters:
fileName - The path of the class/resource.
Returns:
The input stream for the resource/class.
Throws:
IOException - If the resource/class does not exist.
See Also:
ClassLoaderWriter.getInputStream(java.lang.String)

getLastModified

public long getLastModified(String fileName)
Description copied from interface: ClassLoaderWriter
Return the last modified for the class or resource.

Specified by:
getLastModified in interface ClassLoaderWriter
Parameters:
fileName - The path of the class/resource.
Returns:
The last modified information or -1 if the information can't be detected.
See Also:
ClassLoaderWriter.getLastModified(java.lang.String)

activate

protected void activate(org.osgi.service.component.ComponentContext componentContext)
Activate this component.

Parameters:
componentContext - The component context.

deactivate

protected void deactivate(org.osgi.service.component.ComponentContext componentContext)
Deactivate this component

Parameters:
componentContext - The component context.

getOwnerId

protected String getOwnerId()
Return the owner id


getClassPaths

protected String[] getClassPaths()
Return the configured class paths


getReadSession

public javax.jcr.Session getReadSession()
                                 throws javax.jcr.RepositoryException
Return the read session.

Throws:
javax.jcr.RepositoryException


Copyright © 2007-2013 The Apache Software Foundation. All Rights Reserved.