JaRMoS  1.1
Java Reduced Model Simulations
 All Classes Namespaces Files Functions Variables Enumerator Groups Pages
jarmos.io.AModelManager Class Referenceabstract

This class serves as base class for accessing various types of models at different locations. More...

Inheritance diagram for jarmos.io.AModelManager:
jarmos.app.io.AssetModelManager jarmos.io.CachingModelManager jarmos.io.FileModelManager jarmos.io.WebModelManager jarmos.app.io.SDModelManager jarmos.app.io.WebModelManager

Classes

class  ModelManagerException
 This Exception gets thrown when an error occurs regarding the functionality of the ModelManager. More...
 

Public Member Functions

 AModelManager ()
 Constructs a new ModelManager and a private DocumentBuilder and SchemaFactory. More...
 
void addMessageHandler (IMessageHandler h)
 
Object loadModelClass (String name) throws ModelManagerException
 Loads a class available in the precompiled classes associated with the current model. More...
 
BufferedReader getBufReader (String filename) throws IOException
 
ClassLoader getClassLoader ()
 This method yields access to any specialized class loaders in subclasses. More...
 
final InputStream getInStream (String filename) throws IOException
 Returns an InputStream instance streaming the contents of the file given by filename. More...
 
MathObjectReader getMathObjReader ()
 Use this method in order to get a MathObjectReader instance fitted for the current selected model. More...
 
List< ModelDescriptorgetModelDescriptors () throws ModelManagerException
 Scans all directories given by getFolderList() for valid models and returns a list of model descriptors for each valid model. More...
 
List< ModelDescriptorgetModelDescriptors (IProgressReporter pr) throws ModelManagerException
 Scans all directories given by getFolderList() for valid models and returns a list of model descriptors for each valid model. More...
 
String getModelDir ()
 
FieldDescriptor[] getModelFieldTypes ()
 
ModelType getModelType ()
 Returns the model type as given in the model.xml attribute "type" of the "model" tag. More...
 
abstract URI getModelURI ()
 Returns an URI for the current model location/directory. More...
 
String getModelXMLAttribute (String attrib_name)
 Returns the attribute value of any attributes of the "model" tag in the model.xml file. More...
 
String getModelXMLAttribute (String attrib_name, String tagname)
 Returns the attribute value of any attributes of the tag given by tagname in the model.xml file. More...
 
String getModelXMLTagValue (String tagname)
 Works as the overload with default value, but returns null if no matchin element is found. More...
 
String getModelXMLTagValue (String tagname, String default_value)
 Returns the text content of a tag inside the model.xml file. More...
 
String getModelPackageStr ()
 Returns the package of any java source files associated with this model. More...
 
Parameters getParameters ()
 Reads the parameters from the model XML file and returns a Parameters object. More...
 
boolean isValidModelDir (String dir)
 Checks if a model.xml file exists in the specified directory and performs xsd-validation. More...
 
abstract boolean modelFileExists (String filename)
 Returns whether the specified file exists in the current model folder. More...
 
void removeMessageHandler (IMessageHandler h)
 
void useModel (String location) throws ModelManagerException
 Sets the specified source as current model path. More...
 
boolean xmlTagExists (String tagname)
 Checks if a specified tag exists inside the current models model.xml file. More...
 

Static Public Attributes

static final String CLASSES_JARFILE = "classes.jar"
 The name of the jar file inside a models directory containing .class files in java bytecode. More...
 
static final String info_filename = "site_info.html"
 The model's info html file name (imported from rbappmit, might change later) More...
 

Protected Member Functions

abstract String[] getFolderList () throws IOException
 Returns the list of all models directories available at the ModelManagers source location. More...
 
abstract String getLoadingMessage ()
 A short message that writes "loading SD models" dependent on the actual instance. More...
 
abstract InputStream getInStreamImpl (String filename) throws IOException
 Template method. More...
 
void sendMessage (String msg)
 

Detailed Description

This class serves as base class for accessing various types of models at different locations.

Implementing classes implement the abstract members in order to reflect necessary adoptions to different input sources like the file system, websites or others like Android-Assets.

Implemented in JKerMor are jarmos.io.WebModelManager and jarmos.io.FileModelManager.

Each manager has a root directory which must be, depending on the type, either provided at instantiation or are given implicitly. The model system is organized in a way that the root directory contains folders which each contain a single model. Within each such folder, a model.xml-file must be present that describes the model.

The allowed XML file structure is determined by the model.xsd file in the JaRMoSBase project.

Author
Daniel Wirtz
Date
2013-08-07

Definition at line 61 of file AModelManager.java.

Constructor & Destructor Documentation

jarmos.io.AModelManager.AModelManager ( )

Constructs a new ModelManager and a private DocumentBuilder and SchemaFactory.

Unfortunately, the Android 8 API does not seem to support the W3C XML Schema, so no validation is performed on an android :-(

See "http://stackoverflow.com/questions/3129934/schemafactory-doesnt-support-w3c-xml-schema-in-platform-level-8" or "http://developer.android.com/reference/javax/xml/validation/SchemaFactory.html#newInstance%28java.lang.String%29" on how it SHOULD be..

Definition at line 124 of file AModelManager.java.

Member Function Documentation

void jarmos.io.AModelManager.addMessageHandler ( IMessageHandler  h)
Parameters
h

Definition at line 160 of file AModelManager.java.

BufferedReader jarmos.io.AModelManager.getBufReader ( String  filename) throws IOException
Parameters
filename
Returns
A buffered reader with 8192 bytes buffer, pointing at the file specified.
Exceptions
IOException
Deprecated:
Dont use, only here for old rbAppMIT model loading.

Definition at line 192 of file AModelManager.java.

ClassLoader jarmos.io.AModelManager.getClassLoader ( )

This method yields access to any specialized class loaders in subclasses.

As the android platform works with different loaders then a JRE, for example, this interface is provided to enable custom classes loaded with whatever platform.

If subclasses do not override, the default system class loader is provided.

The class loader must be configured in a way that a call to loadClass(String name) must search also inside the current model's directory.

Returns
A custom class loader instance.

Definition at line 211 of file AModelManager.java.

abstract String [] jarmos.io.AModelManager.getFolderList ( ) throws IOException
protectedpure virtual

Returns the list of all models directories available at the ModelManagers source location.

At this stage, no validity checks have to be performed regarding if a returned folder actually contains a valid model.

Returns
Exceptions
IOException

Implemented in jarmos.io.CachingModelManager, jarmos.io.FileModelManager, jarmos.io.WebModelManager, and jarmos.app.io.AssetModelManager.

final InputStream jarmos.io.AModelManager.getInStream ( String  filename) throws IOException

Returns an InputStream instance streaming the contents of the file given by filename.

Parameters
filenameThe model file to return a stream for
Returns
An InputStream pointing to the resource
Exceptions
IOException

Definition at line 240 of file AModelManager.java.

abstract InputStream jarmos.io.AModelManager.getInStreamImpl ( String  filename) throws IOException
protectedpure virtual

Template method.

Implementations of this method must locate the given file inside the current model directory and return an input stream pointing to it.

Parameters
filenameThe model file to return a stream for
Returns
An InputStream pointing to the resource
Exceptions
IOException

Implemented in jarmos.io.CachingModelManager, jarmos.io.WebModelManager, jarmos.io.FileModelManager, and jarmos.app.io.AssetModelManager.

abstract String jarmos.io.AModelManager.getLoadingMessage ( )
protectedpure virtual

A short message that writes "loading SD models" dependent on the actual instance.

Returns

Implemented in jarmos.io.CachingModelManager, jarmos.io.FileModelManager, jarmos.io.WebModelManager, jarmos.app.io.AssetModelManager, jarmos.app.io.SDModelManager, and jarmos.app.io.WebModelManager.

MathObjectReader jarmos.io.AModelManager.getMathObjReader ( )

Use this method in order to get a MathObjectReader instance fitted for the current selected model.

This method returns an automatically configured reader (the old model data is encoded in little endian).

Returns
A MathObjectReader for the current selected model.

Definition at line 265 of file AModelManager.java.

List<ModelDescriptor> jarmos.io.AModelManager.getModelDescriptors ( ) throws ModelManagerException

Scans all directories given by getFolderList() for valid models and returns a list of model descriptors for each valid model.

Returns
A list of ModelDescriptors
Exceptions
ModelManagerException

Definition at line 276 of file AModelManager.java.

List<ModelDescriptor> jarmos.io.AModelManager.getModelDescriptors ( IProgressReporter  pr) throws ModelManagerException

Scans all directories given by getFolderList() for valid models and returns a list of model descriptors for each valid model.

Parameters
prA IProgressReporter instance to report process in the loading to.
Returns
A list of ModelDescriptors
Exceptions
ModelManagerException

Definition at line 290 of file AModelManager.java.

String jarmos.io.AModelManager.getModelDir ( )
Returns
The directory of the current model.

Definition at line 341 of file AModelManager.java.

FieldDescriptor [] jarmos.io.AModelManager.getModelFieldTypes ( )

Definition at line 345 of file AModelManager.java.

String jarmos.io.AModelManager.getModelPackageStr ( )

Returns the package of any java source files associated with this model.

Defaults to the default package (="") if none is given.

Returns

Definition at line 482 of file AModelManager.java.

ModelType jarmos.io.AModelManager.getModelType ( )

Returns the model type as given in the model.xml attribute "type" of the "model" tag.

Returns
The model type as string

Definition at line 370 of file AModelManager.java.

abstract URI jarmos.io.AModelManager.getModelURI ( )
pure virtual

Returns an URI for the current model location/directory.

Returns

Implemented in jarmos.io.CachingModelManager, jarmos.io.FileModelManager, jarmos.io.WebModelManager, and jarmos.app.io.AssetModelManager.

String jarmos.io.AModelManager.getModelXMLAttribute ( String  attrib_name)

Returns the attribute value of any attributes of the "model" tag in the model.xml file.

Returns null if no model directory has been set or the attribute does not exist.

Parameters
attrib_nameThe attribute's name
Returns
The attribute value or null if the attribute does not exist

Definition at line 389 of file AModelManager.java.

String jarmos.io.AModelManager.getModelXMLAttribute ( String  attrib_name,
String  tagname 
)

Returns the attribute value of any attributes of the tag given by tagname in the model.xml file.

Returns null if no model directory has been set or the attribute does not exist.

Parameters
attrib_namethe attribute's name
tagnameThe xml tag whos attributes are to be searched.
Returns
The attribute value or null if the attribute does not exist

Definition at line 408 of file AModelManager.java.

String jarmos.io.AModelManager.getModelXMLTagValue ( String  tagname)

Works as the overload with default value, but returns null if no matchin element is found.

Parameters
tagname
Returns
The tag value or null.

Definition at line 454 of file AModelManager.java.

String jarmos.io.AModelManager.getModelXMLTagValue ( String  tagname,
String  default_value 
)

Returns the text content of a tag inside the model.xml file.

The tag given may be separated by a dot, so that a clear position can be addressed. So "description.name" will look up any tags named "description" and search therein for any tags named "name". Always the first item with a corresponding name is returned.

Parameters
tagnameThe tag whos value should be returned.
default_valueThe default value if no matching element is found
Returns
The tag text content or the default value if no matching tag is found.

Definition at line 471 of file AModelManager.java.

Parameters jarmos.io.AModelManager.getParameters ( )

Reads the parameters from the model XML file and returns a Parameters object.

Returns
A Parameters object or null if the model definition does not contain parameters.

Definition at line 509 of file AModelManager.java.

boolean jarmos.io.AModelManager.isValidModelDir ( String  dir)

Checks if a model.xml file exists in the specified directory and performs xsd-validation.

Note: On the current Android platform the validation using the xsd W3C Schema is somehow NOT implemented; so, validation is skipped on android platforms.

Precondition
dir != null
Parameters
dirThe directory to check
Returns
True if the directory contains a valid model, false otherwise

Definition at line 548 of file AModelManager.java.

Object jarmos.io.AModelManager.loadModelClass ( String  name) throws ModelManagerException

Loads a class available in the precompiled classes associated with the current model.

The model.xml-tag "package" is used if set to specify the package under which the class can be found; if not set the default package (="") is used.

Parameters
name
Returns
Exceptions
ModelManagerException

Definition at line 173 of file AModelManager.java.

abstract boolean jarmos.io.AModelManager.modelFileExists ( String  filename)
pure virtual

Returns whether the specified file exists in the current model folder.

Parameters
filename
Returns
true if the file exists in the model, false otherwise

Implemented in jarmos.io.CachingModelManager, jarmos.io.WebModelManager, jarmos.io.FileModelManager, and jarmos.app.io.AssetModelManager.

void jarmos.io.AModelManager.removeMessageHandler ( IMessageHandler  h)
Parameters
h

Definition at line 592 of file AModelManager.java.

void jarmos.io.AModelManager.sendMessage ( String  msg)
protected

Definition at line 596 of file AModelManager.java.

void jarmos.io.AModelManager.useModel ( String  location) throws ModelManagerException

Sets the specified source as current model path.

Requires the

Precondition
isValidModelDir(location) == true
Postcondition
The model is loaded from the specified location and calls to getInStream etc. will serve files from there.
Parameters
locationThe directory/path to change to
Exceptions
ModelManagerExceptionThe current model directory, path or location does not contain a valid model.

Definition at line 615 of file AModelManager.java.

boolean jarmos.io.AModelManager.xmlTagExists ( String  tagname)

Checks if a specified tag exists inside the current models model.xml file.

Parameters
tagnameThe tag to check
Returns
True if the tag exists or false otherwise

Definition at line 651 of file AModelManager.java.

Member Data Documentation

final String jarmos.io.AModelManager.CLASSES_JARFILE = "classes.jar"
static

The name of the jar file inside a models directory containing .class files in java bytecode.

This file name can be used inside custom implementations of getClassLoader, if directory searches are not permitted/implemented (e.g. WebModelManager)

Definition at line 95 of file AModelManager.java.

final String jarmos.io.AModelManager.info_filename = "site_info.html"
static

The model's info html file name (imported from rbappmit, might change later)

Definition at line 100 of file AModelManager.java.


The documentation for this class was generated from the following file: