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
.eclipse
.ui
.workbench
.jcr
.internal
.model
;
20 import javax
.jcr
.Node
;
21 import javax
.jcr
.NodeIterator
;
22 import javax
.jcr
.Repository
;
23 import javax
.jcr
.RepositoryException
;
24 import javax
.jcr
.RepositoryFactory
;
25 import javax
.jcr
.Session
;
27 import org
.argeo
.ArgeoException
;
28 import org
.argeo
.eclipse
.ui
.TreeParent
;
29 import org
.argeo
.eclipse
.ui
.workbench
.ErrorFeedback
;
30 import org
.argeo
.jcr
.ArgeoNames
;
31 import org
.argeo
.jcr
.MaintainedRepository
;
32 import org
.argeo
.jcr
.RepositoryRegister
;
33 import org
.argeo
.jcr
.UserJcrUtils
;
34 import org
.argeo
.util
.security
.Keyring
;
37 * UI Tree component. Implements the Argeo abstraction of a
38 * {@link RepositoryFactory} that enable a user to "mount" various repositories
39 * in a single Tree like View. It is usually meant to be at the root of the UI
40 * Tree and thus {@link getParent()} method will return null.
42 * The {@link RepositoryFactory} is injected at instantiation time and must be
43 * use get or register new {@link Repository} objects upon which a reference is
47 public class RepositoriesElem
extends TreeParent
implements ArgeoNames
{
48 private final RepositoryRegister repositoryRegister
;
49 private final RepositoryFactory repositoryFactory
;
52 * A session of the logged in user on the default workspace of the node
55 private final Session userSession
;
56 private final Keyring keyring
;
58 public RepositoriesElem(String name
, RepositoryRegister repositoryRegister
,
59 RepositoryFactory repositoryFactory
, TreeParent parent
,
60 Session userSession
, Keyring keyring
) {
62 this.repositoryRegister
= repositoryRegister
;
63 this.repositoryFactory
= repositoryFactory
;
64 this.userSession
= userSession
;
65 this.keyring
= keyring
;
69 * Override normal behavior to initialize the various repositories only at
73 public synchronized Object
[] getChildren() {
75 return super.getChildren();
77 // initialize current object
78 Map
<String
, Repository
> refRepos
= repositoryRegister
80 for (String name
: refRepos
.keySet()) {
81 Repository repository
= refRepos
.get(name
);
82 if (repository
instanceof MaintainedRepository
)
83 super.addChild(new MaintainedRepositoryElem(name
,
86 super.addChild(new RepositoryElem(name
, repository
, this));
90 if (keyring
!= null) {
92 addRemoteRepositories(keyring
);
93 } catch (RepositoryException e
) {
94 throw new ArgeoException(
95 "Cannot browse remote repositories", e
);
98 return super.getChildren();
102 protected void addRemoteRepositories(Keyring jcrKeyring
)
103 throws RepositoryException
{
104 Node userHome
= UserJcrUtils
.getUserHome(userSession
);
105 if (userHome
!= null && userHome
.hasNode(ARGEO_REMOTE
)) {
106 NodeIterator it
= userHome
.getNode(ARGEO_REMOTE
).getNodes();
107 while (it
.hasNext()) {
108 Node remoteNode
= it
.nextNode();
109 String uri
= remoteNode
.getProperty(ARGEO_URI
).getString();
111 RemoteRepositoryElem remoteRepositoryNode
= new RemoteRepositoryElem(
112 remoteNode
.getName(), repositoryFactory
, uri
, this,
113 userSession
, jcrKeyring
, remoteNode
.getPath());
114 super.addChild(remoteRepositoryNode
);
115 } catch (Exception e
) {
116 ErrorFeedback
.show("Cannot add remote repository "
123 public void registerNewRepository(String alias
, Repository repository
) {
124 // TODO: implement this
125 // Create a new RepositoryNode Object
127 // super.addChild(new RepositoriesNode(...));
130 /** Returns the {@link RepositoryRegister} wrapped by this object. */
131 public RepositoryRegister
getRepositoryRegister() {
132 return repositoryRegister
;