org.apache.sling.jcr.base
Class AbstractSlingRepository

java.lang.Object
  extended by org.apache.sling.jcr.base.AbstractSlingRepository
All Implemented Interfaces:
Runnable, javax.jcr.Repository, SlingRepository

public abstract class AbstractSlingRepository
extends Object
implements SlingRepository, Runnable

The AbstractSlingRepository is an abstract implementation of the SlingRepository interface which provides default support for attached repositories as well as ensuring live repository connection, reconnecting if needed. Implementations of the SlingRepository interface may wish to extend this class to benefit from a default implementation.


Field Summary
static String DEFAULT_ADMIN_PASS
           
static String DEFAULT_ADMIN_USER
           
static String DEFAULT_ANONYMOUS_PASS
           
static String DEFAULT_ANONYMOUS_USER
           
static int DEFAULT_POLL_ACTIVE
          The default value for the number of seconds to wait between two consecutive checks while the repository is active (value is 10).
static int DEFAULT_POLL_INACTIVE
          The default value for the number of seconds to wait between two consecutive checks while the repository is not active (value is 10).
static int MIN_POLL
          The minimum number of seconds allowed for any of the two poll times
static String PROPERTY_ADMIN_PASS
           
static String PROPERTY_ADMIN_USER
           
static String PROPERTY_ANONYMOUS_PASS
           
static String PROPERTY_ANONYMOUS_USER
           
static String PROPERTY_DEFAULT_WORKSPACE
           
static String PROPERTY_POLL_ACTIVE
           
static String PROPERTY_POLL_INACTIVE
           
 
Fields inherited from interface javax.jcr.Repository
IDENTIFIER_STABILITY, IDENTIFIER_STABILITY_INDEFINITE_DURATION, IDENTIFIER_STABILITY_METHOD_DURATION, IDENTIFIER_STABILITY_SAVE_DURATION, IDENTIFIER_STABILITY_SESSION_DURATION, LEVEL_1_SUPPORTED, LEVEL_2_SUPPORTED, NODE_TYPE_MANAGEMENT_AUTOCREATED_DEFINITIONS_SUPPORTED, NODE_TYPE_MANAGEMENT_INHERITANCE, NODE_TYPE_MANAGEMENT_INHERITANCE_MINIMAL, NODE_TYPE_MANAGEMENT_INHERITANCE_MULTIPLE, NODE_TYPE_MANAGEMENT_INHERITANCE_SINGLE, NODE_TYPE_MANAGEMENT_MULTIPLE_BINARY_PROPERTIES_SUPPORTED, NODE_TYPE_MANAGEMENT_MULTIVALUED_PROPERTIES_SUPPORTED, NODE_TYPE_MANAGEMENT_ORDERABLE_CHILD_NODES_SUPPORTED, NODE_TYPE_MANAGEMENT_OVERRIDES_SUPPORTED, NODE_TYPE_MANAGEMENT_PRIMARY_ITEM_NAME_SUPPORTED, NODE_TYPE_MANAGEMENT_PROPERTY_TYPES, NODE_TYPE_MANAGEMENT_RESIDUAL_DEFINITIONS_SUPPORTED, NODE_TYPE_MANAGEMENT_SAME_NAME_SIBLINGS_SUPPORTED, NODE_TYPE_MANAGEMENT_UPDATE_IN_USE_SUPORTED, NODE_TYPE_MANAGEMENT_VALUE_CONSTRAINTS_SUPPORTED, OPTION_ACCESS_CONTROL_SUPPORTED, OPTION_ACTIVITIES_SUPPORTED, OPTION_BASELINES_SUPPORTED, OPTION_JOURNALED_OBSERVATION_SUPPORTED, OPTION_LIFECYCLE_SUPPORTED, OPTION_LOCKING_SUPPORTED, OPTION_NODE_AND_PROPERTY_WITH_SAME_NAME_SUPPORTED, OPTION_NODE_TYPE_MANAGEMENT_SUPPORTED, OPTION_OBSERVATION_SUPPORTED, OPTION_QUERY_SQL_SUPPORTED, OPTION_RETENTION_SUPPORTED, OPTION_SHAREABLE_NODES_SUPPORTED, OPTION_SIMPLE_VERSIONING_SUPPORTED, OPTION_TRANSACTIONS_SUPPORTED, OPTION_UNFILED_CONTENT_SUPPORTED, OPTION_UPDATE_MIXIN_NODE_TYPES_SUPPORTED, OPTION_UPDATE_PRIMARY_NODE_TYPE_SUPPORTED, OPTION_VERSIONING_SUPPORTED, OPTION_WORKSPACE_MANAGEMENT_SUPPORTED, OPTION_XML_EXPORT_SUPPORTED, OPTION_XML_IMPORT_SUPPORTED, QUERY_FULL_TEXT_SEARCH_SUPPORTED, QUERY_JOINS, QUERY_JOINS_INNER, QUERY_JOINS_INNER_OUTER, QUERY_JOINS_NONE, QUERY_LANGUAGES, QUERY_STORED_QUERIES_SUPPORTED, QUERY_XPATH_DOC_ORDER, QUERY_XPATH_POS_INDEX, REP_NAME_DESC, REP_VENDOR_DESC, REP_VENDOR_URL_DESC, REP_VERSION_DESC, SPEC_NAME_DESC, SPEC_VERSION_DESC, WRITE_SUPPORTED
 
Constructor Summary
protected AbstractSlingRepository()
           
 
Method Summary
protected  javax.jcr.Repository acquireRepository()
          Acquires the repository by calling the RepositoryAccessor.getRepositoryFromURL(String) with the value of the RepositoryAccessor.REPOSITORY_URL_OVERRIDE_PROPERTY framework or configuration property.
protected  void activate(org.osgi.service.component.ComponentContext componentContext)
          This method must be called if overwritten by implementations !!
protected  void bindLog(org.osgi.service.log.LogService log)
           
protected  void deactivate(org.osgi.service.component.ComponentContext componentContext)
          This method must be called if overwritten by implementations !!
protected  void disposeRepository(javax.jcr.Repository repository)
          Disposes off the given repository.
protected  javax.jcr.Credentials getAdministrativeCredentials(String adminUser)
           
protected  javax.jcr.Credentials getAnonCredentials(String anonUser)
           
protected  org.osgi.service.component.ComponentContext getComponentContext()
           
 String getDefaultWorkspace()
          Returns the default workspace, which may be null meaning to use the repository provided default workspace.
 String getDescriptor(String name)
           
 String[] getDescriptorKeys()
           
 javax.jcr.Value getDescriptorValue(String key)
          
 javax.jcr.Value[] getDescriptorValues(String key)
          
protected  javax.jcr.Repository getRepository()
          Returns the repository underlying this instance or null if no repository is currently being available.
protected  RepositoryAccessor getRepositoryAccessor()
          Returns a new instance of the RepositoryAccessor class to access a repository over RMI or through JNDI.
 boolean isSingleValueDescriptor(String key)
          
 boolean isStandardDescriptor(String key)
          
protected  void log(int level, String message)
           
protected  void log(int level, String message, Throwable t)
           
 javax.jcr.Session login()
          Logs in as an anonymous user.
 javax.jcr.Session login(javax.jcr.Credentials credentials)
           
 javax.jcr.Session login(javax.jcr.Credentials credentials, String workspace)
           
 javax.jcr.Session login(String workspace)
           
 javax.jcr.Session loginAdministrative(String workspace)
          Returns a session to the default workspace which has administrative powers.
protected  boolean pingAndCheck()
          Ping our current repository and check that admin login (required by Sling) works.
protected  boolean pingRepository(javax.jcr.Repository repository)
          Checks that the given repository is still available.
protected  org.osgi.framework.ServiceRegistration registerService()
          Registers this component as an OSGi service with type javax.jcr.Repository and org.apache.sling.jcr.api.SlingRepository using the component properties as service registration properties.
 void run()
           
protected  void setupRepository(javax.jcr.Repository repository)
          This method is called after a repository has been acquired by acquireRepository() but before the repository is registered as a service.
protected  void tearDown(javax.jcr.Repository repository)
          Performs any cleanups before the repository is actually disposed off by the disposeRepository(Repository) method.
protected  void unbindLog(org.osgi.service.log.LogService log)
           
protected  void unregisterService(org.osgi.framework.ServiceRegistration serviceRegistration)
          Unregisters the service represented by the serviceRegistration.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPERTY_DEFAULT_WORKSPACE

public static final String PROPERTY_DEFAULT_WORKSPACE
See Also:
Constant Field Values

PROPERTY_ANONYMOUS_USER

public static final String PROPERTY_ANONYMOUS_USER
See Also:
Constant Field Values

PROPERTY_ANONYMOUS_PASS

public static final String PROPERTY_ANONYMOUS_PASS
See Also:
Constant Field Values

PROPERTY_ADMIN_USER

public static final String PROPERTY_ADMIN_USER
See Also:
Constant Field Values

PROPERTY_ADMIN_PASS

public static final String PROPERTY_ADMIN_PASS
See Also:
Constant Field Values

PROPERTY_POLL_ACTIVE

public static final String PROPERTY_POLL_ACTIVE
See Also:
Constant Field Values

PROPERTY_POLL_INACTIVE

public static final String PROPERTY_POLL_INACTIVE
See Also:
Constant Field Values

DEFAULT_ANONYMOUS_USER

public static final String DEFAULT_ANONYMOUS_USER
See Also:
Constant Field Values

DEFAULT_ANONYMOUS_PASS

public static final String DEFAULT_ANONYMOUS_PASS
See Also:
Constant Field Values

DEFAULT_ADMIN_USER

public static final String DEFAULT_ADMIN_USER
See Also:
Constant Field Values

DEFAULT_ADMIN_PASS

public static final String DEFAULT_ADMIN_PASS
See Also:
Constant Field Values

DEFAULT_POLL_ACTIVE

public static final int DEFAULT_POLL_ACTIVE
The default value for the number of seconds to wait between two consecutive checks while the repository is active (value is 10).

See Also:
Constant Field Values

DEFAULT_POLL_INACTIVE

public static final int DEFAULT_POLL_INACTIVE
The default value for the number of seconds to wait between two consecutive checks while the repository is not active (value is 10).

See Also:
Constant Field Values

MIN_POLL

public static final int MIN_POLL
The minimum number of seconds allowed for any of the two poll times

See Also:
Constant Field Values
Constructor Detail

AbstractSlingRepository

protected AbstractSlingRepository()
Method Detail

getDefaultWorkspace

public final String getDefaultWorkspace()
Returns the default workspace, which may be null meaning to use the repository provided default workspace. Declared final to make sure the SLING-256 rule is enforced.

Specified by:
getDefaultWorkspace in interface SlingRepository
Returns:
null if the configured default workspace name is empty, SLING-256

login

public javax.jcr.Session login()
                        throws javax.jcr.LoginException,
                               javax.jcr.RepositoryException
Logs in as an anonymous user. This implementation simply returns the result of calling login(Credentials, String)

Specified by:
login in interface javax.jcr.Repository
Throws:
javax.jcr.LoginException
javax.jcr.RepositoryException

loginAdministrative

public javax.jcr.Session loginAdministrative(String workspace)
                                      throws javax.jcr.RepositoryException
Description copied from interface: SlingRepository
Returns a session to the default workspace which has administrative powers.

NOTE: This method is intended for use by infrastructure bundles to access the repository and provide general services. This method MUST not be used to handle client requests of whatever kinds. To handle client requests a regular authenticated session retrieved through Repository.login(javax.jcr.Credentials, String) or Session.impersonate(javax.jcr.Credentials) must be used.

Specified by:
loginAdministrative in interface SlingRepository
Parameters:
workspace - The name of the workspace to which to get an administrative session. If null the SlingRepository.getDefaultWorkspace() default workspace is assumed.
Throws:
javax.jcr.RepositoryException

login

public javax.jcr.Session login(javax.jcr.Credentials credentials)
                        throws javax.jcr.LoginException,
                               javax.jcr.RepositoryException
Specified by:
login in interface javax.jcr.Repository
Throws:
javax.jcr.LoginException
javax.jcr.RepositoryException

login

public javax.jcr.Session login(String workspace)
                        throws javax.jcr.LoginException,
                               javax.jcr.NoSuchWorkspaceException,
                               javax.jcr.RepositoryException
Specified by:
login in interface javax.jcr.Repository
Throws:
javax.jcr.LoginException
javax.jcr.NoSuchWorkspaceException
javax.jcr.RepositoryException

login

public javax.jcr.Session login(javax.jcr.Credentials credentials,
                               String workspace)
                        throws javax.jcr.LoginException,
                               javax.jcr.NoSuchWorkspaceException,
                               javax.jcr.RepositoryException
Specified by:
login in interface javax.jcr.Repository
Throws:
javax.jcr.LoginException
javax.jcr.NoSuchWorkspaceException
javax.jcr.RepositoryException

getAnonCredentials

protected javax.jcr.Credentials getAnonCredentials(String anonUser)
Parameters:
anonUser - the user name of the anon user.
Returns:
a Credentials implementation that represents the anon user.

getAdministrativeCredentials

protected javax.jcr.Credentials getAdministrativeCredentials(String adminUser)
Parameters:
adminUser - the name of the administrative user.
Returns:
a Credentials implementation that represents the administrative user.

getDescriptor

public String getDescriptor(String name)
Specified by:
getDescriptor in interface javax.jcr.Repository

getDescriptorKeys

public String[] getDescriptorKeys()
Specified by:
getDescriptorKeys in interface javax.jcr.Repository

getDescriptorValue

public javax.jcr.Value getDescriptorValue(String key)

Specified by:
getDescriptorValue in interface javax.jcr.Repository

getDescriptorValues

public javax.jcr.Value[] getDescriptorValues(String key)

Specified by:
getDescriptorValues in interface javax.jcr.Repository

isSingleValueDescriptor

public boolean isSingleValueDescriptor(String key)

Specified by:
isSingleValueDescriptor in interface javax.jcr.Repository

isStandardDescriptor

public boolean isStandardDescriptor(String key)

Specified by:
isStandardDescriptor in interface javax.jcr.Repository

log

protected void log(int level,
                   String message)

log

protected void log(int level,
                   String message,
                   Throwable t)

getRepositoryAccessor

protected RepositoryAccessor getRepositoryAccessor()
Returns a new instance of the RepositoryAccessor class to access a repository over RMI or through JNDI.

Extensions of this method may return an extension of the RepositoryAccessor class if the provide extended functionality.


acquireRepository

protected javax.jcr.Repository acquireRepository()
Acquires the repository by calling the RepositoryAccessor.getRepositoryFromURL(String) with the value of the RepositoryAccessor.REPOSITORY_URL_OVERRIDE_PROPERTY framework or configuration property. If the property exists and a repository can be accessed using this property, that repository is returned. Otherwise null is returned.

Extensions of this class may overwrite this method with implementation specific acquisition semantics and may call this base class method or not as the implementation sees fit.

This method does not throw any Throwable but instead just returns null if not repository is available. Any problems trying to acquire the repository must be caught and logged as appropriate.

Returns:
The acquired JCR Repository or null if not repository can be acquired.

setupRepository

protected void setupRepository(javax.jcr.Repository repository)
This method is called after a repository has been acquired by acquireRepository() but before the repository is registered as a service.

Implementations may overwrite this method but MUST call this base class implementation first.

Parameters:
repository - The JCR Repository to setup.

registerService

protected org.osgi.framework.ServiceRegistration registerService()
Registers this component as an OSGi service with type javax.jcr.Repository and org.apache.sling.jcr.api.SlingRepository using the component properties as service registration properties.

This method may be overwritten to register the component with different types.

Returns:
The OSGi ServiceRegistration object representing the registered service.

getRepository

protected javax.jcr.Repository getRepository()
Returns the repository underlying this instance or null if no repository is currently being available.


pingRepository

protected boolean pingRepository(javax.jcr.Repository repository)
Checks that the given repository is still available. This implementation tries to get the Repository.SPEC_NAME_DESC descriptor from the repository and returns true if the returned value is not null.

Extensions of this class may overwrite this method to implement different access checks. The contract of this method must be obeyed, though in a sense, the true must only be returned if repository is actually usable.

Parameters:
repository - The JCR Repository to check for availability.
Returns:
true if repository is not null and accessible.

pingAndCheck

protected boolean pingAndCheck()
Ping our current repository and check that admin login (required by Sling) works.


unregisterService

protected void unregisterService(org.osgi.framework.ServiceRegistration serviceRegistration)
Unregisters the service represented by the serviceRegistration.

This method may be overwritten by extensions of this class as long as it is made sure, the given service registration is unregistered.


tearDown

protected void tearDown(javax.jcr.Repository repository)
Performs any cleanups before the repository is actually disposed off by the disposeRepository(Repository) method.

This method is meant for cleanup tasks before the repository is actually disposed off. Extensions of this class may overwrite but must call this base class implementation.

Parameters:
repository -

disposeRepository

protected void disposeRepository(javax.jcr.Repository repository)
Disposes off the given repository. This base class implementation does nothing. Extensions should overwrite if any special disposal operation is required.

Parameters:
repository -

getComponentContext

protected org.osgi.service.component.ComponentContext getComponentContext()

activate

protected void activate(org.osgi.service.component.ComponentContext componentContext)
                 throws Exception
This method must be called if overwritten by implementations !!

Throws:
nothing, - but allow derived classes to throw any Exception
Exception

deactivate

protected void deactivate(org.osgi.service.component.ComponentContext componentContext)
This method must be called if overwritten by implementations !!

Parameters:
componentContext -

bindLog

protected void bindLog(org.osgi.service.log.LogService log)

unbindLog

protected void unbindLog(org.osgi.service.log.LogService log)

run

public void run()
Specified by:
run in interface Runnable


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