1 /*
2 * Copyright (c) 2005-2007 Creative Sphere Limited.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 *
10 * Creative Sphere - initial API and implementation
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 * Service module loader. It loads "service.xml" file as
24 * spring's application context xml configuration file.
25 * TODO: explain donwloading and unpacking of archives
26 *
27 * @author Daniel Sendula
28 */
29 public abstract class AbstractServiceModuleLoader implements ModuleLoader /*, ApplicationContextAware */{
30
31 /** Set of extensions loader will work on */
32 protected Set<String> extensions;
33
34 /** Deployment manager */
35 protected DeploymentManager deploymentManager;
36
37 /**
38 * Empty constructor
39 */
40 public AbstractServiceModuleLoader() {
41 }
42
43 /**
44 * Sets deployment manager
45 * @param deploymentManager deployment manager
46 */
47 public void setDeploymentManager(DeploymentManager deploymentManager) {
48 this.deploymentManager = deploymentManager;
49 }
50
51 /**
52 * Returns deployment manager
53 * @return deployment manager
54 */
55 public DeploymentManager getDeploymentManager() {
56 return deploymentManager;
57 }
58
59 /**
60 * Returns <code>true</code> if module loader knows how to load (create) module from given URI.
61 * @param uri URI
62 * @return <code>true</code> if module loader knows how to load (create) module from given URI.
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 * Returns set of extensions this module will work with.
85 * @return set of extensions this module will work with
86 */
87 public Set<String> getExtensions() {
88 if (extensions == null) {
89 extensions = new HashSet<String>();
90 }
91 return extensions;
92 }
93
94 /**
95 * Sets set of extensions this module will work with.
96 * @param extensions set of extensions this module will work with
97 */
98 public void setExtensions(Set<String> extensions) {
99 this.extensions = extensions;
100 }
101
102
103 /**
104 * Adds this loader to "DeploymentManager" {@link DeploymentManager}.
105 */
106 public void start() {
107 deploymentManager.getModuleLoaders().add(this);
108 }
109
110 /**
111 * Removes this loader from "DeploymentManager" {@link DeploymentManager}.
112 */
113 public void stop() {
114 deploymentManager.getModuleLoaders().remove(this);
115 }
116 }