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