public class ExtensionsFile extends Object implements Comparable<ExtensionsFile>
getFile()
. An XML file can be both a real file
or an abstract stream of bytes and can be accessed by getXmlStream()
.
The latter method can also be used in the case of a JAR file and will then
open the META-INF/extensions.xml
file.Modifier and Type | Class and Description |
---|---|
static class |
ExtensionsFile.WriteableExtensionsFile
An extensions file with additional methods that allows adding
or modifying information in the underlying extensions file.
|
Modifier and Type | Field and Description |
---|---|
private About |
about |
private Map<ObjectKey<?>,Object> |
allObjects |
private File |
file |
private boolean |
hasError |
private boolean |
isJar |
private boolean |
isNew |
private boolean |
isValid |
private JarClassLoader |
jarLoader |
private long |
lastLength |
private long |
lastModified |
private static org.slf4j.Logger |
log |
private ExtensionsManager |
manager |
private String |
name |
private Map<ObjectKey<?>,Object> |
objectMetadata |
private ReentrantReadWriteLock |
rwLock |
private URI |
uri |
private Throwable |
validationError |
private boolean |
wasModified |
Modifier | Constructor and Description |
---|---|
(package private) |
ExtensionsFile(ExtensionsManager manager,
File file)
Create a new extensions file backed by a real file on the
file system.
|
(package private) |
ExtensionsFile(ExtensionsManager manager,
File file,
boolean isJar)
Create a new extensions file backed by a real file
on the file system.
|
private |
ExtensionsFile(ExtensionsManager manager,
File file,
URI uri,
String name,
boolean isJar) |
(package private) |
ExtensionsFile(ExtensionsManager manager,
URI uri)
Create a new extension file backed by an URI.
|
Modifier and Type | Method and Description |
---|---|
boolean |
checkModified()
Check if the underlying file has been modified since it was
last processed.
|
int |
compareTo(ExtensionsFile other) |
boolean |
equals(Object o) |
boolean |
exists()
Check if the file exists.
|
About |
getAbout()
Get information about the extensions in this file.
|
List<Object> |
getAllObjects()
Get a list of all objects defined in this extensions
file.
|
ClassLoader |
getClassLoader()
Get the class loader used to load classes for the extension.
|
File |
getFile()
Get the underlying file on the file system.
|
<M> M |
getMetadata(ObjectKey<M> key)
Get metadata registered for a given given key.
|
<T> List<T> |
getMetadataKeysOfClass(Class<T> ofClass)
Get a list of all metadata defined in this extensions
file that are keyed with the specified class or interface.
|
String |
getName()
Get the name of the file.
|
<O> O |
getObjectForKey(ObjectKey<O> key)
Get the object that was registered for the given key.
|
<T> List<T> |
getObjectsOfClass(Class<T> ofClass)
Get a list of all objects defined in this extensions
file that are of the specified class or interface.
|
InputStream |
getStream(String path)
Get an input stream for reading the resource specified by the
given path
|
URI |
getURI()
Get an URI that points to the extensions file.
|
Throwable |
getValidationError()
Get more information about the error that caused the validation
to fail.
|
(package private) ExtensionsFile.WriteableExtensionsFile |
getWriteableFile()
Get a writeable view for the current file.
|
InputStream |
getXmlStream()
Get an input stream for reading the XML file containing the extension
definitions.
|
boolean |
hasError()
If there was an error when registering the extensions in this file.
|
int |
hashCode() |
boolean |
isIgnored()
Is this an extension file that should be ignored?
|
boolean |
isInstalled()
Is this file installed into the system or not?
|
boolean |
isJar()
If the file name ends with '.jar' the file is considered a JAR file.
|
boolean |
isNew()
If the file is a new file not previously processed by the
extension system.
|
boolean |
isValid()
Is the file a valid extensions file according to the last
performed validation.
|
(package private) boolean |
readLock()
Try to aquire a read-lock.
|
String |
toString() |
(package private) boolean |
validate()
Validate the XML file with the extension definitions.
|
boolean |
wasModified()
Check if the file was modified when the last call to
checkModified() was made. |
(package private) boolean |
writeLock()
Try to aquire a write-lock.
|
private static final org.slf4j.Logger log
private final ExtensionsManager manager
private final File file
private final URI uri
private final boolean isJar
private final String name
private final ReentrantReadWriteLock rwLock
private boolean isNew
private boolean wasModified
private long lastModified
private long lastLength
private JarClassLoader jarLoader
private About about
private boolean hasError
private volatile boolean isValid
private Throwable validationError
ExtensionsFile(ExtensionsManager manager, File file)
file
- The fileExtensionsFile(ExtensionsManager manager, File file, boolean isJar)
file
- The fileisJar
- TRUE if it is a JAR file, FALSE if it is an XML fileExtensionsFile(ExtensionsManager manager, URI uri)
uri
- The URIprivate ExtensionsFile(ExtensionsManager manager, File file, URI uri, String name, boolean isJar)
public int compareTo(ExtensionsFile other)
compareTo
in interface Comparable<ExtensionsFile>
public String getName()
public File getFile()
public URI getURI()
public boolean isJar()
public boolean exists()
File.exists()
and File.isFile()
.File.exists()
public boolean isNew()
ExtensionsFile.WriteableExtensionsFile.markAsProcessed()
is called which
usually happens when all extensions has been registered.public boolean isInstalled()
public boolean isIgnored()
public boolean wasModified()
checkModified()
was made. It is recommended
that processor implementation use this method instead
to avoid inconsistent behaviour if the file happens to
be modified while a processor is running.public boolean checkModified()
File.lastModified()
and File.length()
of the
underlying file and compare that to the last known timestamp and size.
Files that are JAR files we also check with the class loader if any of
the libraries it uses have changed.
The result of this call is remembered until this method is called again or until the file is marked as processed.
public boolean isValid()
META-INF/extensions.xml
.
checkModified()
returns
true, the return value of this method may be out of sync.
Re-validation of modified files are usually performed
by the extensions manager by calling
ExtensionsManager.scanForChanges()
NOTE! The validation will only verify that the XML file
follows the rules defined by the schema definition. It will
not check that actual classes, etc. exists and can be created.
This usually happens later in the registration process, and
can be checked by hasError()
.
getValidationError()
,
checkModified()
,
hasError()
public Throwable getValidationError()
isValid()
public About getAbout()
public InputStream getXmlStream() throws IOException
IOException
public InputStream getStream(String path) throws IOException
path
- The path of the resourceIOException
boolean validate()
public boolean hasError()
isValid()
method. Extensions that
has an error are automatically disabled.public List<Object> getAllObjects()
ExtensionPoint
:s and
Extension
:s. Use getObjectsOfClass(Class)
to get a list with only one type of objects.public <T> List<T> getObjectsOfClass(Class<T> ofClass)
ofClass
- The class/interface the objects must be
an instance ofpublic <O> O getObjectForKey(ObjectKey<O> key)
key
- An object keypublic <M> M getMetadata(ObjectKey<M> key)
key
- An object keypublic <T> List<T> getMetadataKeysOfClass(Class<T> ofClass)
ofClass
- The class/interface the metadata keys must be
an instance ofpublic ClassLoader getClassLoader() throws IOException
checkModified()
which forces the creation of a new class loader
when this method is called.IOException
ExtensionsFile.WriteableExtensionsFile getWriteableFile()
ExtensionsFile.WriteableExtensionsFile.open()
must be called.boolean readLock()
boolean writeLock()