]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - model/SingleJcrNode.java
1 package org
.argeo
.jcr
.ui
.explorer
.model
;
4 import javax
.jcr
.NodeIterator
;
5 import javax
.jcr
.RepositoryException
;
6 import javax
.jcr
.Workspace
;
8 import org
.argeo
.ArgeoException
;
9 import org
.argeo
.eclipse
.ui
.TreeParent
;
12 * UI Tree component. Wraps a node of a JCR {@link Workspace}. It also keeps a
13 * reference to its parent node that can either be a {@link WorkspaceNode}, a
14 * {@link SingleJcrNode} or null if the node is "mounted" as the root of the UI
18 public class SingleJcrNode
extends TreeParent
implements UiNode
{
20 private final Node node
;
21 private String alias
= null;
23 // keeps a local reference to the node's name to avoid exception when the
25 // private final String name;
27 /** Creates a new UiNode in the UI Tree */
28 public SingleJcrNode(TreeParent parent
, Node node
, String name
) {
35 * Creates a new UiNode in the UI Tree, keeping a reference to the alias of
36 * the corresponding repository in the current UI environment. It is useful
37 * to be able to mount nodes as roots of the UI tree.
39 public SingleJcrNode(TreeParent parent
, Node node
, String name
, String alias
) {
46 /** returns the node wrapped by the current Ui object */
47 public Node
getNode() {
52 * Returns the alias corresponding to the repository abstraction that
53 * contains current node. If the current object is mounted as root of the UI
54 * tree, the alias is stored in the object. Otherwise, we must browse the
55 * tree backward to the RepositoryNode.
57 * Alias is then cached in the current object so that next time it will be
60 public String
getAlias() {
62 alias
= ((UiNode
) getParent()).getAlias();
68 * Override normal behaviour to initialize children only when first
72 public synchronized Object
[] getChildren() {
74 return super.getChildren();
76 // initialize current object
78 NodeIterator ni
= node
.getNodes();
79 while (ni
.hasNext()) {
80 Node curNode
= ni
.nextNode();
81 addChild(new SingleJcrNode(this, curNode
, curNode
.getName()));
83 return super.getChildren();
84 } catch (RepositoryException re
) {
85 throw new ArgeoException(
86 "Unexcpected error while initializing children SingleJcrNode",
93 public boolean hasChildren() {
95 return node
.hasNodes();
96 } catch (RepositoryException re
) {
97 throw new ArgeoException(
98 "Unexpected error while checking children node existence",