- /** A software repository */
- private class RepoElem {
- private Node repoNode;
-
- private Repository repository;
- private Credentials credentials;
-
- public RepoElem(Node repoNode) {
- this.repoNode = repoNode;
- }
-
- /** Lazily connects to repository */
- protected void connect() {
- if (repository != null)
- return;
- repository = RepoUtils.getRepository(repositoryFactory, keyring,
- repoNode);
- credentials = RepoUtils.getRepositoryCredentials(keyring, repoNode);
- }
-
- public String getLabel() {
- try {
- if (repoNode.isNodeType(NodeType.MIX_TITLE)) {
- return repoNode.getProperty(Property.JCR_TITLE).getString();
- } else {
- return repoNode.getName();
- }
- } catch (RepositoryException e) {
- throw new SlcException("Cannot read label of " + repoNode, e);
- }
- }
-
- public String toString() {
- return repoNode.toString();
- }
-
- public Object[] getChildren() {
- connect();
- Session session = null;
- try {
- session = repository.login(credentials);
- String[] workspaceNames = session.getWorkspace()
- .getAccessibleWorkspaceNames();
- List<DistributionElem> distributionElems = new ArrayList<DistributionElem>();
- for (String workspaceName : workspaceNames) {
- Node workspaceNode = repoNode.hasNode(workspaceName) ? repoNode
- .getNode(workspaceName) : repoNode
- .addNode(workspaceName);
- repoNode.getSession().save();
- distributionElems.add(new DistributionElem(this,
- workspaceNode));
- // FIXME remove deleted workspaces
- }
- return distributionElems.toArray();
- } catch (RepositoryException e) {
- throw new SlcException(
- "Cannot list workspaces for " + repoNode, e);
- } finally {
- JcrUtils.logoutQuietly(session);
- }
- }
-
- public void dispose() {
- }
-
- public Node getRepoNode() {
- return repoNode;
- }
-
- public String getRepoPath() {
- try {
- return repoNode.getPath();
- } catch (RepositoryException e) {
- throw new SlcException("Cannot get path for " + repoNode, e);
- }
- }
-
- public Repository getRepository() {
- connect();
- return repository;