1 29 30 package com.caucho.jcr.file; 31 32 import com.caucho.jcr.base.BaseNode; 33 import com.caucho.jcr.base.BaseNodeIterator; 34 import com.caucho.jcr.base.BaseNodeType; 35 import com.caucho.vfs.Path; 36 37 import javax.jcr.NodeIterator; 38 import javax.jcr.RepositoryException; 39 import javax.jcr.Session; 40 import javax.jcr.nodetype.NodeType; 41 import java.io.IOException ; 42 43 46 public class DirectoryNode extends BaseNode { 47 private FileSession _session; 48 private Path _path; 49 50 DirectoryNode(FileSession session, Path path) 51 { 52 _session = session; 53 _path = path; 54 } 55 56 59 public NodeType getPrimaryNodeType() 60 { 61 return BaseNodeType.NT_FOLDER; 62 } 63 64 67 public String getPath() 68 throws RepositoryException 69 { 70 return _path.getPath(); 71 } 72 73 76 public String getName() 77 throws RepositoryException 78 { 79 return _path.getTail(); 80 } 81 82 85 public Session getSession() 86 throws RepositoryException 87 { 88 return _session; 89 } 90 91 94 public NodeIterator getNodes() 95 throws RepositoryException 96 { 97 try { 98 String []list = _path.list(); 99 100 BaseNode []children = new BaseNode[list.length]; 101 102 for (int i = 0; i < list.length; i++) { 103 Path childPath = _path.lookup(list[i]); 104 105 if (childPath.isDirectory()) 106 children[i] = new DirectoryNode(_session, childPath); 107 else 108 children[i] = new FileNode(_session, childPath); 109 } 110 111 return new BaseNodeIterator(children); 112 } catch (IOException e) { 113 throw new RepositoryException(e); 114 } 115 } 116 117 public String toString() 118 { 119 return "FileNode[" + _path + "]"; 120 } 121 } 122 | Popular Tags |