gov.sandia.cognition.framework.io
Class ModelFileHandler

java.lang.Object
  extended by gov.sandia.cognition.framework.io.ModelFileHandler

public class ModelFileHandler
extends Object

The ModelFileHandler class is an entry point for reading files that contain a CognitiveModel or CognitiveModelFactory objects. It handles the various file formats that the Framework supports.

Since:
2.0
Author:
Justin Basilico

Field Summary
static String BINARY_SERIALIZED_EXTENSION
          The extension for binary serialized models.
static String CSV_EXTENSION
          The extension for comma-separated-value models.
static String XML_SERIALIZED_EXTENSION
          The extension for XML serialized models.
 
Constructor Summary
protected ModelFileHandler()
          Creates a new instance of ModelIOHandler
 
Method Summary
static CognitiveModel castOrCreateModel(Object o)
          Attempts to cast the given Object to a CognitiveModel.
static CognitiveModel readModel(File file)
          Attempts to read a CognitiveModel from the given file.
static CognitiveModel readModel(String fileName)
          Attempts to read a CognitiveModel from the given file name.
static CognitiveModel readModelBinarySerialized(File file)
          Attempts to read a CognitiveModel from the given file in binary serialized format.
static CognitiveModel readModelCSV(File file)
          Attempts to read a CognitiveModel from the given file in CSV format.
static CognitiveModelFactory readModelFactory(File file)
          Attempts to read a CognitiveModelFactory from the given file.
static CognitiveModelFactory readModelFactory(String fileName)
          Attempts to read a CognitiveModelFactory from the given file name.
static CognitiveModelFactory readModelFactoryBinarySerialized(File file)
          Attempts to read a CognitiveModelFactory from the given file in binary serialized format.
static CognitiveModelFactory readModelFactoryCSV(File file)
          Attempts to read a CognitiveModelFactory from the given file in CSV format.
static CognitiveModelFactory readModelFactoryXMLSerialized(File file)
          Attempts to read a CognitiveModelFactory from the given file in XML serialized format.
static CognitiveModel readModelXMLSerialized(File file)
          Attempts to read a CognitiveModel from the given file in XML serialized format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BINARY_SERIALIZED_EXTENSION

public static final String BINARY_SERIALIZED_EXTENSION
The extension for binary serialized models.

See Also:
Constant Field Values

XML_SERIALIZED_EXTENSION

public static final String XML_SERIALIZED_EXTENSION
The extension for XML serialized models.

See Also:
Constant Field Values

CSV_EXTENSION

public static final String CSV_EXTENSION
The extension for comma-separated-value models.

See Also:
Constant Field Values
Constructor Detail

ModelFileHandler

protected ModelFileHandler()
Creates a new instance of ModelIOHandler

Method Detail

readModel

public static CognitiveModel readModel(String fileName)
                                throws IOException
Attempts to read a CognitiveModel from the given file name.

Parameters:
fileName - The name of the file.
Returns:
The CognitiveModel read from the file or null if it does not contain a model.
Throws:
IOException - If there is an IOException when reading the model.

readModel

public static CognitiveModel readModel(File file)
                                throws IOException
Attempts to read a CognitiveModel from the given file.

Parameters:
file - The file.
Returns:
The CognitiveModel read from the file.
Throws:
IOException - If there is an IOException when reading the model or if the data contained in the file is not a model.

castOrCreateModel

public static CognitiveModel castOrCreateModel(Object o)
                                        throws IOException
Attempts to cast the given Object to a CognitiveModel. If it is not a CognitiveModel or CognitiveModelFactory it throws an exception. If the object is a CognitiveModelFactory it creates a model from the factory and returns it.

Parameters:
o - The Object to cast to a model.
Returns:
A casted or created CognitiveModel.
Throws:
IOException - If the object is not a CognitiveModel or CognitiveModelFactory.

readModelXMLSerialized

public static CognitiveModel readModelXMLSerialized(File file)
                                             throws IOException
Attempts to read a CognitiveModel from the given file in XML serialized format.

Parameters:
file - The file.
Returns:
The CognitiveModel read from the file.
Throws:
IOException - If there is an IOException when reading the model or if the data contained in the file is not a model.

readModelBinarySerialized

public static CognitiveModel readModelBinarySerialized(File file)
                                                throws IOException
Attempts to read a CognitiveModel from the given file in binary serialized format.

Parameters:
file - The file.
Returns:
The CognitiveModel read from the file.
Throws:
IOException - If there is an IOException when reading the model or if the data contained in the file is not a model.

readModelCSV

public static CognitiveModel readModelCSV(File file)
                                   throws IOException
Attempts to read a CognitiveModel from the given file in CSV format.

Parameters:
file - The file.
Returns:
The CognitiveModel read from the file.
Throws:
IOException - If there is an IOException when reading the model or if the data contained in the file is not a model.

readModelFactory

public static CognitiveModelFactory readModelFactory(String fileName)
                                              throws IOException
Attempts to read a CognitiveModelFactory from the given file name.

Parameters:
fileName - The file name.
Returns:
The CognitiveModelFactory read from the file.
Throws:
IOException - If there is an IOException when reading the model or if the data contained in the file is not a model.

readModelFactory

public static CognitiveModelFactory readModelFactory(File file)
                                              throws IOException
Attempts to read a CognitiveModelFactory from the given file.

Parameters:
file - The file.
Returns:
The CognitiveModelFactory read from the file.
Throws:
IOException - If there is an IOException when reading the model or if the data contained in the file is not a model.

readModelFactoryXMLSerialized

public static CognitiveModelFactory readModelFactoryXMLSerialized(File file)
                                                           throws IOException
Attempts to read a CognitiveModelFactory from the given file in XML serialized format.

Parameters:
file - The file.
Returns:
The CognitiveModelFactory read from the file.
Throws:
IOException - If there is an IOException when reading the model factory or if the data contained in the file is not a model factory.

readModelFactoryBinarySerialized

public static CognitiveModelFactory readModelFactoryBinarySerialized(File file)
                                                              throws IOException
Attempts to read a CognitiveModelFactory from the given file in binary serialized format.

Parameters:
file - The file.
Returns:
The CognitiveModelFactory read from the file.
Throws:
IOException - If there is an IOException when reading the model factory or if the data contained in the file is not a model factory.

readModelFactoryCSV

public static CognitiveModelFactory readModelFactoryCSV(File file)
                                                 throws IOException
Attempts to read a CognitiveModelFactory from the given file in CSV format.

Parameters:
file - The file.
Returns:
The CognitiveModelFactory read from the file.
Throws:
IOException - If there is an IOException when reading the model factory or if the data contained in the file is not a model factory.