org.apache.sling.jcr.base
Class AbstractSlingRepository

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

public abstract class AbstractSlingRepository
extends AbstractNamespaceMappingRepository
implements org.apache.sling.jcr.api.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.

As of version 2.2 (bundle version 2.2.0) the registration of repository services based on this abstract base class works differently. To be able to know the calling bundle to implement the loginService(String, String) method the service is registered as a service factory. Yet this component is registered as a non-service component with Declarative Services handling its registration itself so the the ServiceFactory cannot simply create instances of this class. The solution is for the service factory to create a proxy to the actual component object. All method calls are just routed through with the exception of the loginService(String, String) method which is routed to a new internal method taking the calling bundle as an additional argument.

The changes to support this new registration mechanism are as follows:

Implementations of this class overwriting the registerService() method must replace this overwritten method with overwriting the new getServiceRegistrationInterfaces() and/or getServiceRegistrationProperties() methods.


Field Summary
static String DEFAULT_ADMIN_PASS
           
static String DEFAULT_ADMIN_USER
           
static String DEFAULT_ANONYMOUS_PASS
           
static String DEFAULT_ANONYMOUS_USER
           
static boolean DEFAULT_LOGIN_ADMIN_ENABLED
           
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_LOGIN_ADMIN_ENABLED
           
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.
protected  String[] getServiceRegistrationInterfaces()
          Returns the service types to be used to register the repository service in registerService().
protected  Dictionary<String,Object> getServiceRegistrationProperties()
          Return the service registration properties to be used to register the repository service in registerService().
 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)
           
protected  javax.jcr.Session loginAdministrativeInternal(String workspace)
          Actual (unprotected) implementation of administrative login.
 javax.jcr.Session loginService(String subServiceName, String workspace)
          This method always throws LoginException because it does not directly have the calling bundle at its disposition to decide on the required service name.
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 the types provided by the getServiceRegistrationInterfaces() method and properties provided by the getServiceRegistrationProperties() method.
 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 org.apache.sling.jcr.base.AbstractNamespaceMappingRepository
getNamespaceAwareSession, setup, tearDown
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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_LOGIN_ADMIN_ENABLED

public static final boolean DEFAULT_LOGIN_ADMIN_ENABLED
See Also:
Constant Field Values

PROPERTY_DEFAULT_WORKSPACE

@Property
public static final String PROPERTY_DEFAULT_WORKSPACE
See Also:
Constant Field Values

PROPERTY_ANONYMOUS_USER

@Property(value="anonymous")
public static final String PROPERTY_ANONYMOUS_USER
See Also:
Constant Field Values

PROPERTY_ANONYMOUS_PASS

@Property(value="anonymous")
public static final String PROPERTY_ANONYMOUS_PASS
See Also:
Constant Field Values

PROPERTY_ADMIN_USER

@Property(value="admin")
public static final String PROPERTY_ADMIN_USER
See Also:
Constant Field Values

PROPERTY_ADMIN_PASS

@Property(value="admin")
public static final String PROPERTY_ADMIN_PASS
See Also:
Constant Field Values

PROPERTY_LOGIN_ADMIN_ENABLED

@Property(boolValue=true)
public static final String PROPERTY_LOGIN_ADMIN_ENABLED
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

PROPERTY_POLL_ACTIVE

@Property(intValue=10)
public static final String PROPERTY_POLL_ACTIVE
See Also:
Constant Field Values

PROPERTY_POLL_INACTIVE

@Property(intValue=10)
public static final String PROPERTY_POLL_INACTIVE
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 org.apache.sling.jcr.api.SlingRepository

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 final javax.jcr.Session loginAdministrative(String workspace)
                                            throws javax.jcr.RepositoryException
Specified by:
loginAdministrative in interface org.apache.sling.jcr.api.SlingRepository
Throws:
javax.jcr.RepositoryException

loginService

public final javax.jcr.Session loginService(String subServiceName,
                                            String workspace)
                                     throws javax.jcr.LoginException,
                                            javax.jcr.RepositoryException
This method always throws LoginException because it does not directly have the calling bundle at its disposition to decide on the required service name.

This method is final and cannot be overwritten by extensions. See the class comments for full details on how this works.

Specified by:
loginService in interface org.apache.sling.jcr.api.SlingRepository
Throws:
javax.jcr.LoginException
javax.jcr.RepositoryException
Since:
2.2 (bundle version 2.2.0)

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

loginAdministrativeInternal

protected javax.jcr.Session loginAdministrativeInternal(String workspace)
                                                 throws javax.jcr.RepositoryException
Actual (unprotected) implementation of administrative login.

This methods is internally used to administratively login.

Parameters:
workspace - The workspace to login to (or null to use the default workspace.
Returns:
The administrative session
Throws:
javax.jcr.RepositoryException - if an error occurrs.

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 final org.osgi.framework.ServiceRegistration registerService()
Registers this component as an OSGi service with the types provided by the getServiceRegistrationInterfaces() method and properties provided by the getServiceRegistrationProperties() method.

As of version 2.2 (bundle version 2.2.0) this method is final and cannot be overwritten because the mechanism of service registration using a service factory is required to fully implement the loginService(String, String) method. See the class comments for full details on how this works.

Returns:
The OSGi ServiceRegistration object representing the registered service.

getServiceRegistrationProperties

protected Dictionary<String,Object> getServiceRegistrationProperties()
Return the service registration properties to be used to register the repository service in registerService().

This method may be overwritten to return additional service registration properties. But it is strongly recommended to always include the properties returned from this method.

Returns:
The service registration properties to be used to register the repository service in registerService()
Since:
2.2 (bundle version 2.2.0)

getServiceRegistrationInterfaces

protected String[] getServiceRegistrationInterfaces()
Returns the service types to be used to register the repository service in registerService(). All interfaces returned must be accessible to the class loader of the class of this instance.

This method may be overwritten to return additional types but the types returned from this base implementation must always be included.

Returns:
The service types to be used to register the repository service in registerService()
Since:
2.2 (bundle version 2.2.0)

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-2014 The Apache Software Foundation. All Rights Reserved.