View Javadoc
1   package org.argeo.cms.ui.script;
2   
3   import javax.jcr.Repository;
4   
5   import org.apache.commons.logging.Log;
6   import org.apache.commons.logging.LogFactory;
7   import org.osgi.framework.BundleActivator;
8   import org.osgi.framework.BundleContext;
9   import org.osgi.framework.FrameworkUtil;
10  import org.osgi.framework.ServiceReference;
11  import org.osgi.util.tracker.ServiceTracker;
12  
13  public class ScriptAppActivator implements BundleActivator {
14  	private final static Log log = LogFactory.getLog(ScriptAppActivator.class);
15  
16  	@Override
17  	public void start(BundleContext context) throws Exception {
18  		try {
19  			CmsScriptRwtApplication appConfig = new CmsScriptRwtApplication();
20  			appConfig.init(context);
21  			CmsScriptApp app = appConfig.getApp();
22  			ServiceTracker<Repository, Repository> repoSt = new ServiceTracker<Repository, Repository>(context,
23  					FrameworkUtil.createFilter("(&" + app.getRepo() + "(objectClass=javax.jcr.Repository))"), null) {
24  
25  				@Override
26  				public Repository addingService(ServiceReference<Repository> reference) {
27  					Repository repository = super.addingService(reference);
28  					appConfig.setRepository(repository);
29  					CmsScriptApp app = appConfig.getApp();
30  					app.register(context, appConfig);
31  					return repository;
32  				}
33  
34  			};
35  			repoSt.open();
36  		} catch (Exception e) {
37  			log.error("Cannot initialise script bundle " + context.getBundle().getSymbolicName(), e);
38  			throw e;
39  		}
40  	}
41  
42  	@Override
43  	public void stop(BundleContext context) throws Exception {
44  	}
45  
46  }