+ final static String separator = "/";
+ final static char separatorChar = '/';
+
+ private final JcrFileSystem fs;
+ /** null for non absolute paths */
+ private final WorkspaceFileStore fileStore;
+ private final String[] path;// null means root
+ private final boolean absolute;
+
+ // optim
+ private final int hashCode;
+
+ public JcrPath(JcrFileSystem filesSystem, String path) {
+ this.fs = filesSystem;
+ if (path == null)
+ throw new JcrFsException("Path cannot be null");
+ if (path.equals(separator)) {// root
+ this.path = null;
+ this.absolute = true;
+ this.hashCode = 0;
+ this.fileStore = fs.getBaseFileStore();
+ return;
+ } else if (path.equals("")) {// empty path
+ this.path = new String[] { "" };
+ this.absolute = false;
+ this.fileStore = null;
+ this.hashCode = "".hashCode();
+ return;
+ }
+
+ if (path.equals("~")) {// home
+ path = filesSystem.getUserHomePath();
+ if (path == null)
+ throw new JcrFsException("No home directory available");
+ }
+
+ this.absolute = path.charAt(0) == separatorChar ? true : false;
+
+ this.fileStore = absolute ? fs.getFileStore(path) : null;