]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/model/RepositoryNode.java
1 package org
.argeo
.jcr
.ui
.explorer
.model
;
3 import javax
.jcr
.Repository
;
4 import javax
.jcr
.RepositoryException
;
5 import javax
.jcr
.Session
;
7 import org
.argeo
.ArgeoException
;
8 import org
.argeo
.eclipse
.ui
.TreeParent
;
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.
16 public class RepositoryNode
extends TreeParent
implements UiNode
{
18 private final Repository repository
;
19 private Session defaultSession
= null;
21 /** Create a new repository with alias = name */
22 public RepositoryNode(String alias
, Repository repository
, TreeParent parent
) {
23 this(alias
, alias
, repository
, parent
);
26 /** Create a new repository with distinct name & alias */
27 public RepositoryNode(String alias
, String name
, Repository repository
,
30 this.repository
= repository
;
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
));
47 addChild(new WorkspaceNode(this, wkpName
));
49 } catch (RepositoryException e
) {
50 throw new ArgeoException("Cannot connect to repository " + alias
, e
);
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
);
60 public Session
getDefaultSession() {
61 return defaultSession
;
64 /** returns the {@link Repository} referenced by the current UI Node */
65 public Repository
getRepository() {
69 public String
getAlias() {