@ParametersAreNonnullByDefault public class FileAttributesFactory extends Object
This class allows you to register attribute providers and add
implementations. You must provide one such factory per filesystem and at
least provide an implementation of the basic file attributes
, as required by the API.
It is also responsible for generating instances of attribute provider
classes at runtime (using MethodHandle
s).
You must extend this class, provide the metadata class used when
building attribute providers and then register your attribute provider
classes using addImplementation(String, Class)
; you can even
register your own attribute views using addDescriptor(AttributesDescriptor)
(do this before registering
implementations).
See this pagefor a sample use.
Unless otherwise noted, all methods of this class will throw a NullPointerException
if a null argument is passed.
FileSystemDriverBase
Constructor and Description |
---|
FileAttributesFactory()
Constructor to extend
|
Modifier and Type | Method and Description |
---|---|
protected void |
addDescriptor(AttributesDescriptor descriptor)
Add an attribute view descriptor
|
protected void |
addImplementation(String name,
Class<? extends FileAttributesProvider> providerClass)
Add an implementation for a given attribute view
|
Map<String,AttributesDescriptor> |
getDescriptors()
Return a list of all attribute descriptors registered with this factory
|
<A extends BasicFileAttributes> |
getFileAttributes(Class<A> targetClass,
Object metadata)
Generate an attribute provider matching the target attributes class
|
<V extends FileAttributeView> |
getFileAttributeView(Class<V> targetClass,
Object metadata)
Generate an attribute provider implementing the target attribute view
class
|
FileAttributesProvider |
getProvider(String name,
Object metadata)
Instantiate a new provider for a given attribute view with the given
metadata
|
protected void |
setMetadataClass(Class<?> metadataClass)
Set the metadata class used when constructing new attribute provider
instances
|
boolean |
supportsFileAttributeView(Class<? extends FileAttributeView> viewClass) |
boolean |
supportsFileAttributeView(String name) |
public final boolean supportsFileAttributeView(Class<? extends FileAttributeView> viewClass)
public final boolean supportsFileAttributeView(String name)
@Nonnull public final Map<String,AttributesDescriptor> getDescriptors()
@Nullable public final FileAttributesProvider getProvider(String name, Object metadata) throws IOException
name
- the attribute view namemetadata
- the metadata to use to instantiate the providernull
if this view is not supportedIOException
- failed to generate the providerFileSystemDriverBase.readAttributes(Path, String, LinkOption...)
,
FileSystemDriverBase.setAttribute(Path, String, Object,
LinkOption...)
,
MethodHandle.invoke(Object...)
@Nullable public final <V extends FileAttributeView> V getFileAttributeView(Class<V> targetClass, Object metadata) throws IOException
Note that the returned target may not "strictly" implement the view;
it may be a subclass of it. For instance, if you only have an
implementation for DosFileAttributeView
, this is what will be
returned if you ask for a BasicFileAttributeView
(since the
former extends the latter).
V
- type parameter of the target viewtargetClass
- the target viewmetadata
- the metadata to generate the provider withnull
if this view is not supportedIOException
- failed to generate the attribute providerFileSystemDriverBase.getFileAttributeView(Path, Class,
LinkOption...)
@Nullable public final <A extends BasicFileAttributes> A getFileAttributes(Class<A> targetClass, Object metadata) throws IOException
Note that the returned target may not "strictly" implement the
attribute class; it may be a subclass of it. For instance, if you only
have an implementation for DosFileAttributes
, this is what will
be returned if you ask for a BasicFileAttributes
(since the
former extends the latter).
A
- type parameter of the target attribute classtargetClass
- the target attribute classmetadata
- the metadata to generate the provider withnull
if this attribute class is not supportedIOException
- failed to generate the attribute providerFileSystemDriverBase.readAttributes(Path, Class, LinkOption...)
protected final void setMetadataClass(Class<?> metadataClass)
This method must be called before registering attribute provider implementations.
metadataClass
- the classIllegalArgumentException
- a metadata class has already been setFileSystemDriver.getPathMetadata(Path)
protected final void addDescriptor(AttributesDescriptor descriptor)
descriptor
- the descriptor to addIllegalArgumentException
- a descriptor by that name is already
registeredAttributesDescriptor.getName()
protected final void addImplementation(String name, Class<? extends FileAttributesProvider> providerClass)
name
- the name of the viewproviderClass
- the attribute provider classIllegalArgumentException
- no metadata class has been set, or no
descriptor associated with that viewInvalidAttributeProviderException
- provided class is not a
concrete class; or no suitable constructor has been found; or it is not a
subclass of the associated view class and (if any) attribute classAttributesDescriptor.getViewClass()
,
AttributesDescriptor.getAttributeClass()