org.argouml.persistence
Class AbstractFilePersister

java.lang.Object
  extended by javax.swing.filechooser.FileFilter
      extended by org.argouml.persistence.AbstractFilePersister
All Implemented Interfaces:
ProjectFilePersister
Direct Known Subclasses:
UmlFilePersister

public abstract class AbstractFilePersister
extends javax.swing.filechooser.FileFilter
implements ProjectFilePersister

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


Constructor Summary
AbstractFilePersister()
           
 
Method Summary
 boolean accept(java.io.File f)
           
 void addProgressListener(ProgressListener listener)
          Add any object interested in listening to persistence progress.
protected  java.io.File copyFile(java.io.File src, java.io.File dest)
          Copies one file src to another, raising file exceptions if there are some problems.
protected  java.io.File createTempFile(java.io.File file)
          Create a temporary copy of the existing file.
abstract  Project doLoad(java.io.File file)
           
protected abstract  void doSave(Project project, java.io.File file)
          Implement in your concrete class to save a project to a file.
protected abstract  java.lang.String getDesc()
          Just the description, not the extension between "()".
 java.lang.String getDescription()
           
abstract  java.lang.String getExtension()
          The extension valid for this type of file.
protected  org.argouml.persistence.MemberFilePersister getMemberFilePersister(ProjectMember pm)
          Get a MemberFilePersister based on a given ProjectMember.
protected  org.argouml.persistence.MemberFilePersister getMemberFilePersister(java.lang.String tag)
          Get a MemberFilePersister based on a given tag.
abstract  boolean hasAnIcon()
          Returns true if a FileChooser should visualize an icon for the persister.
 boolean isFileExtensionApplicable(java.lang.String filename)
          Given the full filename this returns true if that filename contains the expected extension for the is persister.
 boolean isLoadEnabled()
          Some persisters only provide save functionality for deprecated formats.
 boolean isSaveEnabled()
          Some persisters only provide load functionality for discontinued formats but no save.
 void removeProgressListener(ProgressListener listener)
          Remove any object no longer interested in listening to persistence progress.
 void save(Project project, java.io.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
 

Constructor Detail

AbstractFilePersister

public AbstractFilePersister()
Method Detail

createTempFile

protected java.io.File createTempFile(java.io.File file)
                               throws java.io.FileNotFoundException,
                                      java.io.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:
java.io.FileNotFoundException - if file not found
java.io.IOException - if error reading or writing

copyFile

protected java.io.File copyFile(java.io.File src,
                                java.io.File dest)
                         throws java.io.FileNotFoundException,
                                java.io.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:
java.io.IOException - if there is some problems with the files.
java.io.FileNotFoundException - if any of the files cannot be found.

accept

public boolean accept(java.io.File f)
Specified by:
accept in class javax.swing.filechooser.FileFilter

getExtension

public abstract java.lang.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 java.lang.String getDesc()
Just the description, not the extension between "()".

Returns:
the description valid for this type of file

isFileExtensionApplicable

public boolean isFileExtensionApplicable(java.lang.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 java.lang.String getDescription()
Specified by:
getDescription in class javax.swing.filechooser.FileFilter

save

public final void save(Project project,
                       java.io.File file)
                throws SaveException,
                       java.lang.InterruptedException
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
java.lang.InterruptedException - if the thread is interrupted
See Also:
ProjectFilePersister.save( org.argouml.kernel.Project, java.io.File)

doSave

protected abstract void doSave(Project project,
                               java.io.File file)
                        throws SaveException,
                               java.lang.InterruptedException
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
java.lang.InterruptedException - if the thread is interrupted
See Also:
save( org.argouml.kernel.Project, java.io.File)

isSaveEnabled

public boolean isSaveEnabled()
Some persisters only provide load functionality for discontinued formats but no save. This method returns true by default. Those Peristers that do not provide save must override this.

Returns:
true if this persister is able to save

isLoadEnabled

public boolean isLoadEnabled()
Some persisters only provide save functionality for deprecated formats. Other persisters with the same extension will manage loading. This method returns true by default. Those Peristers that do not provide load must override this.

Returns:
true if this persister is able to load

doLoad

public abstract Project doLoad(java.io.File file)
                        throws OpenException,
                               java.lang.InterruptedException
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
java.lang.InterruptedException - if the thread is interrupted

addProgressListener

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

Specified by:
addProgressListener in interface ProjectFilePersister
Parameters:
listener - the interested listener.

removeProgressListener

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

Specified by:
removeProgressListener in interface ProjectFilePersister
Parameters:
listener - the listener to remove.

hasAnIcon

public abstract boolean hasAnIcon()
Returns true if a FileChooser should visualize an icon for the persister.

Returns:
true if the persister is associated to an icon

getMemberFilePersister

protected org.argouml.persistence.MemberFilePersister getMemberFilePersister(ProjectMember pm)
Get a MemberFilePersister based on a given ProjectMember.

Parameters:
pm - the project member
Returns:
the persister

getMemberFilePersister

protected org.argouml.persistence.MemberFilePersister getMemberFilePersister(java.lang.String tag)
Get a MemberFilePersister based on a given tag.

Parameters:
tag - The tag.
Returns:
the persister


ArgoUML © 1996-2006ArgoUML HomepageArgoUML Developers' pageArgoUML Cookbook