]> git.argeo.org Git - lgpl/argeo-commons.git/blob - commands/AddRemoteRepository.java
Prepare next development cycle
[lgpl/argeo-commons.git] / commands / AddRemoteRepository.java
1 package org.argeo.jcr.ui.explorer.commands;
2
3 import java.util.Hashtable;
4 import java.util.Map;
5
6 import javax.jcr.Repository;
7 import javax.jcr.RepositoryFactory;
8
9 import org.argeo.eclipse.ui.ErrorFeedback;
10 import org.argeo.eclipse.ui.dialogs.SingleValue;
11 import org.argeo.jcr.ArgeoJcrConstants;
12 import org.argeo.jcr.ui.explorer.JcrExplorerConstants;
13 import org.eclipse.core.commands.AbstractHandler;
14 import org.eclipse.core.commands.ExecutionEvent;
15 import org.eclipse.core.commands.ExecutionException;
16 import org.eclipse.jface.dialogs.TitleAreaDialog;
17 import org.eclipse.swt.widgets.Shell;
18 import org.osgi.framework.BundleContext;
19
20 /**
21 * Connect to a remote repository and, if usccessful publish it as an OSGi
22 * service.
23 */
24 public class AddRemoteRepository extends AbstractHandler implements
25 JcrExplorerConstants {
26
27 private RepositoryFactory repositoryFactory;
28 private BundleContext bundleContext;
29
30 public Object execute(ExecutionEvent event) throws ExecutionException {
31 String uri;
32 if (event.getParameters().containsKey(PARAM_REPOSITORY_URI))
33 uri = event.getParameter(PARAM_REPOSITORY_URI);
34 else
35 uri = SingleValue
36 .ask("URI",
37 "Remote repository URI"
38 + " (e.g. http://localhost:7070/org.argeo.jcr.webapp/remoting/node)");
39
40 if (uri == null)
41 return null;
42
43 try {
44 Hashtable<String, String> params = new Hashtable<String, String>();
45 params.put(ArgeoJcrConstants.JCR_REPOSITORY_URI, uri);
46 // by default we use the URI as alias
47 params.put(ArgeoJcrConstants.JCR_REPOSITORY_ALIAS, uri);
48 Repository repository = repositoryFactory.getRepository(params);
49 bundleContext.registerService(Repository.class.getName(),
50 repository, params);
51 } catch (Exception e) {
52 ErrorFeedback.show("Cannot add remote repository " + uri, e);
53 }
54 return null;
55 }
56
57 public void setRepositoryFactory(RepositoryFactory repositoryFactory) {
58 this.repositoryFactory = repositoryFactory;
59 }
60
61 public void setBundleContext(BundleContext bundleContext) {
62 this.bundleContext = bundleContext;
63 }
64
65 }