]>
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
.api
.NodeConstants
;
8 import org
.argeo
.eclipse
.ui
.EclipseUiException
;
9 import org
.argeo
.eclipse
.ui
.TreeParent
;
10 import org
.argeo
.jcr
.JcrUtils
;
13 * UI Tree component that wraps a JCR {@link Repository}. It also keeps a
14 * reference to its parent Tree Ui component; typically the unique
15 * {@link RepositoriesElem} object of the current view to enable bi-directionnal
16 * browsing in the tree.
19 public class RepositoryElem
extends TreeParent
{
21 protected Repository repository
;
22 private Session defaultSession
= null;
24 /** Create a new repository with distinct name and alias */
25 public RepositoryElem(String alias
, Repository repository
, TreeParent parent
) {
27 this.repository
= repository
;
34 defaultSession
= repositoryLogin(NodeConstants
.SYS_WORKSPACE
);
35 String
[] wkpNames
= defaultSession
.getWorkspace().getAccessibleWorkspaceNames();
36 for (String wkpName
: wkpNames
) {
37 if (wkpName
.equals(defaultSession
.getWorkspace().getName()))
38 addChild(new WorkspaceElem(this, wkpName
, defaultSession
));
40 addChild(new WorkspaceElem(this, wkpName
));
42 } catch (RepositoryException e
) {
43 throw new EclipseUiException("Cannot connect to repository " + alias
, e
);
47 public synchronized void logout() {
48 for (Object child
: getChildren()) {
49 if (child
instanceof WorkspaceElem
)
50 ((WorkspaceElem
) child
).logout();
53 JcrUtils
.logoutQuietly(defaultSession
);
54 defaultSession
= null;
58 * Actual call to the {@link Repository#login(javax.jcr.Credentials, String)}
59 * method. To be overridden.
61 protected Session
repositoryLogin(String workspaceName
) throws RepositoryException
{
62 return repository
.login(workspaceName
);
65 public String
[] getAccessibleWorkspaceNames() {
67 return defaultSession
.getWorkspace().getAccessibleWorkspaceNames();
68 } catch (RepositoryException e
) {
69 throw new EclipseUiException("Cannot retrieve workspace names", e
);
73 public void createWorkspace(String workspaceName
) {
77 defaultSession
.getWorkspace().createWorkspace(workspaceName
);
78 } catch (RepositoryException e
) {
79 throw new EclipseUiException("Cannot create workspace", e
);
83 /** returns the {@link Repository} referenced by the current UI Node */
84 public Repository
getRepository() {
88 public String
getAlias() {
92 public Boolean
isConnected() {
93 if (defaultSession
!= null && defaultSession
.isLive())