public abstract class AbstractSlingRepository extends AbstractNamespaceMappingRepository implements SlingRepository, java.lang.Runnable
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.| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
DEFAULT_ADMIN_PASS |
static java.lang.String |
DEFAULT_ADMIN_USER |
static java.lang.String |
DEFAULT_ANONYMOUS_PASS |
static java.lang.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 java.lang.String |
PROPERTY_ADMIN_PASS |
static java.lang.String |
PROPERTY_ADMIN_USER |
static java.lang.String |
PROPERTY_ANONYMOUS_PASS |
static java.lang.String |
PROPERTY_ANONYMOUS_USER |
static java.lang.String |
PROPERTY_DEFAULT_WORKSPACE |
static java.lang.String |
PROPERTY_POLL_ACTIVE |
static java.lang.String |
PROPERTY_POLL_INACTIVE |
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractSlingRepository() |
| Modifier and Type | Method and Description |
|---|---|
protected 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(ComponentContext componentContext)
This method must be called if overwritten by implementations !!
|
protected void |
bindLog(LogService log) |
protected void |
deactivate(ComponentContext componentContext)
This method must be called if overwritten by implementations !!
|
protected void |
disposeRepository(Repository repository)
Disposes off the given
repository. |
protected Credentials |
getAdministrativeCredentials(java.lang.String adminUser) |
protected Credentials |
getAnonCredentials(java.lang.String anonUser) |
protected ComponentContext |
getComponentContext() |
java.lang.String |
getDefaultWorkspace()
Returns the default workspace, which may be
null meaning
to use the repository provided default workspace. |
java.lang.String |
getDescriptor(java.lang.String name) |
java.lang.String[] |
getDescriptorKeys() |
Value |
getDescriptorValue(java.lang.String key) |
Value[] |
getDescriptorValues(java.lang.String key) |
protected 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(java.lang.String key) |
boolean |
isStandardDescriptor(java.lang.String key) |
protected void |
log(int level,
java.lang.String message) |
protected void |
log(int level,
java.lang.String message,
java.lang.Throwable t) |
Session |
login()
Logs in as an anonymous user.
|
Session |
login(Credentials credentials) |
Session |
login(Credentials credentials,
java.lang.String workspace) |
Session |
login(java.lang.String workspace) |
Session |
loginAdministrative(java.lang.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(Repository repository)
Checks that the given
repository is still available. |
protected 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(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(Repository repository)
Performs any cleanups before the repository is actually disposed off by
the
disposeRepository(Repository) method. |
protected void |
unbindLog(LogService log) |
protected void |
unregisterService(ServiceRegistration serviceRegistration)
Unregisters the service represented by the
serviceRegistration. |
getNamespaceAwareSession, setup, tearDownpublic static final java.lang.String DEFAULT_ANONYMOUS_USER
public static final java.lang.String DEFAULT_ANONYMOUS_PASS
public static final java.lang.String DEFAULT_ADMIN_USER
public static final java.lang.String DEFAULT_ADMIN_PASS
public static final java.lang.String PROPERTY_DEFAULT_WORKSPACE
public static final java.lang.String PROPERTY_ANONYMOUS_USER
public static final java.lang.String PROPERTY_ANONYMOUS_PASS
public static final java.lang.String PROPERTY_ADMIN_USER
public static final java.lang.String PROPERTY_ADMIN_PASS
public static final int DEFAULT_POLL_ACTIVE
public static final int DEFAULT_POLL_INACTIVE
public static final java.lang.String PROPERTY_POLL_ACTIVE
public static final java.lang.String PROPERTY_POLL_INACTIVE
public static final int MIN_POLL
public final java.lang.String getDefaultWorkspace()
null meaning
to use the repository provided default workspace. Declared final to make
sure the SLING-256 rule is enforced.getDefaultWorkspace in interface SlingRepositorypublic Session login()
throws LoginException,
RepositoryException
login(Credentials, String)LoginExceptionRepositoryExceptionpublic Session loginAdministrative(java.lang.String workspace)
throws RepositoryException
SlingRepository
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 #login(javax.jcr.Credentials, String) or
Session#impersonate(javax.jcr.Credentials) must be used.
loginAdministrative in interface SlingRepositoryworkspace - The name of the workspace to which to get an
administrative session. If null the
SlingRepository.getDefaultWorkspace() default workspace is assumed.RepositoryExceptionpublic Session login(Credentials credentials)
throws LoginException,
RepositoryException
LoginExceptionRepositoryExceptionpublic Session login(java.lang.String workspace)
throws LoginException,
NoSuchWorkspaceException,
RepositoryException
LoginExceptionNoSuchWorkspaceExceptionRepositoryExceptionpublic Session login(Credentials credentials,
java.lang.String workspace)
throws LoginException,
NoSuchWorkspaceException,
RepositoryException
LoginExceptionNoSuchWorkspaceExceptionRepositoryExceptionprotected Credentials getAnonCredentials(java.lang.String anonUser)
anonUser - the user name of the anon user.protected Credentials getAdministrativeCredentials(java.lang.String adminUser)
adminUser - the name of the administrative user.public java.lang.String getDescriptor(java.lang.String name)
public java.lang.String[] getDescriptorKeys()
public Value getDescriptorValue(java.lang.String key)
public Value[] getDescriptorValues(java.lang.String key)
public boolean isSingleValueDescriptor(java.lang.String key)
public boolean isStandardDescriptor(java.lang.String key)
protected void log(int level,
java.lang.String message)
protected void log(int level,
java.lang.String message,
java.lang.Throwable t)
protected RepositoryAccessor getRepositoryAccessor()
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.
protected Repository acquireRepository()
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.
Repository or null
if not repository can be acquired.protected void setupRepository(Repository repository)
acquireRepository() but before the repository is registered as a
service.
Implementations may overwrite this method but MUST call this base class implementation first.
repository - The JCR Repository to setup.protected ServiceRegistration registerService()
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.
ServiceRegistration object representing
the registered service.protected Repository getRepository()
null if
no repository is currently being available.protected boolean pingRepository(Repository repository)
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.
repository - The JCR Repository to check for
availability.true if repository is not
null and accessible.protected boolean pingAndCheck()
protected void unregisterService(ServiceRegistration serviceRegistration)
serviceRegistration.
This method may be overwritten by extensions of this class as long as it is made sure, the given service registration is unregistered.
protected void tearDown(Repository repository)
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.
repository - protected void disposeRepository(Repository repository)
repository. This base class
implementation does nothing. Extensions should overwrite if any special
disposal operation is required.repository - protected ComponentContext getComponentContext()
protected void activate(ComponentContext componentContext)
throws java.lang.Exception
nothing, - but allow derived classes to throw any Exceptionjava.lang.Exceptionprotected void deactivate(ComponentContext componentContext)
componentContext - protected void bindLog(LogService log)
protected void unbindLog(LogService log)
public void run()
run in interface java.lang.Runnable