Improve launch config
[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 import javax.jcr.Session;
8
9 import org.argeo.connect.AppService;
10 import org.argeo.connect.SystemAppService;
11 import org.argeo.eclipse.ui.EclipseUiUtils;
12 import org.argeo.suite.SuiteConstants;
13 import org.argeo.suite.SuiteException;
14
15 public class DefaultSuiteAppService implements SystemAppService {
16
17 // Injected known AppWorkbenchServices: order is important, first found
18 // result will be returned by the various methods.
19 private List<AppService> knownAppServices;
20
21 @Override
22 public Node publishEntity(Node parent, String nodeType, Node srcNode, boolean removeSrcNode)
23 throws RepositoryException {
24 for (AppService appService : knownAppServices) {
25 if (appService.isKnownType(nodeType))
26 return appService.publishEntity(parent, nodeType, srcNode, removeSrcNode);
27 }
28 return null;
29 }
30
31 @Override
32 public String getAppBaseName() {
33 return SuiteConstants.SUITE_APP_BASE_NAME;
34 }
35
36 @Override
37 public String getBaseRelPath(String nodeType) {
38 for (AppService appService : knownAppServices) {
39 if (appService.isKnownType(nodeType))
40 return appService.getBaseRelPath(nodeType);
41 }
42 return null;
43 // return getAppBaseName();
44 }
45
46 @Override
47 public String getDefaultRelPath(Node entity) throws RepositoryException {
48 for (AppService appService : knownAppServices) {
49 if (appService.isKnownType(entity))
50 return appService.getDefaultRelPath(entity);
51 }
52 return null;
53 }
54
55 @Override
56 public String getMainNodeType(Node node) {
57 for (AppService appService : knownAppServices) {
58 String foundType = appService.getMainNodeType(node);
59 if (EclipseUiUtils.notEmpty(foundType))
60 return foundType;
61 }
62 return null;
63 }
64
65 @Override
66 public String getDefaultRelPath(Session session, String nodetype, String id) {
67 for (AppService appService : knownAppServices) {
68 if (appService.isKnownType(nodetype))
69 return appService.getDefaultRelPath(session, nodetype, id);
70 }
71 return null;
72 }
73
74 /** Insures the correct service is called on save */
75 @Override
76 public Node saveEntity(Node entity, boolean publish) {
77 for (AppService appService : knownAppServices) {
78 if (appService.isKnownType(entity))
79 return appService.saveEntity(entity, publish);
80 }
81 throw new SuiteException("Unknown NodeType for " + entity + ". Cannot save");
82 // return AppService.super.saveEntity(entity, publish);
83 }
84
85 @Override
86 public boolean isKnownType(Node entity) {
87 for (AppService appService : knownAppServices) {
88 if (appService.isKnownType(entity))
89 return true;
90 }
91 return false;
92 }
93
94 @Override
95 public boolean isKnownType(String nodeType) {
96 for (AppService appService : knownAppServices) {
97 if (appService.isKnownType(nodeType))
98 return true;
99 }
100 return false;
101 }
102
103 public void setKnownAppServices(List<AppService> knownAppServices) {
104 this.knownAppServices = knownAppServices;
105 }
106
107 }