]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/server/jackrabbit/JackrabbitContainer.java
1 package org
.argeo
.server
.jackrabbit
;
4 import java
.io
.InputStream
;
6 import javax
.jcr
.Credentials
;
7 import javax
.jcr
.LoginException
;
8 import javax
.jcr
.NoSuchWorkspaceException
;
9 import javax
.jcr
.Repository
;
10 import javax
.jcr
.RepositoryException
;
11 import javax
.jcr
.Session
;
13 import org
.apache
.commons
.io
.FileUtils
;
14 import org
.apache
.commons
.io
.IOUtils
;
15 import org
.apache
.commons
.logging
.Log
;
16 import org
.apache
.commons
.logging
.LogFactory
;
17 import org
.apache
.jackrabbit
.core
.RepositoryImpl
;
18 import org
.apache
.jackrabbit
.core
.TransientRepository
;
19 import org
.apache
.jackrabbit
.core
.config
.RepositoryConfig
;
20 import org
.springframework
.beans
.factory
.DisposableBean
;
21 import org
.springframework
.beans
.factory
.InitializingBean
;
22 import org
.springframework
.core
.io
.Resource
;
24 public class JackrabbitContainer
implements InitializingBean
, DisposableBean
,
26 private Log log
= LogFactory
.getLog(JackrabbitContainer
.class);
28 private Resource configuration
;
29 private File homeDirectory
;
31 private Boolean inMemory
= false;
33 private Repository repository
;
35 public void afterPropertiesSet() throws Exception
{
36 if (inMemory
&& homeDirectory
.exists()) {
37 FileUtils
.deleteDirectory(homeDirectory
);
38 log
.warn("Deleted Jackrabbit home directory " + homeDirectory
);
41 RepositoryConfig config
;
42 InputStream in
= configuration
.getInputStream();
44 config
= RepositoryConfig
.create(in
, homeDirectory
46 } catch (Exception e
) {
47 throw new RuntimeException("Cannot read configuration", e
);
49 IOUtils
.closeQuietly(in
);
53 repository
= new TransientRepository(config
);
55 repository
= RepositoryImpl
.create(config
);
57 log
.info("Initialized Jackrabbit repository " + repository
+ " in "
58 + homeDirectory
+ " with config " + configuration
);
61 public void destroy() throws Exception
{
62 if (repository
!= null) {
63 if (repository
instanceof RepositoryImpl
)
64 ((RepositoryImpl
) repository
).shutdown();
65 else if (repository
instanceof TransientRepository
)
66 ((TransientRepository
) repository
).shutdown();
70 if (homeDirectory
.exists()) {
71 FileUtils
.deleteDirectory(homeDirectory
);
72 if (log
.isDebugEnabled())
73 log
.debug("Deleted Jackrabbit home directory "
76 log
.info("Destroyed Jackrabbit repository " + repository
+ " in "
77 + homeDirectory
+ " with config " + configuration
);
80 // JCR REPOSITORY (delegated)
81 public String
getDescriptor(String key
) {
82 return repository
.getDescriptor(key
);
85 public String
[] getDescriptorKeys() {
86 return repository
.getDescriptorKeys();
89 public Session
login() throws LoginException
, RepositoryException
{
90 return repository
.login();
93 public Session
login(Credentials credentials
, String workspaceName
)
94 throws LoginException
, NoSuchWorkspaceException
,
96 return repository
.login(credentials
, workspaceName
);
99 public Session
login(Credentials credentials
) throws LoginException
,
100 RepositoryException
{
101 return repository
.login(credentials
);
104 public Session
login(String workspaceName
) throws LoginException
,
105 NoSuchWorkspaceException
, RepositoryException
{
106 return repository
.login(workspaceName
);
110 public void setHomeDirectory(File homeDirectory
) {
111 this.homeDirectory
= homeDirectory
;
114 public void setConfiguration(Resource configuration
) {
115 this.configuration
= configuration
;
118 public void setInMemory(Boolean inMemory
) {
119 this.inMemory
= inMemory
;