1 /*
2 * Copyright (C) 2005-2015 Schlichtherle IT Services.
3 * All rights reserved. Use is subject to license terms.
4 */
5 package net.java.truevfs.kernel.spec;
6
7 import javax.annotation.concurrent.Immutable;
8 import net.java.truecommons.shed.UniqueObject;
9
10 /**
11 * An abstract factory for components required to access a file system.
12 * <p>
13 * Subclasses should be immutable.
14 *
15 * @see FsCompositeDriver
16 * @author Christian Schlichtherle
17 */
18 @Immutable
19 public abstract class FsDriver
20 extends UniqueObject
21 implements FsModel.Factory<FsManager>, FsController.Factory<FsManager> {
22
23 /**
24 * Returns {@code true} if and only if this is an archive driver, that is,
25 * if file systems of this type must be a member of a parent file system.
26 *
27 * @return The implementation in the class {@link FsDriver}
28 * unconditionally returns {@code false}.
29 */
30 public boolean isArchiveDriver() { return false; }
31
32 /**
33 * {@inheritDoc}
34 * <p>
35 * The implementation in the class {@link FsDriver} forwards the call to
36 * the given file system manager.
37 */
38 @Override
39 public final FsModel newModel(
40 FsManager context,
41 FsMountPoint mountPoint,
42 FsModel parent) {
43 assert null == parent
44 ? null == mountPoint.getParent()
45 : parent.getMountPoint().equals(mountPoint.getParent());
46 return context.newModel(this, mountPoint, parent);
47 }
48
49 /**
50 * Decorates the given file system model.
51 *
52 * @param model the file system model to decorate.
53 * @return The implementation in the class {@link FsDriver}
54 * unconditionally returns {@code model}.
55 */
56 public FsModel decorate(FsModel model) { return model; }
57
58 /**
59 * Returns a string representation of this object for debugging and logging
60 * purposes.
61 */
62 @Override
63 public String toString() {
64 return String.format("%s@%x[archiveDriver=%b]",
65 getClass().getName(),
66 hashCode(),
67 isArchiveDriver());
68 }
69 }