1 package org
.argeo
.entity
.core
;
6 import javax
.jcr
.Repository
;
7 import javax
.jcr
.RepositoryException
;
8 import javax
.jcr
.Session
;
10 import org
.argeo
.api
.NodeUtils
;
11 import org
.argeo
.entity
.EntityConstants
;
12 import org
.argeo
.entity
.EntityDefinition
;
13 import org
.argeo
.entity
.EntityNames
;
14 import org
.argeo
.entity
.EntityTypes
;
15 import org
.argeo
.jcr
.Jcr
;
16 import org
.argeo
.jcr
.JcrUtils
;
17 import org
.osgi
.framework
.BundleContext
;
19 /** An entity definition based on a JCR data structure. */
20 public class JcrEntityDefinition
implements EntityDefinition
{
21 private Repository repository
;
24 private String defaultEditoryId
;
26 public void init(BundleContext bundleContext
, Map
<String
, String
> properties
) throws RepositoryException
{
27 Session adminSession
= NodeUtils
.openDataAdminSession(repository
, null);
29 type
= properties
.get(EntityConstants
.TYPE
);
31 throw new IllegalArgumentException("Entity type property " + EntityConstants
.TYPE
+ " must be set.");
32 defaultEditoryId
= properties
.get(EntityConstants
.DEFAULT_EDITORY_ID
);
33 String definitionPath
= EntityNames
.ENTITY_DEFINITIONS_PATH
+ '/' + type
;
34 if (!adminSession
.itemExists(definitionPath
)) {
35 Node entityDefinition
= JcrUtils
.mkdirs(adminSession
, definitionPath
, EntityTypes
.ENTITY_DEFINITION
);
36 // entityDefinition.addMixin(EntityTypes.ENTITY_DEFINITION);
39 initJcr(adminSession
);
41 Jcr
.logout(adminSession
);
45 /** To be overridden in order to perform additional initialisations. */
46 protected void initJcr(Session adminSession
) throws RepositoryException
{
50 public void destroy(BundleContext bundleContext
, Map
<String
, String
> properties
) throws RepositoryException
{
55 public String
getEditorId(Node entity
) {
56 return defaultEditoryId
;
60 public String
getType() {
64 protected Repository
getRepository() {
68 public void setRepository(Repository repository
) {
69 this.repository
= repository
;
72 public String
toString() {
73 return "Entity Definition " + getType();