public class ExtensionsFile extends java.lang.Object implements java.lang.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 java.util.Map<ObjectKey<?>,java.lang.Object> |
allObjects |
private java.io.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 java.lang.String |
name |
private java.util.Map<ObjectKey<?>,java.lang.Object> |
objectMetadata |
private java.util.concurrent.locks.ReentrantReadWriteLock |
rwLock |
private java.net.URI |
uri |
private java.lang.Throwable |
validationError |
private boolean |
wasModified |
Modifier | Constructor and Description |
---|---|
(package private) |
ExtensionsFile(ExtensionsManager manager,
java.io.File file)
Create a new extensions file backed by a real file on the
file system.
|
(package private) |
ExtensionsFile(ExtensionsManager manager,
java.io.File file,
boolean isJar)
Create a new extensions file backed by a real file
on the file system.
|
private |
ExtensionsFile(ExtensionsManager manager,
java.io.File file,
java.net.URI uri,
java.lang.String name,
boolean isJar) |
(package private) |
ExtensionsFile(ExtensionsManager manager,
java.net.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(java.lang.Object o) |
boolean |
exists()
Check if the file exists.
|
About |
getAbout()
Get information about the extensions in this file.
|
java.util.List<java.lang.Object> |
getAllObjects()
Get a list of all objects defined in this extensions
file.
|
java.lang.ClassLoader |
getClassLoader()
Get the class loader used to load classes for the extension.
|
java.io.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> java.util.List<T> |
getMetadataKeysOfClass(java.lang.Class<T> ofClass)
Get a list of all metadata defined in this extensions
file that are keyed with the specified class or interface.
|
java.lang.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> java.util.List<T> |
getObjectsOfClass(java.lang.Class<T> ofClass)
Get a list of all objects defined in this extensions
file that are of the specified class or interface.
|
java.io.InputStream |
getStream(java.lang.String path)
Get an input stream for reading the resource specified by the
given path
|
java.net.URI |
getURI()
Get an URI that points to the extensions file.
|
java.lang.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.
|
java.io.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.
|
java.lang.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 java.io.File file
private final java.net.URI uri
private final boolean isJar
private final java.lang.String name
private final java.util.concurrent.locks.ReentrantReadWriteLock rwLock
private final java.util.Map<ObjectKey<?>,java.lang.Object> allObjects
private final java.util.Map<ObjectKey<?>,java.lang.Object> objectMetadata
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 java.lang.Throwable validationError
ExtensionsFile(ExtensionsManager manager, java.io.File file)
file
- The fileExtensionsFile(ExtensionsManager manager, java.io.File file, boolean isJar)
file
- The fileisJar
- TRUE if it is a JAR file, FALSE if it is an XML fileExtensionsFile(ExtensionsManager manager, java.net.URI uri)
uri
- The URIprivate ExtensionsFile(ExtensionsManager manager, java.io.File file, java.net.URI uri, java.lang.String name, boolean isJar)
public int compareTo(ExtensionsFile other)
compareTo
in interface java.lang.Comparable<ExtensionsFile>
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String getName()
public java.io.File getFile()
public java.net.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 java.lang.Throwable getValidationError()
isValid()
public About getAbout()
public java.io.InputStream getXmlStream() throws java.io.IOException
java.io.IOException
public java.io.InputStream getStream(java.lang.String path) throws java.io.IOException
path
- The path of the resourcejava.io.IOException
boolean validate()
public boolean hasError()
isValid()
method. Extensions that
has an error are automatically disabled.public java.util.List<java.lang.Object> getAllObjects()
ExtensionPoint
:s and
Extension
:s. Use getObjectsOfClass(Class)
to get a list with only one type of objects.public <T> java.util.List<T> getObjectsOfClass(java.lang.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> java.util.List<T> getMetadataKeysOfClass(java.lang.Class<T> ofClass)
ofClass
- The class/interface the metadata keys must be
an instance ofpublic java.lang.ClassLoader getClassLoader() throws java.io.IOException
checkModified()
which forces the creation of a new class loader
when this method is called.java.io.IOException
ExtensionsFile.WriteableExtensionsFile getWriteableFile()
ExtensionsFile.WriteableExtensionsFile.open()
must be called.boolean readLock()
boolean writeLock()