org.argouml.persistence
Class AbstractFilePersister

java.lang.Object
  extended byjavax.swing.filechooser.FileFilter
      extended byorg.argouml.persistence.AbstractFilePersister
All Implemented Interfaces:
ProjectFilePersister
Direct Known Subclasses:
UmlFilePersister, XmiFilePersister

public abstract class AbstractFilePersister
extends FileFilter
implements ProjectFilePersister

To persist to and from zargo (zipped file) storage.


Field Summary
private  EventListenerList listenerList
           
 
Constructor Summary
AbstractFilePersister()
           
 
Method Summary
 boolean accept(File f)
           
 void addProgressListener(ProgressListener listener)
          Add any object interested in listening to persistence progress.
protected  File copyFile(File src, File dest)
          Copies one file src to another, raising file exceptions if there are some problems.
protected  File createTempFile(File file)
          Create a temporary copy of the existing file.
abstract  Project doLoad(File file)
           
protected abstract  void doSave(Project project, File file)
          Implement in your concrete class to save a project to a file.
protected  void fireProgressEvent(long percent)
          Inform listeners of any progress notifications.
protected abstract  String getDesc()
          Just the description, not the extension between "()".
 String getDescription()
           
protected  String getEncoding()
          Supply the encoding to be used throughout the persistence mechanism.
abstract  String getExtension()
          The extension valid for this type of file.
private static String getExtension(File f)
           
private static String getExtension(String filename)
           
 boolean isFileExtensionApplicable(String filename)
          Given the full filename this returns true if that filename contains the expected extension for the is persister.
private  void postSave(Project project, File file)
          Handle archiving on completion of a save such as renaming the temporary save file to the real filename.
private  void preSave(Project project, File file)
          Handle archiving of previous file or any other common requirements before saving a model to a file.
 void removeProgressListener(ProgressListener listener)
          Remove any object no longer interested in listening to persistence progress.
 void save(Project project, File file)
          Save a project to file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

listenerList

private EventListenerList listenerList
Constructor Detail

AbstractFilePersister

public AbstractFilePersister()
Method Detail

getEncoding

protected String getEncoding()
Supply the encoding to be used throughout the persistence mechanism.

Returns:
the encoding.

createTempFile

protected File createTempFile(File file)
                       throws FileNotFoundException,
                              IOException
Create a temporary copy of the existing file.

Parameters:
file - the file to copy.
Returns:
the temp file or null if none copied.
Throws:
FileNotFoundException - if file not found
IOException - if error reading or writing

copyFile

protected File copyFile(File src,
                        File dest)
                 throws FileNotFoundException,
                        IOException
Copies one file src to another, raising file exceptions if there are some problems.

Parameters:
dest - The destination file.
src - The source file.
Returns:
The destination file after successful copying.
Throws:
IOException - if there is some problems with the files.
FileNotFoundException - if any of the files cannot be found.

accept

public boolean accept(File f)
See Also:
FileFilter.accept(java.io.File)

getExtension

public abstract String getExtension()
The extension valid for this type of file. (Just the chars, not the dot: e.g. "zargo".)

Returns:
the extension valid for this type of file

getDesc

protected abstract String getDesc()
Just the description, not the extension between "()".

Returns:
the description valid for this type of file

getExtension

private static String getExtension(File f)

getExtension

private static String getExtension(String filename)

isFileExtensionApplicable

public boolean isFileExtensionApplicable(String filename)
Given the full filename this returns true if that filename contains the expected extension for the is persister.

Parameters:
filename - The filename to test.
Returns:
true if the filename is valid for this persister

getDescription

public String getDescription()
See Also:
FileFilter.getDescription()

save

public final void save(Project project,
                       File file)
                throws SaveException
Save a project to file.

This first archives the existing file, then calls doSave(...) to do the actual saving.

Should doSave(...) throw an exception then it is caught here and any rollback handled before rethrowing the exception.

Specified by:
save in interface ProjectFilePersister
Parameters:
project - The project being saved.
file - The file to which the save is taking place.
Throws:
SaveException - when anything goes wrong
See Also:
ProjectFilePersister.save( org.argouml.kernel.Project, java.io.File)

preSave

private void preSave(Project project,
                     File file)
              throws SaveException
Handle archiving of previous file or any other common requirements before saving a model to a file.

Parameters:
project - The project being saved.
file - The file to which the save is taking place.
Throws:
SaveException - when anything goes wrong

postSave

private void postSave(Project project,
                      File file)
               throws SaveException
Handle archiving on completion of a save such as renaming the temporary save file to the real filename.

Parameters:
project - The project being saved.
file - The file to which the save is taking place.
Throws:
SaveException - when anything goes wrong

doSave

protected abstract void doSave(Project project,
                               File file)
                        throws SaveException
Implement in your concrete class to save a project to a file.

There is no need to worry about archiving or restoring archive on failure, that is handled by the rest of the framework.

Parameters:
project - the project to save
file - The file to write.
Throws:
SaveException - when anything goes wrong
See Also:
save( org.argouml.kernel.Project, java.io.File)

doLoad

public abstract Project doLoad(File file)
                        throws OpenException
Specified by:
doLoad in interface ProjectFilePersister
Parameters:
file - the file of the project to load.
Returns:
the Project
Throws:
OpenException - when we fail to open from this url
See Also:
ProjectFilePersister.doLoad(java.io.File)

fireProgressEvent

protected void fireProgressEvent(long percent)
Inform listeners of any progress notifications.

Parameters:
percent - the current percentage progress.

addProgressListener

public void addProgressListener(ProgressListener listener)
Add any object interested in listening to persistence progress.

Parameters:
listener - the interested listener.

removeProgressListener

public void removeProgressListener(ProgressListener listener)
Remove any object no longer interested in listening to persistence progress.

Parameters:
listener - the listener to remove.


ArgoUML © 1996-2005ArgoUML HomepageArgoUML Developers' pageArgoUML Cookbook