import org.argeo.ArgeoException;
import org.argeo.jcr.ArgeoJcrConstants;
import org.argeo.jcr.DefaultRepositoryFactory;
-import org.osgi.framework.BundleContext;
-/** Repository factory which can access remote Jackrabbit repositories */
+/**
+ * Repository factory which can create new repositories and access remote
+ * Jackrabbit repositories
+ */
public class JackrabbitRepositoryFactory extends DefaultRepositoryFactory
implements RepositoryFactory, ArgeoJcrConstants {
private final static Log log = LogFactory
.getLog(JackrabbitRepositoryFactory.class);
- private BundleContext bundleContext;
-
@SuppressWarnings({ "rawtypes", "unchecked" })
public Repository getRepository(Map parameters) throws RepositoryException {
+ // check if can be found by alias
Repository repository = super.getRepository(parameters);
if (repository != null)
return repository;
- String uri;
+ // check if remote
+ String uri = null;
if (parameters.containsKey(JCR_REPOSITORY_URI))
uri = parameters.get(JCR_REPOSITORY_URI).toString();
else if (parameters.containsKey(JcrUtils.REPOSITORY_URI))
uri = parameters.get(JcrUtils.REPOSITORY_URI).toString();
- else
- return null;
+ if (uri == null)
+ repository = createRemoteRepository(uri);
+
+ if (parameters.containsKey(JCR_REPOSITORY_ALIAS)) {
+ Properties properties = new Properties();
+ properties.putAll(parameters);
+ String alias = parameters.get(JCR_REPOSITORY_ALIAS).toString();
+ publish(alias, repository, properties);
+ log.info("Registered JCR repository under alias '" + alias
+ + "' with properties " + properties);
+ }
+
+ return repository;
+ }
+
+ protected Repository createRemoteRepository(String uri)
+ throws RepositoryException {
Map<String, String> params = new HashMap<String, String>();
params.put(JcrUtils.REPOSITORY_URI, uri);
- repository = new Jcr2davRepositoryFactory().getRepository(params);
+ Repository repository = new Jcr2davRepositoryFactory()
+ .getRepository(params);
if (repository == null)
throw new ArgeoException("Remote Davex repository " + uri
+ " not found");
log.info("Initialized remote Jackrabbit repository from uri " + uri);
-
- if (parameters.containsKey(JCR_REPOSITORY_ALIAS)
- && bundleContext != null) {
- Properties properties = new Properties();
- properties.putAll(parameters);
- bundleContext.registerService(Repository.class.getName(),
- repository, properties);
- log.info("Registered under alias '"
- + parameters.get(JCR_REPOSITORY_ALIAS)
- + "' the remote JCR repository from uri " + uri);
- }
-
return repository;
}
- public void setBundleContext(BundleContext bundleContext) {
- this.bundleContext = bundleContext;
+ /**
+ * Called after the repository has been initialized. Does nothing by
+ * default.
+ */
+ @SuppressWarnings("rawtypes")
+ protected void postInitialization(Repository repository, Map parameters) {
+
}
}
--- /dev/null
+package org.argeo.jackrabbit;
+
+import java.util.Properties;
+
+import javax.jcr.Repository;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.osgi.framework.BundleContext;
+
+/**
+ * OSGi-aware Jackrabbit repository factory which can retrieve/publish
+ * {@link Repository} as OSGi services.
+ */
+public class OsgiJackrabbitRepositoryFactory extends
+ JackrabbitRepositoryFactory {
+ private final static Log log = LogFactory
+ .getLog(OsgiJackrabbitRepositoryFactory.class);
+ private BundleContext bundleContext;
+
+ protected void publish(String alias, Repository repository,
+ Properties properties) {
+ if (bundleContext != null) {
+ // do not modify reference
+ Properties props = new Properties(properties);
+ props.setProperty(JCR_REPOSITORY_ALIAS, alias);
+ bundleContext.registerService(Repository.class.getName(),
+ repository, props);
+ }
+ }
+
+ public void setBundleContext(BundleContext bundleContext) {
+ this.bundleContext = bundleContext;
+ }
+
+}
<?xml version="1.0"?>
<!DOCTYPE Repository PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 1.6//EN"
"http://jackrabbit.apache.org/dtd/repository-2.0.dtd">
+<!-- LEGACY, will be replaced by repository-memory.xml -->
<Repository>
<!-- Shared datasource -->
<DataSources>
--- /dev/null
+<?xml version="1.0"?>
+<!DOCTYPE Repository PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 1.6//EN"
+ "http://jackrabbit.apache.org/dtd/repository-2.0.dtd">
+<Repository>
+ <!-- File system and datastore -->
+ <FileSystem class="org.apache.jackrabbit.core.fs.mem.MemoryFileSystem" />
+
+ <!-- Workspace templates -->
+ <Workspaces rootPath="${rep.home}/workspaces"
+ defaultWorkspace="${argeo.node.repo.defaultWorkspace}" configRootPath="/workspaces" />
+ <Workspace name="${wsp.name}">
+ <FileSystem class="org.apache.jackrabbit.core.fs.mem.MemoryFileSystem" />
+ <PersistenceManager
+ class="org.apache.jackrabbit.core.persistence.bundle.BundleFsPersistenceManager">
+ <param name="blobFSBlockSize" value="1" />
+ </PersistenceManager>
+ <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
+ <param name="path" value="${rep.home}/repository/index" />
+ <param name="directoryManagerClass"
+ value="org.apache.jackrabbit.core.query.lucene.directory.RAMDirectoryManager" />
+ <FileSystem class="org.apache.jackrabbit.core.fs.mem.MemoryFileSystem" />
+ </SearchIndex>
+ </Workspace>
+
+ <!-- Versioning -->
+ <Versioning rootPath="${rep.home}/version">
+ <FileSystem class="org.apache.jackrabbit.core.fs.mem.MemoryFileSystem" />
+ <PersistenceManager
+ class="org.apache.jackrabbit.core.persistence.bundle.BundleFsPersistenceManager">
+ <param name="blobFSBlockSize" value="1" />
+ </PersistenceManager>
+ </Versioning>
+
+ <!-- Indexing -->
+ <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
+ <param name="path" value="${rep.home}/repository/index" />
+ <param name="directoryManagerClass"
+ value="org.apache.jackrabbit.core.query.lucene.directory.RAMDirectoryManager" />
+ <FileSystem class="org.apache.jackrabbit.core.fs.mem.MemoryFileSystem" />
+ </SearchIndex>
+
+ <!-- Security -->
+ <Security appName="Jackrabbit">
+ <SecurityManager class="org.argeo.security.jackrabbit.ArgeoSecurityManager"
+ workspaceName="security">
+ </SecurityManager>
+ <AccessManager class="org.argeo.security.jackrabbit.ArgeoAccessManager">
+ </AccessManager>
+ <LoginModule class="org.argeo.security.jackrabbit.ArgeoLoginModule">
+ </LoginModule>
+ </Security>
+</Repository>
\ No newline at end of file