10 import java.io.FileOutputStream;
11 import java.io.IOException;
12 import java.io.InputStream;
14 import java.util.List;
34 private boolean overwriteFlag;
45 this(source, dest,
false);
61 this.overwriteFlag = overwriteFlag;
66 dest.addMessageHandler(h);
69 private void cacheFile(String filename)
throws IOException {
71 dest.writeModelFile(filename, source.getInStream(filename));
75 private void cacheModelFiles() throws IOException, ModelManagerException {
79 String infohtml = source.getModelXMLTagValue(
"model.description.infohtml");
81 throw new ModelManagerException(
"Inconsistent model state: XML tag for infohtml exists but the file "
82 + infohtml +
" could not be found in the model directory.");
87 String image = source.getModelXMLTagValue(
"model.description.image");
89 throw new ModelManagerException(
90 "Inconsistent model state: XML tag for a model image exists but the file " + image
91 +
" could not be found in the model directory.");
95 cacheFile(
"dexclasses.jar");
96 cacheFile(
"classes.jar");
101 return dest.getClassLoader();
111 return source.getFolderList();
123 dest.writeModelFile(filename, source.getInStream(filename));
126 return dest.getInStream(filename);
131 return dest.getMathObjReader();
137 return source.getModelDescriptors(pr);
142 return dest.getModelDir();
147 return dest.getModelType();
152 return dest.getModelURI();
157 return dest.getModelXMLAttribute(attrib_name);
162 return dest.getModelXMLAttribute(attrib_name, tagname);
167 return dest.getModelXMLTagValue(tagname);
172 return dest.getModelXMLTagValue(tagname, default_value);
177 return dest.getParameters();
183 return source.isValidModelDir(dir);
193 return dest.modelFileExists(filename) || source.
modelFileExists(filename);
198 dest.removeMessageHandler(h);
203 dest.sendMessage(msg);
207 public void useModel(String dir)
throws ModelManagerException {
208 source.useModel(dir);
209 File destdir =
new File(dest.
getRoot() + File.separator + dir);
210 if (!destdir.isDirectory()) {
211 if (!destdir.mkdir())
212 throw new ModelManagerException(
"Could not create directory " + dir +
" in " + dest.
getRoot());
214 File modelxml =
new File(destdir,
"model.xml");
215 if (overwriteFlag || !modelxml.exists()) {
217 FileOutputStream out =
new FileOutputStream(modelxml);
218 byte[] buffer =
new byte[1024];
220 InputStream in = source.getInStream(
"model.xml");
221 while ((bytes_read = in.read(buffer)) > 0) {
222 out.write(buffer, 0, bytes_read);
225 }
catch (IOException e) {
226 throw new ModelManagerException(
"Error caching model.xml", e);
232 }
catch (IOException e) {
233 throw new ModelManagerException(
"Error caching model files.", e);
238 return dest.clearCurrentModel();
243 return dest.xmlTagExists(tagname);
248 return source.getLoadingMessage();
String getModelXMLAttribute(String attrib_name, String tagname)
An interface for classes capable of sending messages.
boolean deleteCachedFiles()
boolean modelFileExists(String filename)
Returns whether the specified file exists in the current model folder.
Reading matrices and vectors with a bunch of convenient overloads for different sources and output fo...
String[] getFolderList()
Returns the list of all models directories available at the ModelManagers source location.
void addMessageHandler(IMessageHandler h)
abstract boolean modelFileExists(String filename)
Returns whether the specified file exists in the current model folder.
String getRoot()
Returns the root folder for the model directories.
Manages models loaded from the file system available via the java.io classes.
boolean isValidModelDir(String dir)
Known model types within the JaRMoSBase project.
This class serves as base class for accessing various types of models at different locations...
A class for model parameters.
String getModelXMLTagValue(String tagname, String default_value)
Represents a short description of a model managed by a model manager.
CachingModelManager(AModelManager source, FileModelManager dest, boolean overwriteFlag)
Creates a new caching model manager.
String getModelXMLTagValue(String tagname)
URI getModelURI()
Returns an URI for the current model location/directory.
InputStream getInStreamImpl(String filename)
Template method.
void useModel(String dir)
String getModelXMLAttribute(String attrib_name)
MathObjectReader getMathObjReader()
void sendMessage(String msg)
Parameters getParameters()
void removeMessageHandler(IMessageHandler h)
CachingModelManager(AModelManager source, FileModelManager dest)
Creates a new caching model manager with overwriteFlag set to false.
A wrapper class that takes any AModelManager as source and a FileModelManager as target.
boolean xmlTagExists(String tagname)
List< ModelDescriptor > getModelDescriptors(IProgressReporter pr)
boolean xmlTagExists(String tagname)
Checks if a specified tag exists inside the current models model.xml file.
String getLoadingMessage()
A short message that writes "loading SD models" dependent on the actual instance. ...
ClassLoader getClassLoader()
boolean modelFileExists(String filename)
Simple interface for progress reporting.