]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms.ui/src/org/argeo/cms/ui/jcr/model/RepositoryElem.java
6f2288c4c294efdfa2ec07590b44fb335da7fe54
2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.cms
.ui
.jcr
.model
;
18 import javax
.jcr
.Repository
;
19 import javax
.jcr
.RepositoryException
;
20 import javax
.jcr
.Session
;
22 import org
.argeo
.eclipse
.ui
.EclipseUiException
;
23 import org
.argeo
.eclipse
.ui
.TreeParent
;
24 import org
.argeo
.jcr
.JcrUtils
;
27 * UI Tree component that wraps a JCR {@link Repository}. It also keeps a
28 * reference to its parent Tree Ui component; typically the unique
29 * {@link RepositoriesElem} object of the current view to enable bi-directionnal
30 * browsing in the tree.
33 public class RepositoryElem
extends TreeParent
{
35 protected Repository repository
;
36 private Session defaultSession
= null;
38 /** Create a new repository with distinct name and alias */
39 public RepositoryElem(String alias
, Repository repository
, TreeParent parent
) {
41 this.repository
= repository
;
48 defaultSession
= repositoryLogin("main");
49 String
[] wkpNames
= defaultSession
.getWorkspace().getAccessibleWorkspaceNames();
50 for (String wkpName
: wkpNames
) {
51 if (wkpName
.equals(defaultSession
.getWorkspace().getName()))
52 addChild(new WorkspaceElem(this, wkpName
, defaultSession
));
54 addChild(new WorkspaceElem(this, wkpName
));
56 } catch (RepositoryException e
) {
57 throw new EclipseUiException("Cannot connect to repository " + alias
, e
);
61 public synchronized void logout() {
62 for (Object child
: getChildren()) {
63 if (child
instanceof WorkspaceElem
)
64 ((WorkspaceElem
) child
).logout();
67 JcrUtils
.logoutQuietly(defaultSession
);
68 defaultSession
= null;
72 * Actual call to the {@link Repository#login(javax.jcr.Credentials, String)}
73 * method. To be overridden.
75 protected Session
repositoryLogin(String workspaceName
) throws RepositoryException
{
76 return repository
.login(workspaceName
);
79 public String
[] getAccessibleWorkspaceNames() {
81 return defaultSession
.getWorkspace().getAccessibleWorkspaceNames();
82 } catch (RepositoryException e
) {
83 throw new EclipseUiException("Cannot retrieve workspace names", e
);
87 public void createWorkspace(String workspaceName
) {
91 defaultSession
.getWorkspace().createWorkspace(workspaceName
);
92 } catch (RepositoryException e
) {
93 throw new EclipseUiException("Cannot create workspace", e
);
97 /** returns the {@link Repository} referenced by the current UI Node */
98 public Repository
getRepository() {
102 public String
getAlias() {
106 public Boolean
isConnected() {
107 if (defaultSession
!= null && defaultSession
.isLive())