]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/server/jackrabbit/JackrabbitContainer.java
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org
.argeo
.server
.jackrabbit
;
20 import java
.io
.InputStream
;
22 import javax
.jcr
.Credentials
;
23 import javax
.jcr
.LoginException
;
24 import javax
.jcr
.NoSuchWorkspaceException
;
25 import javax
.jcr
.Repository
;
26 import javax
.jcr
.RepositoryException
;
27 import javax
.jcr
.Session
;
29 import org
.apache
.commons
.io
.FileUtils
;
30 import org
.apache
.commons
.io
.IOUtils
;
31 import org
.apache
.commons
.logging
.Log
;
32 import org
.apache
.commons
.logging
.LogFactory
;
33 import org
.apache
.jackrabbit
.core
.RepositoryImpl
;
34 import org
.apache
.jackrabbit
.core
.TransientRepository
;
35 import org
.apache
.jackrabbit
.core
.config
.RepositoryConfig
;
36 import org
.springframework
.beans
.factory
.DisposableBean
;
37 import org
.springframework
.beans
.factory
.InitializingBean
;
38 import org
.springframework
.core
.io
.Resource
;
40 public class JackrabbitContainer
implements InitializingBean
, DisposableBean
,
42 private Log log
= LogFactory
.getLog(JackrabbitContainer
.class);
44 private Resource configuration
;
45 private File homeDirectory
;
47 private Boolean inMemory
= false;
49 private Repository repository
;
51 public void afterPropertiesSet() throws Exception
{
52 if (inMemory
&& homeDirectory
.exists()) {
53 FileUtils
.deleteDirectory(homeDirectory
);
54 log
.warn("Deleted Jackrabbit home directory " + homeDirectory
);
57 RepositoryConfig config
;
58 InputStream in
= configuration
.getInputStream();
60 config
= RepositoryConfig
.create(in
, homeDirectory
62 } catch (Exception e
) {
63 throw new RuntimeException("Cannot read configuration", e
);
65 IOUtils
.closeQuietly(in
);
69 repository
= new TransientRepository(config
);
71 repository
= RepositoryImpl
.create(config
);
73 log
.info("Initialized Jackrabbit repository " + repository
+ " in "
74 + homeDirectory
+ " with config " + configuration
);
77 public void destroy() throws Exception
{
78 if (repository
!= null) {
79 if (repository
instanceof RepositoryImpl
)
80 ((RepositoryImpl
) repository
).shutdown();
81 else if (repository
instanceof TransientRepository
)
82 ((TransientRepository
) repository
).shutdown();
86 if (homeDirectory
.exists()) {
87 FileUtils
.deleteDirectory(homeDirectory
);
88 if (log
.isDebugEnabled())
89 log
.debug("Deleted Jackrabbit home directory "
92 log
.info("Destroyed Jackrabbit repository " + repository
+ " in "
93 + homeDirectory
+ " with config " + configuration
);
96 // JCR REPOSITORY (delegated)
97 public String
getDescriptor(String key
) {
98 return repository
.getDescriptor(key
);
101 public String
[] getDescriptorKeys() {
102 return repository
.getDescriptorKeys();
105 public Session
login() throws LoginException
, RepositoryException
{
106 return repository
.login();
109 public Session
login(Credentials credentials
, String workspaceName
)
110 throws LoginException
, NoSuchWorkspaceException
,
111 RepositoryException
{
112 return repository
.login(credentials
, workspaceName
);
115 public Session
login(Credentials credentials
) throws LoginException
,
116 RepositoryException
{
117 return repository
.login(credentials
);
120 public Session
login(String workspaceName
) throws LoginException
,
121 NoSuchWorkspaceException
, RepositoryException
{
122 return repository
.login(workspaceName
);
126 public void setHomeDirectory(File homeDirectory
) {
127 this.homeDirectory
= homeDirectory
;
130 public void setConfiguration(Resource configuration
) {
131 this.configuration
= configuration
;
134 public void setInMemory(Boolean inMemory
) {
135 this.inMemory
= inMemory
;