de.tum.in.targeteam.client
Class SimplePoolInterface

java.lang.Object
  extended byde.tum.in.targeteam.client.SimplePoolInterface
All Implemented Interfaces:
TransactionMethods

public class SimplePoolInterface
extends java.lang.Object
implements TransactionMethods

A SimplePoolManager supports basic functions for managing an associated pool. The following functions are not supported by this class:

This class supports the following functions: Each operation which changes the pool content is performed as a single transaction.


Field Summary
 
Fields inherited from interface de.tum.in.targeteam.pool.TransactionMethods
CREATE_ALTERNATIVE, DELETE, INSERT_CHILD_ATOM, INSERT_CHILD_MODULE, PREPARE, REMOVE_CHILD_ATOM, REMOVE_CHILD_MODULE, SET_ATOM_CONTENT, SET_ATTR_VALUE, SET_MODULE_CONTENT, STABILIZE
 
Constructor Summary
SimplePoolInterface(PoolManager poolManager, boolean remote)
          Class constructor.
 
Method Summary
 void addAtomChild(java.lang.String name, java.lang.String child)
          Adds the atom child as child to the module name.
 void addModuleChild(java.lang.String name, java.lang.String child)
          Adds the module child as child to the module name.
 void createAtom(java.lang.String name)
          Creates a new atom.
 void createAtomFormat(java.lang.String name, java.lang.String ext, java.lang.String contentfile, java.lang.String attrs)
          Creates a new alternative format of an atom and imports its initial content.
 void createCourse(java.lang.String name, java.lang.String module)
          Creates a new course.
 void createModule(java.lang.String name)
          Creates a new module.
 void deactivate()
          Deactivate the Interface by unexporting the PMClient.
 void deleteAtom(java.lang.String name)
          Deletes an atom and all its alternative formats.
 void deleteCourse(java.lang.String name)
          Deletes a course with its content and error log.
 void deleteModule(java.lang.String name)
          Deletes a module and its content.
 java.lang.String describeAtom(java.lang.String name)
          Gets a description of the Atom with name.
 java.lang.String describeCourse(java.lang.String name)
          Gets a description of the Course with name.
 java.lang.String describeModule(java.lang.String name)
          Gets a description of the module with name.
 java.lang.String describePool()
          Gets a description of the pool.
 void exportAtom(java.lang.String name)
          Exports the atom name.
 void exportAtoms(java.lang.String regexp)
          Exports several atoms in the pool.
 void exportModule(java.lang.String name)
          Exports the content of the module name to the file name.tml.
 void exportModule(java.lang.String name, java.lang.String filename)
          Exports the content of the module name to a file.
 void exportModules(java.lang.String regexp)
          Exports the content of several modules in the pool.
 void importAtom(java.lang.String name)
          Imports the atom name.
 void importAtoms(java.lang.String regexp)
          Imports several atoms in the pool.
 void importModule(java.lang.String name)
          Imports the content of the module name from the file name.tml.
 java.lang.String importModule(java.lang.String name, java.lang.String filename)
          Imports the content of the module name from a file.
 void importModules(java.lang.String regexp)
          Imports the content of several modules in the pool.
 void prepareChildren(java.lang.String name)
          Prepares the children of a module and exports the corresponding pseudo document to the directory specified by the option targeteam.exportdir.
 void prepareCourse(java.lang.String name)
          Prepares a course and exports the result to the directory specified by the option targeteam.coursedir.
 void removeAtomChild(java.lang.String name, java.lang.String i)
          Removes the ith atom child of the module name.
 void removeModuleChild(java.lang.String name, java.lang.String i)
          Removes the ith module child of the module name.
 void rotateAtomChildren(java.lang.String name, java.lang.String cycle)
          Reorders atom children of the module name.
 void rotateModuleChildren(java.lang.String name, java.lang.String cycle)
          Reorders module children of the module name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimplePoolInterface

public SimplePoolInterface(PoolManager poolManager,
                           boolean remote)
                    throws java.io.IOException
Class constructor.

Parameters:
poolManager - the pool to be accessed, wrapped by its manager. May be null if needed only for inspecting the classe's methods, not for real use.
remote - whether the pool manager is remote.
Method Detail

deactivate

public void deactivate()
Deactivate the Interface by unexporting the PMClient.


createModule

public void createModule(java.lang.String name)
                  throws ArgumentException,
                         TransactionException,
                         java.io.IOException
Creates a new module. The initial content is a new (not shared with any other module) empty string.

Parameters:
name - the name for referencing the module.
Throws:
ArgumentException - If there is already a module with name in the pool or if name is null.
TransactionException - If the pool is currently processed by another client.
java.io.IOException - If an error occurred accessing the external pool representation.

createAtom

public void createAtom(java.lang.String name)
                throws ArgumentException,
                       TransactionException,
                       java.io.IOException
Creates a new atom. Initially, there is no format content.

Parameters:
name - the name for referencing the atom.
Throws:
ArgumentException - If there is already a module with name in the pool or if name is null.
TransactionException - If the pool is currently processed by another client.
java.io.IOException - If an error occurred accessing the external pool representation.

deleteModule

public void deleteModule(java.lang.String name)
                  throws ArgumentException,
                         TransactionException,
                         java.io.IOException
Deletes a module and its content.

The module can only be deleted if it is not used as a child of another module or as the associated module of a course.

All versions of the content are deleted which are not shared with any other module.

Parameters:
name - the name of the module to be deleted. If the name is not unique in the pool, only one module with this name will be deleted.
Throws:
ArgumentException - If there is no module with name in the pool or if name is null or if the module is still used as a child of at least one other module in the pool or as the root module of a course in the pool.
TransactionException - If the pool is currently processed by another client.
java.io.IOException - If an error occurred accessing the external pool representation.

deleteAtom

public void deleteAtom(java.lang.String name)
                throws ArgumentException,
                       TransactionException,
                       java.io.IOException
Deletes an atom and all its alternative formats. All versions of all formats are deleted.

The atom can only be deleted if it is not used as a child of a module in the pool.

Parameters:
name - the name of the atom to be deleted. If the name is not unique in the pool, only one atom with this name will be deleted.
Throws:
ArgumentException - If there is no atom with name in the pool or if name is null or if the atom is still used as a child of at least one module in the pool or in the last preparation of at least one course.
TransactionException - If the pool is currently processed by another client.
java.io.IOException - If an error occurred accessing the external pool representation.

createAtomFormat

public void createAtomFormat(java.lang.String name,
                             java.lang.String ext,
                             java.lang.String contentfile,
                             java.lang.String attrs)
                      throws ArgumentException,
                             TransactionException,
                             java.io.IOException
Creates a new alternative format of an atom and imports its initial content. The attributes are specified as a string.

Parameters:
name - the atom name. If the name is not unique in the pool, an arbitrary atom with this name will be used.
ext - the extension for referencing the format.
contentfile - the file from which the initial format content is imported.
attrs - the attributes. This is a string containing the attribute settings in XML notation. Example:
   "type=\"image/gif\" derived-from=\"fig\" derived-by=\"xv\"
 
Throws:
ArgumentException - If there is no atom with name in the pool or if a parameter is null or if there is already a format of atom name with extension ext in the pool or if the contentfile does not exist or if there is a syntax error in attrs.
TransactionException - If the pool is currently processed by another client.
java.io.IOException - If an error occurred accessing the contentfile.

addModuleChild

public void addModuleChild(java.lang.String name,
                           java.lang.String child)
                    throws ArgumentException,
                           TransactionException,
                           java.io.IOException
Adds the module child as child to the module name. If the names child or name are not unique among the modules in the pool, arbitrary modules with these names are used. The module is added behind the last existing child module.

This method checks for cycles. If (in the current versions), the module with name is a descendant of the child module, an exception is signaled.

Parameters:
name - the name of the module to become the parent.
child - the name of the module to be added as child.
Throws:
ArgumentException - If one of the parameters is null or if there is no module with name or child in the pool or if the module with name is (in the current versions) a descendant of the child module.
TransactionException - If the pool is currently processed by another client.
java.io.IOException - If an error occurred accessing the external pool representation.

addAtomChild

public void addAtomChild(java.lang.String name,
                         java.lang.String child)
                  throws ArgumentException,
                         TransactionException,
                         java.io.IOException
Adds the atom child as child to the module name. If the names child or name are not unique among the modules in the pool, an arbitrary atom or module with the name is used. The atom is added behind the last existing child atom.

Parameters:
name - the name of the module to become the parent.
child - the name of the atom to be added as child.
Throws:
ArgumentException - If one of the parameters is null or if there is no module with name or child in the pool or if the module with name is (in the current versions) a descendant of the child module.
TransactionException - If the pool is currently processed by another client.
java.io.IOException - If an error occurred accessing the external pool representation.

removeModuleChild

public void removeModuleChild(java.lang.String name,
                              java.lang.String i)
                       throws ArgumentException,
                              TransactionException,
                              java.io.IOException
Removes the ith module child of the module name. The child modules after the removed child are moved one place to the front.

Parameters:
name - the name of the parent module. If the name is not unique in the pool, an arbitrary module with this name will be used.
i - the index (as a String) of the child to be removed. The first child has index 0. Negative indices are treated as 0. If the index is too large, nothing happens.
Throws:
ArgumentException - If the name is null or if there is no module with name in the pool or if i is no valid number.
TransactionException - If the pool is currently processed by another client.
java.io.IOException - If an error occurred accessing the external pool representation.

removeAtomChild

public void removeAtomChild(java.lang.String name,
                            java.lang.String i)
                     throws ArgumentException,
                            TransactionException,
                            java.io.IOException
Removes the ith atom child of the module name. The child atoms after the removed child are moved one place to the front.

Parameters:
name - the name of the parent module. If the name is not unique in the pool, an arbitrary module with this name will be used.
i - the index (as a String) of the child to be removed. The first child has index 0. Negative indices are treated as 0. If the index is too large, nothing happens.
Throws:
ArgumentException - If the name is null or if there is no module with name in the pool or if i is no valid number.
TransactionException - If the pool is currently processed by another client.
java.io.IOException - If an error occurred accessing the external pool representation.

rotateModuleChildren

public void rotateModuleChildren(java.lang.String name,
                                 java.lang.String cycle)
                          throws ArgumentException,
                                 TransactionException,
                                 java.io.IOException
Reorders module children of the module name. The children are "rotated" according to the index sequence specified in cycle. This means, the child at the first index in cycle is moved to the second index in cycle, the child at the second index is moved to the third index, etc. and the child at the last index is moved to the first index. If the cycle has length 0 or 1, nothing happens.

The cycle is specified as a String, containing positive integer values separated by white space.

Parameters:
name - the name of the parent module. If the name is not unique in the pool, an arbitrary module with this name will be used.
cycle - the index sequence specifying the rotation. The first child has index 0.
Throws:
ArgumentException - If one of the parameters is null or if there is no module with name in the pool or If one of the indices in cycle is larger than the index of the last module child of the module with name or if there is a syntax error in cycle.
TransactionException - If the pool is currently processed by another client.
java.io.IOException - If an error occurred accessing the external pool representation.

rotateAtomChildren

public void rotateAtomChildren(java.lang.String name,
                               java.lang.String cycle)
                        throws ArgumentException,
                               TransactionException,
                               java.io.IOException
Reorders atom children of the module name. The children are "rotated" according to the index sequence specified in cycle. This means, the child at the first index in cycle is moved to the second index in cycle, the child at the second index is moved to the third index, etc. and the child at the last index is moved to the first index. If the cycle has length 0 or 1, nothing happens.

The cycle is specified as a String, containing positive integer values separated by white space.

Parameters:
name - the name of the parent module. If the name is not unique in the pool, an arbitrary module with this name will be used.
cycle - the index sequence specifying the rotation. The first child has index 0.
Throws:
ArgumentException - If one of the parameters is null or if there is no module with name in the pool or If one of the indices in cycle is larger than the index of the last module child of the module with name or if there is a syntax error in cycle.
TransactionException - If the pool is currently processed by another client.
java.io.IOException - If an error occurred accessing the external pool representation.

exportModule

public void exportModule(java.lang.String name,
                         java.lang.String filename)
                  throws ArgumentException,
                         java.io.IOException
Exports the content of the module name to a file. If the file exists, it is replaced.

If no file name is specified, name is used with the extension "tml". If a file name is specified, it must be a local name. The file is always put into the directory specified by the option targeteam.exportdir.

The encoding to be used in the file is taken from the option targeteam.encoding. A corresponding XML declaration is added to the file.

Parameters:
name - the name of the module to be exported. If the name is not unique in the pool, an arbitrary module with this name will be used.
filename - the filename where the content is stored. This must be a local name. If it is null, name is used with extension "tml".
Throws:
ArgumentException - If name is null or if there is no module with name in the pool, or if filename contains a directory part.
java.io.IOException - If an error occurred when writing the content file.

exportModule

public void exportModule(java.lang.String name)
                  throws ArgumentException,
                         java.io.IOException
Exports the content of the module name to the file name.tml. If the file exists, it is replaced. The file is put into the directory specified by the option targeteam.exportdir.

The encoding to be used in the file is taken from the option targeteam.encoding. A corresponding XML declaration is added to the file.

Parameters:
name - the name of the module to be exported. If the name is not unique in the pool, an arbitrary module with this name will be used.
Throws:
ArgumentException - If name is null or if there is no module with name in the pool.
java.io.IOException - If an error occurred when writing the content file.

exportModules

public void exportModules(java.lang.String regexp)
                   throws ArgumentException,
                          java.io.IOException
Exports the content of several modules in the pool. Every module "name", where "name" matches a given regular expression, is written to the file "name.tml". Existing files are replaced. The files are put into the directory as specified by the option targeteam.exportdir.

The encoding to be used in the file is taken from the option targeteam.encoding. A corresponding XML declaration is added to the file.

Parameters:
regexp - the regular expression (in Perl5 syntax) for matching the names of the modules to be exported.
Throws:
ArgumentException - If regexp is null.
java.io.IOException - If an error occurred when writing the content file.

importModule

public java.lang.String importModule(java.lang.String name,
                                     java.lang.String filename)
                              throws ArgumentException,
                                     TransactionException,
                                     java.io.IOException
Imports the content of the module name from a file. The existing content is replaced.

If no file name is specified, name is used with the extension "tml". If a file name is specified, it must be a local name. The file is always accessed in the directory specified by the option targeteam.importdir.

If the file contains an xml declaration with an encoding declaration, the encoding is taken from the declaration. Otherwise, UTF-8 is assumed.

The xml declaration is stripped from the content. If the file contains a document type definition, this is ignored and also stripped.

The file content is always validated against the internal Targeteam DTD for module contents. If the content is not valid, a message describing the error(s) is output and the content in the pool is not replaced.

Parameters:
name - the name of the module to be imported. If the name is not unique in the pool, an arbitrary module with this name will be used.
filename - the filename where the content is stored. This must be a local name. If it is null, name is used with extension "tml".
Returns:
A success message, whether the content has been imported.
Throws:
ArgumentException - If name is null. or if there is no module with name in the pool or if the file does not exist, or if filename contains a directory part.
TransactionException - If the pool is currently processed by another client.
java.io.IOException - If an error occurred when reading the content file or accessing the external pool representation.

importModule

public void importModule(java.lang.String name)
                  throws ArgumentException,
                         TransactionException,
                         java.io.IOException
Imports the content of the module name from the file name.tml. The existing content is replaced. The file is accessed in the directory specified by the option targeteam.importdir.

If the file contains an xml declaration with an encoding declaration, the encoding is taken from the declaration. Otherwise, UTF-8 is assumed.

The xml declaration is stripped from the content. If the file contains a document type definition, this is ignored and also stripped.

The file content is always validated against the internal Targeteam DTD for module contents. If the content is not valid, a message describing the error(s) is output and the content in the pool is not replaced.

Parameters:
name - the name of the module to be imported. If the name is not unique in the pool, an arbitrary module with this name will be used.
Throws:
ArgumentException - If name is null. or if there is no module with name in the pool or if the file does not exist.
TransactionException - If the pool is currently processed by another client.
java.io.IOException - If an error occurred when reading the content file or accessing the external pool representation..

importModules

public void importModules(java.lang.String regexp)
                   throws ArgumentException,
                          java.io.IOException
Imports the content of several modules in the pool. Every module "name", where "name" matches a given regular expression, is imported from the file "name.tml", replacing the existing content in the pool. The files are always accessed in the directory specified by the option targeteam.importdir.

If a file contains an xml declaration with an encoding declaration, the encoding is taken from the declaration. Otherwise, UTF-8 is assumed.

The xml declaration is stripped from the content. If the file contains a document type definition, this is ignored and also stripped.

The file content is always validated against the internal Targeteam DTD for module contents. If the content is not valid, a message describing the error(s) is output and the content in the pool is not replaced.

Parameters:
regexp - the regular expression (in Perl5 syntax) for matching the names of the modules to be imported. The match is performed based on the existing modules in the course, not on the existing files in the import directory!
Throws:
ArgumentException - If regexp is null.
java.io.IOException - If an error occurred when accessing the external pool representation.

exportAtom

public void exportAtom(java.lang.String name)
                throws ArgumentException,
                       java.io.IOException
Exports the atom name. All formats of the atom are exported to the directory specified by the option targeteam.exportdir. For each format a file is created, using the atom name and the format extension. If corresponding files exist in the directory, they are replaced.

If an extension is not unique among the atom formats, an arbitrary format with this extension is exported.

Parameters:
name - the name of the atom to be exported. If the name is not unique in the pool, an arbitrary atom with this name will be used.
Throws:
ArgumentException - If name is null. or if there is no module with name in the pool
java.io.IOException - If an error occurred when writing the files.

exportAtoms

public void exportAtoms(java.lang.String regexp)
                 throws ArgumentException,
                        java.io.IOException
Exports several atoms in the pool. For every atom "name", where "name" matches a given regular expression, all formats of the atom are exported to the directory specified by the option targeteam.exportdir. For each format a file is created, using the atom name and the format extension. If corresponding files exist in the directory, they are replaced.

If an extension is not unique among the formats of an atom, an arbitrary format with this extension is exported.

Throws:
ArgumentException - If regexp is null.
java.io.IOException - If an error occurred when writing the files.

importAtom

public void importAtom(java.lang.String name)
                throws ArgumentException,
                       TransactionException,
                       java.io.IOException
Imports the atom name. All formats of the atom are imported from the directory specified by the option targeteam.importdir. For each format the file is read, which has the atom name and the format extension. If for a format no such file is found, the import is aborted and all formats of the atom remain unchanged. If an extension is not unique among the formats, all formats with the same extension are imported from the same file.

Parameters:
name - the name of the atom to be imported. If the name is not unique in the pool, an arbitrary atom with this name will be used.
Throws:
ArgumentException - If name is null or if there is no module with name in the pool.
TransactionException - If the pool is currently processed by another client.
java.io.IOException - If an error occurred when reading the files.

importAtoms

public void importAtoms(java.lang.String regexp)
                 throws ArgumentException,
                        java.io.IOException
Imports several atoms in the pool. For every atom "name", where "name" matches a given regular expression, all formats of the atom are imported from the directory specified by the option targeteam.importdir. For each format the file is read, which has the atom name and the format extension. If for a format no such file is found, the atom is not imported and all its formats are unchanged in the pool. If an extension is not unique among the formats, all formats with the same extension are imported from the same file.

Parameters:
regexp - the regular expression (in Perl5 syntax) for matching the names of the atoms to be imported. The match is performed based on the existing atoms in the course, not on the existing files in the import directory!
Throws:
ArgumentException - If regexp is null.
java.io.IOException - If an error occurred when accessing the external pool representation.

createCourse

public void createCourse(java.lang.String name,
                         java.lang.String module)
                  throws ArgumentException,
                         TransactionException,
                         java.io.IOException
Creates a new course.

Parameters:
name - the name for referencing the course.
module - the name of the module to associate with the course. If the module name is not unique in the pool, an arbitrary module with this name will be used.
Throws:
ArgumentException - If one of the parameters is null or if there is already a course with name in the pool or if there is no module with module in the pool.
TransactionException - If the pool is currently processed by another client.
java.io.IOException - If an error occurred accessing the external pool representation.

deleteCourse

public void deleteCourse(java.lang.String name)
                  throws ArgumentException,
                         TransactionException,
                         java.io.IOException
Deletes a course with its content and error log.

Parameters:
name - the name of the course to be deleted. If the name is not unique in the pool, only one module with this name will be deleted.
Throws:
ArgumentException - If the name is null or if there is no Course with name in the pool.
TransactionException - If the pool is currently processed by another client.
java.io.IOException - If an error occurred accessing the external pool representation.

prepareCourse

public void prepareCourse(java.lang.String name)
                   throws ArgumentException,
                          PreparationException,
                          TransactionException,
                          java.io.IOException
Prepares a course and exports the result to the directory specified by the option targeteam.coursedir. The following files are stored in the directory: Existing files are replaced.

The encoding to be used for writing the TeachML content is taken from the option targeteam.encoding.

Parameters:
name - the name of the course to be prepared. If the name is not unique in the pool, an arbitrary course with this name will be prepared.
Throws:
ArgumentException - If the name is null or if there is no Course with name in the pool.
PreparationException - If there was an error during preparation.
TransactionException - If the pool is currently processed by another client.
java.io.IOException - If an error occurred when writing files.

prepareChildren

public void prepareChildren(java.lang.String name)
                     throws ArgumentException,
                            PreparationException,
                            TransactionException,
                            java.io.IOException
Prepares the children of a module and exports the corresponding pseudo document to the directory specified by the option targeteam.exportdir. The pseudo document is exported into a file with the name m-children.xml where m is the name of the module. If that file exists, it is replaced.

The encoding to be used for writing the pseudo document is taken from the option targeteam.encoding.

Parameters:
name - the name of the module for which to prepare the children. If the name is not unique in the pool, an arbitrary module with this name will be used.
Throws:
ArgumentException - If the name is null or if there is no Module with name in the pool.
PreparationException - If there was an error during preparation.
TransactionException - If the pool is currently processed by another client.
java.io.IOException - If an error occurred when writing files.

describeModule

public java.lang.String describeModule(java.lang.String name)
                                throws ArgumentException,
                                       java.io.IOException
Gets a description of the module with name. The description contains the names of all child modules and atoms, the names of all parent modules, the names of courses using the module directly or indirectly, and all attributes with their values.

Parameters:
name - the name of the module. If the name is not unique in the pool, an arbitrary module with this name will be described.
Returns:
the description as a string.
Throws:
ArgumentException - If the name is null or if there is no module with name in the pool.
java.io.IOException - If an error occurs when accessing the external pool representation.

describeAtom

public java.lang.String describeAtom(java.lang.String name)
                              throws ArgumentException,
                                     java.io.IOException
Gets a description of the Atom with name. The description contains the extensions and attributes of all formats, the names of all parent modules, the names of courses using the atom directly or indirectly, and all attributes with their values.

Parameters:
name - the name of the atom. If the name is not unique in the pool, an arbitrary atom with this name will be described.
Returns:
the description as a string.
Throws:
ArgumentException - If the name is null or if there is no atom with name in the pool.
java.io.IOException - If an error occurs when accessing the external pool representation.

describeCourse

public java.lang.String describeCourse(java.lang.String name)
                                throws ArgumentException,
                                       java.io.IOException
Gets a description of the Course with name. The description contains the name of the associated module, the date of the last preparation, and the names of all atoms used in the last prepared content.

Parameters:
name - the name of the course. If the name is not unique in the pool, an arbitrary course with this name will be described.
Returns:
the description as a string.
Throws:
ArgumentException - If the name is null or if there is no course with name in the pool.
java.io.IOException - If an error occurs when accessing the external pool representation.

describePool

public java.lang.String describePool()
                              throws java.io.IOException
Gets a description of the pool. The description contains the names of all modules, atoms and courses.

Returns:
the description as a string.
Throws:
java.io.IOException - If an error occurs when accessing the external pool representation.