]>
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
.jackrabbit
.core
.RepositoryImpl
;
16 import org
.apache
.jackrabbit
.core
.TransientRepository
;
17 import org
.apache
.jackrabbit
.core
.config
.RepositoryConfig
;
18 import org
.springframework
.beans
.factory
.DisposableBean
;
19 import org
.springframework
.beans
.factory
.InitializingBean
;
20 import org
.springframework
.core
.io
.Resource
;
22 public class JackrabbitContainer
implements InitializingBean
, DisposableBean
,
24 private Resource configuration
;
25 private File homeDirectory
;
27 private Boolean inMemory
= false;
29 private Repository repository
;
31 public void afterPropertiesSet() throws Exception
{
32 RepositoryConfig config
;
33 InputStream in
= configuration
.getInputStream();
35 config
= RepositoryConfig
.create(in
, homeDirectory
37 } catch (Exception e
) {
38 throw new RuntimeException("Cannot read configuration", e
);
40 IOUtils
.closeQuietly(in
);
44 repository
= new TransientRepository(config
);
46 repository
= RepositoryImpl
.create(config
);
49 public void destroy() throws Exception
{
50 if (repository
!= null) {
51 if (repository
instanceof RepositoryImpl
)
52 ((RepositoryImpl
) repository
).shutdown();
56 if (homeDirectory
.exists())
57 FileUtils
.deleteDirectory(homeDirectory
);
60 // JCR REPOSITORY (delegated)
61 public String
getDescriptor(String key
) {
62 return repository
.getDescriptor(key
);
65 public String
[] getDescriptorKeys() {
66 return repository
.getDescriptorKeys();
69 public Session
login() throws LoginException
, RepositoryException
{
70 return repository
.login();
73 public Session
login(Credentials credentials
, String workspaceName
)
74 throws LoginException
, NoSuchWorkspaceException
,
76 return repository
.login(credentials
, workspaceName
);
79 public Session
login(Credentials credentials
) throws LoginException
,
81 return repository
.login(credentials
);
84 public Session
login(String workspaceName
) throws LoginException
,
85 NoSuchWorkspaceException
, RepositoryException
{
86 return repository
.login(workspaceName
);
90 public void setHomeDirectory(File homeDirectory
) {
91 this.homeDirectory
= homeDirectory
;
94 public void setConfiguration(Resource configuration
) {
95 this.configuration
= configuration
;