]> git.argeo.org Git - gpl/argeo-suite.git/blob - org.argeo.suite.e4.rap/src/org/argeo/suite/e4/rap/settings/AppDeployer.java
Use tabbed area.
[gpl/argeo-suite.git] / org.argeo.suite.e4.rap / src / org / argeo / suite / e4 / rap / settings / AppDeployer.java
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.util.LangUtils;
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 /**
18 * Managed service factory deploying Argeo RAP app based on OSGi configurations.
19 */
20 public class AppDeployer implements ManagedServiceFactory {
21 private final static Log log = LogFactory.getLog(AppDeployer.class);
22 private BundleContext bundleContext;
23
24 public void init(BundleContext bundleContext, Map<String, String> properties) {
25 this.bundleContext = bundleContext;
26
27 deploy(findBundle("org.argeo.suite.studio", null), properties);
28 deploy(findBundle("org.argeo.suite.docs", null), properties);
29 }
30
31 public void destroy() {
32
33 }
34
35 @Override
36 public String getName() {
37 return "Argeo App Deployer";
38 }
39
40 @Override
41 public void updated(String pid, Dictionary<String, ?> properties) throws ConfigurationException {
42 Bundle bundle = findBundle(pid, properties);
43 deploy(bundle, LangUtils.dictToStringMap(properties));
44 }
45
46 protected void deploy(Bundle bundle, Map<String, String> properties) {
47 // CmsTheme cmsTheme;
48 // if (properties.containsKey(CmsTheme.CMS_THEME_BUNDLE_PROPERTY)) {
49 // String cmsThemeBundle = properties.get(CmsTheme.CMS_THEME_BUNDLE_PROPERTY);
50 // cmsTheme = new CmsTheme(bundleContext, cmsThemeBundle);
51 // } else {
52 // cmsTheme = new CmsTheme(bundleContext, CmsTheme.DEFAULT_CMS_THEME_BUNDLE);
53 // }
54
55 ArgeoRapApp app = new ArgeoRapApp(bundleContext, bundle, null);
56
57 Hashtable<String, String> props = new Hashtable<String, String>();
58 props.put(AbstractRapE4App.CONTEXT_NAME_PROPERTY, app.getContextName());
59 bundleContext.registerService(ApplicationConfiguration.class, app, props);
60
61 if (log.isDebugEnabled())
62 log.debug("Deployed Argeo App " + bundle.getSymbolicName() + " to " + app.getContextName());
63 }
64
65 @Override
66 public void deleted(String pid) {
67 }
68
69 protected Bundle findBundle(String pid, Dictionary<String, ?> properties) {
70 Bundle bundle = null;
71 for (Bundle b : bundleContext.getBundles()) {
72 if (b.getSymbolicName().equals(pid)) {
73 bundle = b;
74 break;
75 }
76 }
77 if (bundle == null)
78 throw new IllegalStateException("Bundle " + pid + " not found");
79 return bundle;
80 }
81 }