Skip to content

Commit

Permalink
More tweaks the VirtualFileAssembly to porperly support children with…
Browse files Browse the repository at this point in the history
…in the assembly
  • Loading branch information
John Bailey committed Dec 17, 2009
1 parent 566c188 commit a44fbaa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/main/java/org/jboss/vfs/VirtualFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ public List<VirtualFile> getChildren() {
virtualFiles.add(child);
submounts.remove(name);
}
for (String name : submounts) {
final VirtualFile child = new VirtualFile(name, this);
virtualFiles.add(child);
}
return virtualFiles;
}

Expand Down
26 changes: 17 additions & 9 deletions src/main/java/org/jboss/vfs/VirtualFileAssembly.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class VirtualFileAssembly implements Closeable {

private static final Random RANDOM_NUM_GEN = new SecureRandom();

private final AssemblyNode rootNode = new AssemblyNode();
private final AssemblyNode rootNode = new AssemblyNode("");

private final List<Closeable> mountHandles = new CopyOnWriteArrayList<Closeable>();

Expand Down Expand Up @@ -111,15 +111,20 @@ public VirtualFile getFile(VirtualFile mountPoint, VirtualFile target) {
* Returns a list of all the names of the children in the assembly.
* @return
*/
public Set<String> getChildNames(VirtualFile mountPoint, VirtualFile target) {
public List<String> getChildNames(VirtualFile mountPoint, VirtualFile target) {
List<String> names = new LinkedList<String>();
AssemblyNode targetNode = null;
if(mountPoint.equals(target)) {
return rootNode.children.keySet();
targetNode = rootNode;
} else {
targetNode = rootNode.find(new Path(VFSUtils.getRelativePath(mountPoint, target)));
}
AssemblyNode node = rootNode.find(new Path(VFSUtils.getRelativePath(mountPoint, target)));
if(node != null) {
return node.children.keySet();
if(targetNode != null) {
for(AssemblyNode childNode : targetNode.children.values()) {
names.add(childNode.realName);
}
}
return Collections.emptySet();
return names;
}

public boolean contains(VirtualFile mountPoint, VirtualFile target) {
Expand Down Expand Up @@ -180,10 +185,13 @@ private String getCurrent() {
*/
private static class AssemblyNode {
private final Map<String, AssemblyNode> children = new ConcurrentHashMap<String, AssemblyNode>();

private final String realName;

private VirtualFile target;

public AssemblyNode() {
public AssemblyNode(String realName) {
this.realName = realName;
}

/**
Expand Down Expand Up @@ -223,7 +231,7 @@ public AssemblyNode find(Path path, boolean createIfMissing) {
if (!createIfMissing) {
return null;
}
childNode = new AssemblyNode();
childNode = new AssemblyNode(current);
addChild(current, childNode);
}
return childNode.find(path, createIfMissing);
Expand Down

0 comments on commit a44fbaa

Please sign in to comment.