1
2
3
4
5
6
7
8
9
10
11
12
13 package org.abstracthorizon.extend.server.deployment.service;
14
15 import java.net.URI;
16 import java.util.HashSet;
17 import java.util.Set;
18
19 import org.abstracthorizon.extend.server.deployment.DeploymentManager;
20 import org.abstracthorizon.extend.server.deployment.ModuleLoader;
21
22
23
24
25
26
27
28
29 public abstract class AbstractServiceModuleLoader implements ModuleLoader
30
31
32 protected Set<String> extensions;
33
34
35 protected DeploymentManager deploymentManager;
36
37
38
39
40 public AbstractServiceModuleLoader() {
41 }
42
43
44
45
46
47 public void setDeploymentManager(DeploymentManager deploymentManager) {
48 this.deploymentManager = deploymentManager;
49 }
50
51
52
53
54
55 public DeploymentManager getDeploymentManager() {
56 return deploymentManager;
57 }
58
59
60
61
62
63
64 public boolean canLoad(URI uri) {
65 String file = uri.getPath();
66 if (file != null) {
67 if (file.endsWith("/")) {
68 if ("file".equals(uri.getScheme())) {
69 file = file.substring(0, file.length() - 1);
70 } else {
71 return false;
72 }
73 }
74 for (String extension : extensions) {
75 if (file.endsWith(extension)) {
76 return true;
77 }
78 }
79 }
80 return false;
81 }
82
83
84
85
86
87 public Set<String> getExtensions() {
88 if (extensions == null) {
89 extensions = new HashSet<String>();
90 }
91 return extensions;
92 }
93
94
95
96
97
98 public void setExtensions(Set<String> extensions) {
99 this.extensions = extensions;
100 }
101
102
103
104
105
106 public void start() {
107 deploymentManager.getModuleLoaders().add(this);
108 }
109
110
111
112
113 public void stop() {
114 deploymentManager.getModuleLoaders().remove(this);
115 }
116 }