org.activemath.omdocjdom.mbase
Class OmdocJdomMBase

java.lang.Object
  extended by org.activemath.omdocjdom.mbase.OmdocJdomMBase
All Implemented Interfaces:
Serializable

public class OmdocJdomMBase
extends Object
implements Serializable

This class is the base class of a remake of the lost FileMBase approach (which was based on Xerces DOM structure), this one is based on the JDOM package and its extension in the org.activemath.omdocjdom.package package.

It can serve requests as defined in the MBaseRef interface through the use of OmdocJdomMBaseRef class. It can also serve as a good validator of IDs where IDs used follow the syntax described under the ID class.

It also has a little API for reloading documents and other debugging output. See the command-line invocation of this method or of the MBaseBuilder class, which serves as main configuration engine. The class here is mainly to enable reading methods and is the one used by

All documents (hence ids) produced here contain a constant collection, i.e. a source-descriptor, so that clients refer to the same source, it is given by parameters of the builder or is "thisMBase".

All access methods synchronized on a read-write lock, {@link #lock}, thereby allowing rebuilds performed securely.

Version:
See Also:
Serialized Form

Field Summary
 MBaseBuilder builder
           
static String CVS_ID
           
 ReadWriteLock lock
           
 ElementFromIDTable table
           
 
Constructor Summary
OmdocJdomMBase(ElementFromIDTable table, MBaseBuilder builder)
           
OmdocJdomMBase(Subconfiguration config)
           
 
Method Summary
 void addOMdoc(File file)
          Adds the named file and rebuilds.
 String getAttribute(MBaseID id, String attName)
           
 MBaseID getCanonicalID(MBaseID givenID)
          Identifies the given element and returns the ID read from there.
 OJElement getChildren(MBaseID mbaseid, String xPathReducedExpression)
           
 Collection getCollectionsProvided()
           
 Hashtable getCommonName(MBaseID id)
           
 org.jdom.Element getCompleteDCMetadata(MBaseID id)
           
 Collection getDefinitions(MBaseID symbolID, Collection collections)
          Reads the "inversed-dependency" elements of type "DEFINES" in metadata/extradata that are built by MBaseBuilder then filters out those whose "of" is not in the collections given as parameter.
 Collection getDependencies(MBaseID id)
           
 Collection getDepsOrInvDeps(MBaseID mbaseID, String depName)
          Returns a collection of MBaseRef.Dependency objects.
 org.jdom.Element getFormalContent(MBaseID id)
           
 Collection getForWhat(MBaseID id)
           
 Collection getInversedDependency(MBaseID mbaseID, String wantedType)
          Returns a List of the MBaseIDs that have inversed-dependencies of the given type in the given element.
 org.jdom.Element getMetadata(MBaseID id)
           
 Collection getProofs(MBaseID assertionID, Collection collections)
          Reads the "inversed-dependency" elements of type "PROVES" in metadata/extradata that are built by MBaseBuilder then filters out those whose "of" is not in the collections given as parameter.
 Collection getRelated(MBaseID id, Collection collections)
          Reads the "inversed-dependency" elements in metadata/extradata that are built by MBaseBuilder then filters out those whose "of" is not in the collections given as parameter.
 OJDocument getStructuredListOfConcepts(Collection collections)
           
 List getTextualContent(MBaseID id)
           
 MBaseID getTheory(MBaseID id)
           
 String getTypeString(MBaseID id)
           
 boolean isUpAndRunning()
          Returns true only if there was no exception during the last build process.
 Iterator listItems(MBaseID mbaseID)
          Iterates over the element itself and its children listing the IDs of this element.
 Set listTheories(Collection collections)
          Goes through the list of IDs collecting all the theories in the given collection.
static void main(String[] args)
           
 ID makeID(MBaseID id)
          This makes an ID of an MBaseID but ignores the collection part of the ID as it supposes a dispatch has been made already before if there were different collections.
 MBaseID makeMBaseID(ID id)
          Makes a simple shadow MBaseID out of an ID...
 MBaseID makeMBaseID(MBaseID baseID, ID id)
          Checks weather the collection name of id matches the collection name of this one then returns something with the collectio name of baseID, otherwise builds another collection name.
 String possiblyRemoveBasePath(File file)
           
 void reload()
          Does the same as reload(java.util.List) except with no error-accumulator.
 void reload(List errorAccumulator)
          Checks the modification dates of the files that were recorded, reloads the newer files, drops the too old files and rebuilds.
 void removeOMdoc(File file)
          Removes the named file and rebuilds.
 Iterator searchIDs(String idSubstring)
          A quite inefficient method to search for IDs, a tree or index would be needed, moreover, asynchronous result serving should be done one day.
 Collection searchText(String textToSearch)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CVS_ID

public static final String CVS_ID
See Also:
Constant Field Values

table

public final ElementFromIDTable table

builder

public final MBaseBuilder builder

lock

public final ReadWriteLock lock
Constructor Detail

OmdocJdomMBase

public OmdocJdomMBase(ElementFromIDTable table,
                      MBaseBuilder builder)

OmdocJdomMBase

public OmdocJdomMBase(Subconfiguration config)
               throws Exception
Throws:
Exception
Method Detail

main

public static void main(String[] args)
                 throws Exception
Throws:
Exception

getInversedDependency

public Collection getInversedDependency(MBaseID mbaseID,
                                        String wantedType)
Returns a List of the MBaseIDs that have inversed-dependencies of the given type in the given element.

Parameters:
mbaseID - Missing description of Parameter
wantedType - Missing description of Parameter
Returns:
Missing description of return The inversedDependency value

getDepsOrInvDeps

public Collection getDepsOrInvDeps(MBaseID mbaseID,
                                   String depName)
                            throws MBaseException
Returns a collection of MBaseRef.Dependency objects.

Parameters:
mbaseID - Missing description of Parameter
depName - Missing description of Parameter
Returns:
Missing description of return The depsOrInvDeps value
Throws:
MBaseException

getDependencies

public Collection getDependencies(MBaseID id)
                           throws MBaseException
Throws:
MBaseException

getRelated

public Collection getRelated(MBaseID id,
                             Collection collections)
                      throws MBaseException
Reads the "inversed-dependency" elements in metadata/extradata that are built by MBaseBuilder then filters out those whose "of" is not in the collections given as parameter.

Parameters:
id - Missing description of Parameter
collections - Missing description of Parameter
Returns:
Missing description of return The related value
Throws:
MBaseException

getDefinitions

public Collection getDefinitions(MBaseID symbolID,
                                 Collection collections)
Reads the "inversed-dependency" elements of type "DEFINES" in metadata/extradata that are built by MBaseBuilder then filters out those whose "of" is not in the collections given as parameter.

Parameters:
symbolID - Missing description of Parameter
collections - Missing description of Parameter
Returns:
Missing description of return The definitions value

getProofs

public Collection getProofs(MBaseID assertionID,
                            Collection collections)
Reads the "inversed-dependency" elements of type "PROVES" in metadata/extradata that are built by MBaseBuilder then filters out those whose "of" is not in the collections given as parameter.

Parameters:
assertionID - Missing description of Parameter
collections - Missing description of Parameter
Returns:
Missing description of return The proofs value

getTextualContent

public List getTextualContent(MBaseID id)
                       throws MBaseItemNotFoundException
Throws:
MBaseItemNotFoundException

getFormalContent

public org.jdom.Element getFormalContent(MBaseID id)
                                  throws MBaseException
Throws:
MBaseException

getMetadata

public org.jdom.Element getMetadata(MBaseID id)
                             throws MBaseItemNotFoundException
Throws:
MBaseItemNotFoundException

getCompleteDCMetadata

public org.jdom.Element getCompleteDCMetadata(MBaseID id)
                                       throws MBaseItemNotFoundException
Throws:
MBaseItemNotFoundException

getTheory

public MBaseID getTheory(MBaseID id)
                  throws MBaseItemNotFoundException
Parameters:
id - Missing description of Parameter
Returns:
Missing description of return The theory value
Throws:
MBaseItemNotFoundException - Missing description of Exception

getCommonName

public Hashtable getCommonName(MBaseID id)
                        throws MBaseItemNotFoundException
Parameters:
id - Missing description of Parameter
Returns:
Missing description of return The commonName value
Throws:
MBaseItemNotFoundException - Missing description of Exception

getAttribute

public String getAttribute(MBaseID id,
                           String attName)
                    throws MBaseItemNotFoundException
Throws:
MBaseItemNotFoundException

getTypeString

public String getTypeString(MBaseID id)
                     throws MBaseItemNotFoundException
Parameters:
id - Missing description of Parameter
Returns:
Missing description of return The typeString value
Throws:
MBaseItemNotFoundException - Missing description of Exception

getForWhat

public Collection getForWhat(MBaseID id)
                      throws MBaseItemNotFoundException
Throws:
MBaseItemNotFoundException

getChildren

public OJElement getChildren(MBaseID mbaseid,
                             String xPathReducedExpression)
                      throws MBaseItemNotFoundException
Throws:
MBaseItemNotFoundException

getStructuredListOfConcepts

public OJDocument getStructuredListOfConcepts(Collection collections)
                                       throws MBaseException
Throws:
MBaseException

isUpAndRunning

public boolean isUpAndRunning()
Returns true only if there was no exception during the last build process.

Returns:
Missing description of return The upAndRunning value

getCollectionsProvided

public Collection getCollectionsProvided()

getCanonicalID

public MBaseID getCanonicalID(MBaseID givenID)
                       throws MBaseItemNotFoundException
Identifies the given element and returns the ID read from there. Currently contains no heuristic.

Parameters:
givenID - Missing description of Parameter
Returns:
Missing description of return The canonicalID value
Throws:
MBaseItemNotFoundException - Missing description of Exception

reload

public void reload()
            throws org.jdom.JDOMException,
                   NoSuchIDException,
                   IOException
Does the same as reload(java.util.List) except with no error-accumulator.

Throws:
org.jdom.JDOMException
NoSuchIDException
IOException

reload

public void reload(List errorAccumulator)
            throws org.jdom.JDOMException,
                   NoSuchIDException,
                   IOException
Checks the modification dates of the files that were recorded, reloads the newer files, drops the too old files and rebuilds. If the rebuild throws an exception, restores the unloaded document and rebuilds. The builder throws an exception only when instructed to do so, on startup, otherwise reports errors as indicated, see MBaseErrorReporter and its configuration throught MBaseBuilder.

Parameters:
errorAccumulator - A list where error records will be added-to. Can be null. (see MBaseErrorReporter#makeAsRecord()).
Throws:
org.jdom.JDOMException - Missing description of Exception
NoSuchIDException - Missing description of Exception
IOException - Missing description of Exception

removeOMdoc

public void removeOMdoc(File file)
                 throws IOException,
                        NoSuchIDException
Removes the named file and rebuilds. If the rebuild throws an exception, restores the removed file and rebuilds. The builder throws an exception only when instructed to do so, on startup, otherwise reports (all) errors as it did before.

Parameters:
file - Missing description of Parameter
Throws:
IOException - Missing description of Exception
NoSuchIDException - Missing description of Exception

addOMdoc

public void addOMdoc(File file)
              throws NoSuchIDException,
                     org.jdom.JDOMException,
                     IOException,
                     Exception
Adds the named file and rebuilds. If the rebuild throws an exception, restores the removed file and rebuilds. The builder throws an exception only when instructed to do so, on startup, otherwise reports (all) errors as it did before.

Parameters:
file - Missing description The feature to be added to the OMdoc attribute
Throws:
NoSuchIDException - Missing description of Exception
org.jdom.JDOMException - Missing description of Exception
IOException - Missing description of Exception
Exception

makeMBaseID

public MBaseID makeMBaseID(MBaseID baseID,
                           ID id)
Checks weather the collection name of id matches the collection name of this one then returns something with the collectio name of baseID, otherwise builds another collection name. This makes calls to this database relative and absolute ones absolute...

Parameters:
baseID - Missing description of Parameter
id - Missing description of Parameter
Returns:
Missing description of the Returned Value

makeMBaseID

public MBaseID makeMBaseID(ID id)
Makes a simple shadow MBaseID out of an ID...

Parameters:
id - Missing description of Parameter
Returns:
Missing description of the Returned Value

makeID

public ID makeID(MBaseID id)
This makes an ID of an MBaseID but ignores the collection part of the ID as it supposes a dispatch has been made already before if there were different collections.

Parameters:
id - Missing description of Parameter
Returns:
Missing description of the Returned Value

listItems

public Iterator listItems(MBaseID mbaseID)
                   throws MBaseException
Iterates over the element itself and its children listing the IDs of this element. This will not list the children that are magically added to a theory like the assertion elements with a theory attribute.

Parameters:
mbaseID - Missing description of Parameter
Returns:
an iterator that walks progressively hence would be invalid if a content is modified return MBaseID objects.
Throws:
MBaseException

listTheories

public Set listTheories(Collection collections)
Goes through the list of IDs collecting all the theories in the given collection. This method could be much optimized if the ElementFromIDTable would use a better storage.

Parameters:
collections - Missing description of Parameter
Returns:
a set of theory names.

searchText

public Collection searchText(String textToSearch)

searchIDs

public Iterator searchIDs(String idSubstring)
A quite inefficient method to search for IDs, a tree or index would be needed, moreover, asynchronous result serving should be done one day.

Parameters:
idSubstring - Missing description of Parameter
Returns:
Missing description of the Returned Value

possiblyRemoveBasePath

public String possiblyRemoveBasePath(File file)
                              throws IOException
Throws:
IOException