1 package org.argeo.suite.e4.rap.settings;
2
3 import java.util.Dictionary;
4 import java.util.Hashtable;
5 import java.util.Map;
6
7 import org.apache.commons.logging.Log;
8 import org.apache.commons.logging.LogFactory;
9 import org.argeo.cms.e4.rap.AbstractRapE4App;
10 import org.argeo.cms.util.CmsTheme;
11 import org.eclipse.rap.rwt.application.ApplicationConfiguration;
12 import org.osgi.framework.Bundle;
13 import org.osgi.framework.BundleContext;
14 import org.osgi.service.cm.ConfigurationException;
15 import org.osgi.service.cm.ManagedServiceFactory;
16
17 public class AppDeployer implements ManagedServiceFactory {
18 private final static Log log = LogFactory.getLog(AppDeployer.class);
19 private BundleContext bundleContext;
20
21 public void init(BundleContext bundleContext, Map<String, String> properties) {
22 this.bundleContext = bundleContext;
23
24 deploy(findBundle("org.argeo.suite.studio", null));
25 deploy(findBundle("org.argeo.suite.docs", null));
26 }
27
28 public void destroy() {
29
30 }
31
32 @Override
33 public String getName() {
34 return "Argeo App Deployer";
35 }
36
37 @Override
38 public void updated(String pid, Dictionary<String, ?> properties) throws ConfigurationException {
39 Bundle bundle = findBundle(pid, properties);
40 deploy(bundle);
41 }
42
43 protected void deploy(Bundle bundle) {
44 CmsTheme cmsTheme = new CmsTheme(bundleContext, "org.argeo.theme.argeo2");
45
46 ArgeoRapApp app = new ArgeoRapApp(bundle, cmsTheme);
47
48 Hashtable<String, String> props = new Hashtable<String, String>();
49 props.put(AbstractRapE4App.CONTEXT_NAME_PROPERTY, app.getContextName());
50 bundleContext.registerService(ApplicationConfiguration.class, app, props);
51
52 if (log.isDebugEnabled())
53 log.debug("Deployed Argeo App " + bundle.getSymbolicName() + " to " + app.getContextName());
54 }
55
56 @Override
57 public void deleted(String pid) {
58 }
59
60 protected Bundle findBundle(String pid, Dictionary<String, ?> properties) {
61 Bundle bundle = null;
62 for (Bundle b : bundleContext.getBundles()) {
63 if (b.getSymbolicName().equals(pid)) {
64 bundle = b;
65 break;
66 }
67 }
68 if (bundle == null)
69 throw new IllegalStateException("Bundle " + pid + " not found");
70 return bundle;
71 }
72 }