1 package org
.argeo
.jackrabbit
;
3 import java
.util
.HashMap
;
5 import java
.util
.Properties
;
7 import javax
.jcr
.Repository
;
8 import javax
.jcr
.RepositoryException
;
9 import javax
.jcr
.RepositoryFactory
;
11 import org
.apache
.commons
.logging
.Log
;
12 import org
.apache
.commons
.logging
.LogFactory
;
13 import org
.apache
.jackrabbit
.commons
.JcrUtils
;
14 import org
.apache
.jackrabbit
.jcr2dav
.Jcr2davRepositoryFactory
;
15 import org
.argeo
.ArgeoException
;
16 import org
.argeo
.jcr
.ArgeoJcrConstants
;
17 import org
.argeo
.jcr
.DefaultRepositoryFactory
;
18 import org
.osgi
.framework
.BundleContext
;
20 /** Repository factory which can access remote Jackrabbit repositories */
21 public class JackrabbitRepositoryFactory
extends DefaultRepositoryFactory
22 implements RepositoryFactory
, ArgeoJcrConstants
{
23 private final static Log log
= LogFactory
24 .getLog(JackrabbitRepositoryFactory
.class);
26 private BundleContext bundleContext
;
28 @SuppressWarnings({ "rawtypes", "unchecked" })
29 public Repository
getRepository(Map parameters
) throws RepositoryException
{
30 Repository repository
= super.getRepository(parameters
);
31 if (repository
!= null)
35 if (parameters
.containsKey(JCR_REPOSITORY_URI
))
36 uri
= parameters
.get(JCR_REPOSITORY_URI
).toString();
37 else if (parameters
.containsKey(JcrUtils
.REPOSITORY_URI
))
38 uri
= parameters
.get(JcrUtils
.REPOSITORY_URI
).toString();
42 Map
<String
, String
> params
= new HashMap
<String
, String
>();
43 params
.put(JcrUtils
.REPOSITORY_URI
, uri
);
44 repository
= new Jcr2davRepositoryFactory().getRepository(params
);
45 if (repository
== null)
46 throw new ArgeoException("Remote Davex repository " + uri
48 log
.info("Initialized remote Jackrabbit repository from uri " + uri
);
50 if (parameters
.containsKey(JCR_REPOSITORY_ALIAS
)
51 && bundleContext
!= null) {
52 Properties properties
= new Properties();
53 properties
.putAll(parameters
);
54 bundleContext
.registerService(Repository
.class.getName(),
55 repository
, properties
);
56 log
.info("Registered under alias '"
57 + parameters
.get(JCR_REPOSITORY_ALIAS
)
58 + "' the remote JCR repository from uri " + uri
);
64 public void setBundleContext(BundleContext bundleContext
) {
65 this.bundleContext
= bundleContext
;