Adapt after AppService API modification
[gpl/argeo-suite.git] / org.argeo.suite.core / src / org / argeo / suite / core / DefaultSuiteAppService.java
1 package org.argeo.suite.core;
2
3 import java.util.List;
4
5 import javax.jcr.Node;
6 import javax.jcr.RepositoryException;
7
8 import org.argeo.connect.AppService;
9 import org.argeo.suite.SuiteConstants;
10
11 public class DefaultSuiteAppService implements AppService {
12
13 // Injected known AppWorkbenchServices: order is important, first found
14 // result will be returned by the various methods.
15 private List<AppService> knownAppServices;
16
17 @Override
18 public Node createEntity(Node parent, String nodeType, Node srcNode, boolean removeSrcNode)
19 throws RepositoryException {
20 for (AppService appService : knownAppServices) {
21 if (appService.isKnownType(nodeType))
22 return appService.createEntity(parent, nodeType, srcNode, removeSrcNode);
23 }
24 return null;
25 }
26
27 @Override
28 public String getAppBaseName() {
29 return SuiteConstants.SUITE_APP_BASE_NAME;
30 }
31
32 @Override
33 public String getBaseRelPath(String nodeType) {
34 for (AppService appService : knownAppServices) {
35 if (appService.isKnownType(nodeType))
36 return appService.getBaseRelPath(nodeType);
37 }
38 return null;
39 // return getAppBaseName();
40 }
41
42 @Override
43 public String getDefaultRelPath(Node entity) throws RepositoryException {
44 for (AppService appService : knownAppServices) {
45 if (appService.isKnownType(entity))
46 return appService.getDefaultRelPath(entity);
47 }
48 return null;
49 }
50
51 @Override
52 public String getDefaultRelPath(String nodetype, String id) {
53 for (AppService appService : knownAppServices) {
54 if (appService.isKnownType(nodetype))
55 return appService.getDefaultRelPath(nodetype, id);
56 }
57 return null;
58 }
59
60 /** Insures the correct service is called on save */
61 @Override
62 public Node saveEntity(Node entity, boolean publish) {
63 for (AppService appService : knownAppServices) {
64 if (appService.isKnownType(entity))
65 return appService.saveEntity(entity, publish);
66 }
67 return AppService.super.saveEntity(entity, publish);
68 }
69
70 @Override
71 public boolean isKnownType(Node entity) {
72 for (AppService appService : knownAppServices) {
73 if (appService.isKnownType(entity))
74 return true;
75 }
76 return false;
77 }
78
79 @Override
80 public boolean isKnownType(String nodeType) {
81 for (AppService appService : knownAppServices) {
82 if (appService.isKnownType(nodeType))
83 return true;
84 }
85 return false;
86 }
87
88 public void setKnownAppServices(List<AppService> knownAppServices) {
89 this.knownAppServices = knownAppServices;
90 }
91
92 }