|
3.2.4: 2013-12-06 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.basedb.util.extensions.manager.ExtensionsFile
public class ExtensionsFile
Represents a file with extensions in it. The file is either an XML file
or a JAR file. A JAR file is always a real file on the file system and
can be accessed with 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.
Nested Class Summary | |
---|---|
static class |
ExtensionsFile.WriteableExtensionsFile
An extensions file with additional methods that allows adding or modifying information in the underlying extensions file. |
Field Summary | |
---|---|
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.apache.log4j.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
|
Constructor Summary | |
---|---|
(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. |
Method Summary | ||
---|---|---|
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. |
|
|
getMetadata(ObjectKey<M> key)
Get metadata registered for a given given key. |
|
|
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. |
|
|
getObjectForKey(ObjectKey<O> key)
Get the object that was registered for the given key. |
|
|
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 |
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. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private static final org.apache.log4j.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 final Map<ObjectKey,Object> allObjects
private final Map<ObjectKey,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 Throwable validationError
Constructor Detail |
---|
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)
Method Detail |
---|
public int compareTo(ExtensionsFile other)
compareTo
in interface Comparable<ExtensionsFile>
public int hashCode()
hashCode
in class Object
public boolean equals(Object o)
equals
in class Object
public String toString()
toString
in class Object
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 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.
ExtensionsFile.WriteableExtensionsFile.markAsProcessed()
,
wasModified()
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 resource
IOException
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 of
public <O> O getObjectForKey(ObjectKey<O> key)
key
- An object key
public <M> M getMetadata(ObjectKey<M> key)
key
- An object key
public <T> List<T> getMetadataKeysOfClass(Class<T> ofClass)
ofClass
- The class/interface the metadata keys must be
an instance of
public ClassLoader getClassLoader() throws IOException
IOException
ExtensionsFile.WriteableExtensionsFile getWriteableFile()
ExtensionsFile.WriteableExtensionsFile.open()
must be called.
boolean readLock()
boolean writeLock()
|
3.2.4: 2013-12-06 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |