]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms.ui/src/org/argeo/cms/ui/jcr/model/RepositoryElem.java
1 package org
.argeo
.cms
.ui
.jcr
.model
;
3 import javax
.jcr
.Repository
;
4 import javax
.jcr
.RepositoryException
;
5 import javax
.jcr
.Session
;
7 import org
.argeo
.eclipse
.ui
.EclipseUiException
;
8 import org
.argeo
.eclipse
.ui
.TreeParent
;
9 import org
.argeo
.jcr
.JcrUtils
;
12 * UI Tree component that wraps a JCR {@link Repository}. It also keeps a
13 * reference to its parent Tree Ui component; typically the unique
14 * {@link RepositoriesElem} object of the current view to enable bi-directionnal
15 * browsing in the tree.
18 public class RepositoryElem
extends TreeParent
{
20 protected Repository repository
;
21 private Session defaultSession
= null;
23 /** Create a new repository with distinct name and alias */
24 public RepositoryElem(String alias
, Repository repository
, TreeParent parent
) {
26 this.repository
= repository
;
33 defaultSession
= repositoryLogin("main");
34 String
[] wkpNames
= defaultSession
.getWorkspace().getAccessibleWorkspaceNames();
35 for (String wkpName
: wkpNames
) {
36 if (wkpName
.equals(defaultSession
.getWorkspace().getName()))
37 addChild(new WorkspaceElem(this, wkpName
, defaultSession
));
39 addChild(new WorkspaceElem(this, wkpName
));
41 } catch (RepositoryException e
) {
42 throw new EclipseUiException("Cannot connect to repository " + alias
, e
);
46 public synchronized void logout() {
47 for (Object child
: getChildren()) {
48 if (child
instanceof WorkspaceElem
)
49 ((WorkspaceElem
) child
).logout();
52 JcrUtils
.logoutQuietly(defaultSession
);
53 defaultSession
= null;
57 * Actual call to the {@link Repository#login(javax.jcr.Credentials, String)}
58 * method. To be overridden.
60 protected Session
repositoryLogin(String workspaceName
) throws RepositoryException
{
61 return repository
.login(workspaceName
);
64 public String
[] getAccessibleWorkspaceNames() {
66 return defaultSession
.getWorkspace().getAccessibleWorkspaceNames();
67 } catch (RepositoryException e
) {
68 throw new EclipseUiException("Cannot retrieve workspace names", e
);
72 public void createWorkspace(String workspaceName
) {
76 defaultSession
.getWorkspace().createWorkspace(workspaceName
);
77 } catch (RepositoryException e
) {
78 throw new EclipseUiException("Cannot create workspace", e
);
82 /** returns the {@link Repository} referenced by the current UI Node */
83 public Repository
getRepository() {
87 public String
getAlias() {
91 public Boolean
isConnected() {
92 if (defaultSession
!= null && defaultSession
.isLive())