1 package org
.argeo
.cms
.internal
.kernel
;
3 import java
.util
.Dictionary
;
4 import java
.util
.Hashtable
;
6 import java
.util
.Locale
;
8 import org
.apache
.jackrabbit
.core
.RepositoryContext
;
9 import org
.argeo
.ArgeoException
;
10 import org
.argeo
.jcr
.ArgeoJcrConstants
;
11 import org
.argeo
.node
.RepoConf
;
12 import org
.osgi
.framework
.BundleContext
;
13 import org
.osgi
.framework
.FrameworkUtil
;
14 import org
.osgi
.framework
.ServiceRegistration
;
15 import org
.osgi
.service
.cm
.ConfigurationException
;
16 import org
.osgi
.service
.cm
.ManagedService
;
17 import org
.osgi
.service
.metatype
.MetaTypeProvider
;
18 import org
.osgi
.service
.metatype
.ObjectClassDefinition
;
20 public class RepositoryService
implements ManagedService
, MetaTypeProvider
{
21 private BundleContext bc
= FrameworkUtil
.getBundle(getClass()).getBundleContext();
22 // private RepositoryContext repositoryContext = null;
23 private ServiceRegistration
<RepositoryContext
> repositoryContextReg
;
26 public void updated(Dictionary
<String
, ?
> properties
) throws ConfigurationException
{
27 if (properties
== null)
30 if (repositoryContextReg
!= null) {
34 // for (String key : LangUtils.keys(properties)) {
35 // Object value = properties.get(key);
36 // System.out.println(key + " : " + value.getClass().getName());
40 RepositoryBuilder repositoryBuilder
= new RepositoryBuilder();
41 RepositoryContext repositoryContext
= repositoryBuilder
.createRepositoryContext(properties
);
42 Dictionary
<String
, Object
> props
= new Hashtable
<>();
43 props
.put(ArgeoJcrConstants
.JCR_REPOSITORY_URI
, properties
.get(RepoConf
.labeledUri
.name()));
44 Object cn
= properties
.get(ArgeoJcrConstants
.JCR_REPOSITORY_ALIAS
);
46 props
.put(ArgeoJcrConstants
.JCR_REPOSITORY_ALIAS
, cn
);
48 repositoryContextReg
= bc
.registerService(RepositoryContext
.class, repositoryContext
, props
);
49 } catch (Exception e
) {
50 throw new ArgeoException("Cannot create Jackrabbit repository", e
);
55 public void shutdown() {
56 if (repositoryContextReg
== null)
58 RepositoryContext repositoryContext
= bc
.getService(repositoryContextReg
.getReference());
59 repositoryContext
.getRepository().shutdown();
60 repositoryContextReg
.unregister();
61 repositoryContextReg
= null;
68 public ObjectClassDefinition
getObjectClassDefinition(String id
, String locale
) {
69 return new RepoConf
.OCD(locale
);
70 // return new EnumOCD<>(RepoConf.class);
71 // return new JcrRepositoryOCD(locale);
75 public String
[] getLocales() {
77 List
<Locale
> locales
= Activator
.getNodeState().getLocales();
78 String
[] res
= new String
[locales
.size()];
79 for (int i
= 0; i
< locales
.size(); i
++)
80 res
[i
] = locales
.get(i
).toString();
85 * JACKRABBIT REPOSITORY
88 // private RepositoryImpl repo() {
89 // return repositoryContext.getRepository();
93 // public String[] getDescriptorKeys() {
94 // return repo().getDescriptorKeys();
98 // public boolean isStandardDescriptor(String key) {
99 // return repo().isStandardDescriptor(key);
103 // public boolean isSingleValueDescriptor(String key) {
104 // return repo().isSingleValueDescriptor(key);
108 // public Value getDescriptorValue(String key) {
109 // return repo().getDescriptorValue(key);
113 // public Value[] getDescriptorValues(String key) {
114 // return repo().getDescriptorValues(key);
118 // public String getDescriptor(String key) {
119 // return repo().getDescriptor(key);
123 // public Session login(Credentials credentials, String workspaceName)
124 // throws LoginException, NoSuchWorkspaceException, RepositoryException {
125 // return repo().login();
129 // public Session login(Credentials credentials) throws LoginException,
130 // RepositoryException {
131 // return repo().login(credentials);
135 // public Session login(String workspaceName) throws LoginException,
136 // NoSuchWorkspaceException, RepositoryException {
137 // return repo().login(workspaceName);
141 // public Session login() throws LoginException, RepositoryException {
142 // return repo().login();
146 // public Session login(Credentials credentials, String workspaceName,
147 // Map<String, Object> attributes)
148 // throws LoginException, NoSuchWorkspaceException, RepositoryException {
149 // return repo().login(credentials, workspaceName, attributes);