]> git.argeo.org Git - lgpl/argeo-commons.git/blob - model/RepositoryNode.java
Prepare next development cycle
[lgpl/argeo-commons.git] / model / RepositoryNode.java
1 package org.argeo.jcr.ui.explorer.model;
2
3 import javax.jcr.Repository;
4 import javax.jcr.RepositoryException;
5 import javax.jcr.Session;
6
7 import org.argeo.ArgeoException;
8 import org.argeo.eclipse.ui.TreeParent;
9
10 /**
11 * UI Tree component. Wraps a JCR {@link Repository}. It also keeps a reference
12 * to its parent Tree Ui component; typically the unique {@link Repositories}
13 * object of the current view to enable bi-directionnal browsing in the tree.
14 */
15
16 public class RepositoryNode extends TreeParent implements UiNode {
17 private String alias;
18 private final Repository repository;
19 private Session defaultSession = null;
20
21 /** Create a new repository with alias = name */
22 public RepositoryNode(String alias, Repository repository, TreeParent parent) {
23 this(alias, alias, repository, parent);
24 }
25
26 /** Create a new repository with distinct name & alias */
27 public RepositoryNode(String alias, String name, Repository repository,
28 TreeParent parent) {
29 super(name);
30 this.repository = repository;
31 setParent(parent);
32 this.alias = alias;
33 }
34
35 public void login() {
36 try {
37 // SimpleCredentials sc = new SimpleCredentials("root",
38 // "demo".toCharArray());
39 // defaultSession = repository.login(sc);
40 defaultSession = repositoryLogin(null);
41 String[] wkpNames = defaultSession.getWorkspace()
42 .getAccessibleWorkspaceNames();
43 for (String wkpName : wkpNames) {
44 if (wkpName.equals(defaultSession.getWorkspace().getName()))
45 addChild(new WorkspaceNode(this, wkpName, defaultSession));
46 else
47 addChild(new WorkspaceNode(this, wkpName));
48 }
49 } catch (RepositoryException e) {
50 throw new ArgeoException("Cannot connect to repository " + alias, e);
51 }
52 }
53
54 /** Actual call to the {@link Repository#login(javax.jcr.Credentials, String)} method. To be overridden.*/
55 protected Session repositoryLogin(String workspaceName)
56 throws RepositoryException {
57 return repository.login(workspaceName);
58 }
59
60 public Session getDefaultSession() {
61 return defaultSession;
62 }
63
64 /** returns the {@link Repository} referenced by the current UI Node */
65 public Repository getRepository() {
66 return repository;
67 }
68
69 public String getAlias() {
70 return alias;
71 }
72
73 }