1 package org
.argeo
.app
.core
;
6 import javax
.jcr
.Repository
;
7 import javax
.jcr
.RepositoryException
;
8 import javax
.jcr
.Session
;
10 import org
.argeo
.app
.api
.EntityConstants
;
11 import org
.argeo
.app
.api
.EntityDefinition
;
12 import org
.argeo
.cms
.jcr
.CmsJcrUtils
;
13 import org
.argeo
.jcr
.Jcr
;
14 import org
.osgi
.framework
.BundleContext
;
16 /** An entity definition based on a JCR data structure. */
17 public class JcrEntityDefinition
implements EntityDefinition
{
18 private Repository repository
;
21 private String defaultEditorId
;
23 public void init(BundleContext bundleContext
, Map
<String
, String
> properties
) throws RepositoryException
{
24 Session adminSession
= CmsJcrUtils
.openDataAdminSession(repository
, null);
26 type
= properties
.get(EntityConstants
.TYPE
);
28 throw new IllegalArgumentException("Entity type property " + EntityConstants
.TYPE
+ " must be set.");
29 defaultEditorId
= properties
.get(EntityConstants
.DEFAULT_EDITOR_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();
36 initJcr(adminSession
);
38 Jcr
.logout(adminSession
);
42 /** To be overridden in order to perform additional initialisations. */
43 protected void initJcr(Session adminSession
) throws RepositoryException
{
47 public void destroy(BundleContext bundleContext
, Map
<String
, String
> properties
) throws RepositoryException
{
52 public String
getEditorId(Node entity
) {
53 return defaultEditorId
;
57 public String
getType() {
61 protected Repository
getRepository() {
65 public void setRepository(Repository repository
) {
66 this.repository
= repository
;
69 public String
toString() {
70 return "Entity Definition " + getType();