1fba2635c088b01af59300e8a02611bb788ee3bffchrismair/*
2fba2635c088b01af59300e8a02611bb788ee3bffchrismair * Copyright 2008 the original author or authors.
3fba2635c088b01af59300e8a02611bb788ee3bffchrismair *
4fba2635c088b01af59300e8a02611bb788ee3bffchrismair * Licensed under the Apache License, Version 2.0 (the "License");
5fba2635c088b01af59300e8a02611bb788ee3bffchrismair * you may not use this file except in compliance with the License.
6fba2635c088b01af59300e8a02611bb788ee3bffchrismair * You may obtain a copy of the License at
7fba2635c088b01af59300e8a02611bb788ee3bffchrismair *
8fba2635c088b01af59300e8a02611bb788ee3bffchrismair *      http://www.apache.org/licenses/LICENSE-2.0
9fba2635c088b01af59300e8a02611bb788ee3bffchrismair *
10fba2635c088b01af59300e8a02611bb788ee3bffchrismair * Unless required by applicable law or agreed to in writing, software
11fba2635c088b01af59300e8a02611bb788ee3bffchrismair * distributed under the License is distributed on an "AS IS" BASIS,
12fba2635c088b01af59300e8a02611bb788ee3bffchrismair * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13fba2635c088b01af59300e8a02611bb788ee3bffchrismair * See the License for the specific language governing permissions and
14fba2635c088b01af59300e8a02611bb788ee3bffchrismair * limitations under the License.
15fba2635c088b01af59300e8a02611bb788ee3bffchrismair */
16fba2635c088b01af59300e8a02611bb788ee3bffchrismairpackage org.mockftpserver.fake.filesystem;
17fba2635c088b01af59300e8a02611bb788ee3bffchrismair
18fba2635c088b01af59300e8a02611bb788ee3bffchrismair/**
19fba2635c088b01af59300e8a02611bb788ee3bffchrismair * File system entry representing a directory
20fba2635c088b01af59300e8a02611bb788ee3bffchrismair *
21fba2635c088b01af59300e8a02611bb788ee3bffchrismair * @author Chris Mair
22fba2635c088b01af59300e8a02611bb788ee3bffchrismair * @version $Revision$ - $Date$
23fba2635c088b01af59300e8a02611bb788ee3bffchrismair */
24fba2635c088b01af59300e8a02611bb788ee3bffchrismairpublic class DirectoryEntry extends AbstractFileSystemEntry {
25fba2635c088b01af59300e8a02611bb788ee3bffchrismair
26fba2635c088b01af59300e8a02611bb788ee3bffchrismair    /**
27fba2635c088b01af59300e8a02611bb788ee3bffchrismair     * Construct a new instance without setting its path
28fba2635c088b01af59300e8a02611bb788ee3bffchrismair     */
29fba2635c088b01af59300e8a02611bb788ee3bffchrismair    public DirectoryEntry() {
30fba2635c088b01af59300e8a02611bb788ee3bffchrismair    }
31fba2635c088b01af59300e8a02611bb788ee3bffchrismair
32fba2635c088b01af59300e8a02611bb788ee3bffchrismair    /**
33fba2635c088b01af59300e8a02611bb788ee3bffchrismair     * Construct a new instance with the specified value for its path
34fba2635c088b01af59300e8a02611bb788ee3bffchrismair     *
35fba2635c088b01af59300e8a02611bb788ee3bffchrismair     * @param path - the value for path
36fba2635c088b01af59300e8a02611bb788ee3bffchrismair     */
37fba2635c088b01af59300e8a02611bb788ee3bffchrismair    public DirectoryEntry(String path) {
38fba2635c088b01af59300e8a02611bb788ee3bffchrismair        super(path);
39fba2635c088b01af59300e8a02611bb788ee3bffchrismair    }
40fba2635c088b01af59300e8a02611bb788ee3bffchrismair
41fba2635c088b01af59300e8a02611bb788ee3bffchrismair    /**
42fba2635c088b01af59300e8a02611bb788ee3bffchrismair     * Return true to indicate that this entry represents a directory
43fba2635c088b01af59300e8a02611bb788ee3bffchrismair     *
44fba2635c088b01af59300e8a02611bb788ee3bffchrismair     * @return true
45fba2635c088b01af59300e8a02611bb788ee3bffchrismair     */
46fba2635c088b01af59300e8a02611bb788ee3bffchrismair    public boolean isDirectory() {
47fba2635c088b01af59300e8a02611bb788ee3bffchrismair        return true;
48fba2635c088b01af59300e8a02611bb788ee3bffchrismair    }
49fba2635c088b01af59300e8a02611bb788ee3bffchrismair
50fba2635c088b01af59300e8a02611bb788ee3bffchrismair    /**
51fba2635c088b01af59300e8a02611bb788ee3bffchrismair     * Return the size of this directory. This method returns zero.
52fba2635c088b01af59300e8a02611bb788ee3bffchrismair     *
53fba2635c088b01af59300e8a02611bb788ee3bffchrismair     * @return the file size in bytes
54fba2635c088b01af59300e8a02611bb788ee3bffchrismair     */
55fba2635c088b01af59300e8a02611bb788ee3bffchrismair    public long getSize() {
56fba2635c088b01af59300e8a02611bb788ee3bffchrismair        return 0;
57fba2635c088b01af59300e8a02611bb788ee3bffchrismair    }
58fba2635c088b01af59300e8a02611bb788ee3bffchrismair
59fba2635c088b01af59300e8a02611bb788ee3bffchrismair    /**
60fba2635c088b01af59300e8a02611bb788ee3bffchrismair     * @see java.lang.Object#toString()
61fba2635c088b01af59300e8a02611bb788ee3bffchrismair     */
62fba2635c088b01af59300e8a02611bb788ee3bffchrismair    public String toString() {
63fba2635c088b01af59300e8a02611bb788ee3bffchrismair        return "Directory['" + getPath() + "' lastModified=" + getLastModified() + "  owner=" + getOwner() +
64fba2635c088b01af59300e8a02611bb788ee3bffchrismair                "  group=" + getGroup() + "  permissions=" + getPermissions() + "]";
65fba2635c088b01af59300e8a02611bb788ee3bffchrismair    }
66fba2635c088b01af59300e8a02611bb788ee3bffchrismair
67fba2635c088b01af59300e8a02611bb788ee3bffchrismair    /**
68fba2635c088b01af59300e8a02611bb788ee3bffchrismair     * Return a new FileSystemEntry that is a clone of this object, except having the specified path
69fba2635c088b01af59300e8a02611bb788ee3bffchrismair     *
70fba2635c088b01af59300e8a02611bb788ee3bffchrismair     * @param path - the new path value for the cloned file system entry
71fba2635c088b01af59300e8a02611bb788ee3bffchrismair     * @return a new FileSystemEntry that has all the same values as this object except for its path
72fba2635c088b01af59300e8a02611bb788ee3bffchrismair     */
73fba2635c088b01af59300e8a02611bb788ee3bffchrismair    public FileSystemEntry cloneWithNewPath(String path) {
74fba2635c088b01af59300e8a02611bb788ee3bffchrismair        DirectoryEntry clone = new DirectoryEntry(path);
75fba2635c088b01af59300e8a02611bb788ee3bffchrismair        clone.setLastModified(getLastModified());
76fba2635c088b01af59300e8a02611bb788ee3bffchrismair        clone.setOwner(getOwner());
77fba2635c088b01af59300e8a02611bb788ee3bffchrismair        clone.setGroup(getGroup());
78fba2635c088b01af59300e8a02611bb788ee3bffchrismair        clone.setPermissions(getPermissions());
79fba2635c088b01af59300e8a02611bb788ee3bffchrismair        return clone;
80fba2635c088b01af59300e8a02611bb788ee3bffchrismair    }
81fba2635c088b01af59300e8a02611bb788ee3bffchrismair
82fba2635c088b01af59300e8a02611bb788ee3bffchrismair}
83