]> git.argeo.org Git - gpl/argeo-suite.git/blob - core/org.argeo.entity.core/src/org/argeo/entity/core/JcrEntityDefinition.java
Introduce full DocBook CND.
[gpl/argeo-suite.git] / core / org.argeo.entity.core / src / org / argeo / entity / core / JcrEntityDefinition.java
1 package org.argeo.entity.core;
2
3 import java.util.Map;
4
5 import javax.jcr.Node;
6 import javax.jcr.Repository;
7 import javax.jcr.RepositoryException;
8 import javax.jcr.Session;
9
10 import org.argeo.api.NodeUtils;
11 import org.argeo.entity.EntityConstants;
12 import org.argeo.entity.EntityDefinition;
13 import org.argeo.jcr.Jcr;
14 import org.osgi.framework.BundleContext;
15
16 /** An entity definition based on a JCR data structure. */
17 public class JcrEntityDefinition implements EntityDefinition {
18 private Repository repository;
19
20 private String type;
21 private String defaultEditoryId;
22
23 public void init(BundleContext bundleContext, Map<String, String> properties) throws RepositoryException {
24 Session adminSession = NodeUtils.openDataAdminSession(repository, null);
25 try {
26 type = properties.get(EntityConstants.TYPE);
27 if (type == null)
28 throw new IllegalArgumentException("Entity type property " + EntityConstants.TYPE + " must be set.");
29 defaultEditoryId = properties.get(EntityConstants.DEFAULT_EDITORY_ID);
30 // String definitionPath = EntityNames.ENTITY_DEFINITIONS_PATH + '/' + type;
31 // if (!adminSession.itemExists(definitionPath)) {
32 // Node entityDefinition = JcrUtils.mkdirs(adminSession, definitionPath, EntityTypes.ENTITY_DEFINITION);
33 //// entityDefinition.addMixin(EntityTypes.ENTITY_DEFINITION);
34 // adminSession.save();
35 // }
36 initJcr(adminSession);
37 } finally {
38 Jcr.logout(adminSession);
39 }
40 }
41
42 /** To be overridden in order to perform additional initialisations. */
43 protected void initJcr(Session adminSession) throws RepositoryException {
44
45 }
46
47 public void destroy(BundleContext bundleContext, Map<String, String> properties) throws RepositoryException {
48
49 }
50
51 @Override
52 public String getEditorId(Node entity) {
53 return defaultEditoryId;
54 }
55
56 @Override
57 public String getType() {
58 return type;
59 }
60
61 protected Repository getRepository() {
62 return repository;
63 }
64
65 public void setRepository(Repository repository) {
66 this.repository = repository;
67 }
68
69 public String toString() {
70 return "Entity Definition " + getType();
71 }
72
73 }