From: Stian Soiland-R. <st...@us...> - 2009-01-30 16:10:25
|
Update of /cvsroot/taverna/t2workbench/net.sf.taverna.t2.ui.ui-api/file-api/src/main/java/net/sf/taverna/t2/workbench/file In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv2820/file-api/src/main/java/net/sf/taverna/t2/workbench/file Added Files: Tag: t2workbench-platform AbstractDataflowPersistenceHandler.java DataflowInfo.java FileType.java FileManager.java DataflowPersistenceHandler.java Log Message: added File Manager --- NEW FILE: DataflowPersistenceHandler.java --- /******************************************************************************* * Copyright (C) 2007 The University of Manchester * * Modifications to the initial code base are copyright of their * respective authors, or their employers as appropriate. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 ******************************************************************************/ package net.sf.taverna.t2.workbench.file; import java.io.File; import java.net.URL; import java.util.Collection; import net.sf.taverna.t2.workbench.file.exceptions.OpenException; import net.sf.taverna.t2.workbench.file.exceptions.SaveException; import net.sf.taverna.t2.workflowmodel.Dataflow; /** * An SPI for handling of opening or saving dataflows from * the {@link FileManager}. * <p> * </p> * * @author Stian Soiland-Reyes * */ public interface DataflowPersistenceHandler { /** * A collection of supported file types for * {@link #openDataflow(FileType, Object)}, or an empty collection if * opening is not supported by this handler. * * @return A collection of supported {@link FileType}s for opening. */ public Collection<FileType> getOpenFileTypes(); /** * A collection of supported source classes for * {@link #openDataflow(FileType, Object)}, or an empty collection if * opening is not supported by this handler. * <p> * For example, a handler that supports sources opened from a {@link File} * and {@link URL} could return * <code>Arrays.asList(File.class, URL.class)</code> * * @return A collection of supported {@link Class}es of the open source * types. */ public Collection<Class<?>> getOpenSourceTypes(); /** * A collection of supported destination classes for * {@link #saveDataflow(Dataflow, FileType, Object)}, or an empty collection * if saving is not supported by this handler. * <p> * For example, a handler that supports saving to destinations that are * instances of a {@link File} could return * <code>Arrays.asList(File.class)</code> * * @return A collection of supported {{@link Class}es of the save * destination types. */ public Collection<Class<?>> getSaveDestinationTypes(); /** * A collection of supported file types for * {@link #saveDataflow(Dataflow, FileType, Object)}, or an empty collection * if saving is not supported by this handler. * * @return A collection of supported {@link FileType}s for saving. */ public Collection<FileType> getSaveFileTypes(); /** * Open a dataflow from a source containing a dataflow of the given * {@link FileType}. * <p> * The {@link FileType} will be equal to one of the types from * {@link #getOpenFileTypes()}, and the source class will be one that is * assignable to one of the classes from {@link #getOpenSourceTypes()}. * * @param fileType * {@link FileType} determining which serialisation method has * been used * @param source * Source for reading the Dataflow * @return {@link DataflowInfo} describing the opened dataflow, including * the dataflow itself * @throws OpenException * If the dataflow could not be read, parsed or opened for any * reason. */ public DataflowInfo openDataflow(FileType fileType, Object source) throws OpenException; /** * Save a dataflow to a destination of the given {@link FileType}. * <p> * The {@link FileType} will be equal to one of the types from * {@link #getSaveFileTypes()}, and the destination class will be one that * is assignable to one of the classes from * {@link #getSaveDestinationTypes()}. * * @param dataflow * {@link Dataflow} to be saved * @param fileType * {@link FileType} determining which serialisation method to use * @param destination * Destination for writing the Dataflow * @return {@link DataflowInfo} describing the saved dataflow, including the * dataflow itself * @throws OpenException * If the dataflow could not be read, parsed or opened for any * reason. */ public DataflowInfo saveDataflow(Dataflow dataflow, FileType fileType, Object destination) throws SaveException; /** * Return <code>true</code> if a call to * {@link #saveDataflow(Dataflow, FileType, Object)} would overwrite the * destination, and the destination is different from last * {@link #openDataflow(FileType, Object)} or * {@link #saveDataflow(Dataflow, FileType, Object)} of the given dataflow. * * @param dataflow * {@link Dataflow} that is to be saved * @param fileType * {@link FileType} for saving dataflow * @param destination * destination for writing dataflow * @param lastDataflowInfo * last provided {@link DataflowInfo} returned by * {@link #openDataflow(FileType, Object)} or * {@link #saveDataflow(Dataflow, FileType, Object)}. (but not * necessarily from this handler) * @return <code>true</code> if the save would overwrite */ public boolean wouldOverwriteDataflow(Dataflow dataflow, FileType fileType, Object destination, DataflowInfo lastDataflowInfo); } --- NEW FILE: DataflowInfo.java --- /******************************************************************************* * Copyright (C) 2007 The University of Manchester * * Modifications to the initial code base are copyright of their * respective authors, or their employers as appropriate. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 ******************************************************************************/ package net.sf.taverna.t2.workbench.file; import java.util.Date; import net.sf.taverna.t2.workflowmodel.Dataflow; /** * Information about a dataflow that has been opened by the {@link FileManager}. * <p> * This class, or a subclass of it, is used by * {@link DataflowPersistenceHandler}s to keep information about where a * dataflow came from or where it was saved to. * </p> * * @author Stian Soiland-Reyes * */ public class DataflowInfo { private final FileType fileType; private final Dataflow dataflow; private final Date lastModified; private final Object canonicalSource; public DataflowInfo(FileType fileType, Object canonicalSource, Dataflow dataflow, Date lastModified) { this.fileType = fileType; this.canonicalSource = canonicalSource; this.dataflow = dataflow; this.lastModified = lastModified; } public DataflowInfo(FileType fileType, Object canonicalSource, Dataflow dataflow) { this(fileType, canonicalSource, dataflow, null); } /** * Return the canonical source of where the dataflow was opened from or * saved to. * <p> * This is not necessarily the source provided to * {@link FileManager#openDataflow(FileType, Object)} or * {@link FileManager#saveDataflow(Dataflow, FileType, Object, boolean)}, * but it's canonical version. * </p> * <p> * For instance, if a dataflow was opened from a * File("relative/something.t2flow") this canonical source would resolve the * relative path. * </p> * * @return */ public Object getCanonicalSource() { return canonicalSource; } /** * Return the dataflow that is open. * * @return The open dataflow */ public Dataflow getDataflow() { return dataflow; } /** * Get the last modified {@link Date} of the source at the time when it was * opened/saved. * <p> * It is important that this value is checked on creation time, and not on * demand. * </p> * * @return The {@link Date} of the source/destination's last modified * timestamp, or <code>null</code> if unknown. */ public Date getLastModified() { return lastModified; } /** * The {@link FileType} of this {@link Dataflow} serialisation used for * opening/saving. * * @return The {@link FileType}, for instance * {@link net.sf.taverna.t2.workbench.file.impl.T2FlowFileType} */ public FileType getFileType() { return fileType; } } --- NEW FILE: FileManager.java --- /******************************************************************************* * Copyright (C) 2007-2009 The University of Manchester * * Modifications to the initial code base are copyright of their * respective authors, or their employers as appropriate. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 ******************************************************************************/ package net.sf.taverna.t2.workbench.file; import java.io.File; import java.net.URL; import java.util.List; import javax.swing.filechooser.FileFilter; import net.sf.taverna.t2.lang.observer.Observable; import net.sf.taverna.t2.lang.observer.Observer; import net.sf.taverna.t2.workbench.file.events.ClosedDataflowEvent; import net.sf.taverna.t2.workbench.file.events.FileManagerEvent; import net.sf.taverna.t2.workbench.file.events.OpenedDataflowEvent; import net.sf.taverna.t2.workbench.file.events.SavedDataflowEvent; import net.sf.taverna.t2.workbench.file.events.SetCurrentDataflowEvent; import net.sf.taverna.t2.workbench.file.exceptions.OpenException; import net.sf.taverna.t2.workbench.file.exceptions.OverwriteException; import net.sf.taverna.t2.workbench.file.exceptions.SaveException; import net.sf.taverna.t2.workbench.file.exceptions.UnsavedException; import net.sf.taverna.t2.workflowmodel.Dataflow; /** * Manager of open files (Dataflows) in the workbench. * <p> * A {@link Dataflow} can be opened for the workbench using * {@link #openDataflow(FileType, Object)} or {@link #openDataflow(Dataflow)}. * {@link Observer}s of the FileManager gets notified with an * {@link OpenedDataflowEvent}. The opened workflow is also * {@link #setCurrentDataflow(Dataflow) made the current dataflow}, available * through {@link #getCurrentDataflow()} or by observing the * {@link net.sf.taverna.t2.lang.ui.ModelMap} for the model name * {@link net.sf.taverna.t2.workbench.ModelMapConstants#CURRENT_DATAFLOW}. * </p> * <p> * A dataflow can be saved using * {@link #saveDataflow(Dataflow, FileType, Object, boolean)}. Observers will be * presented a {@link SavedDataflowEvent}. * </p> * <p> * If a dataflow was previously opened from a saveable destination or previously * saved using {@link #saveDataflow(Dataflow, FileType, Object, boolean) * * {@link #saveDataflow(Dataflow, boolean)} can be used to resave to that * destination. * </p> * <p> * You can get the last opened/saved source and type using * {@link #getDataflowSource(Dataflow)} and {@link #getDataflowType(Dataflow)}. * </p> * <p> * If the save methods are used with failOnOverwrite=true, an * {@link OverwriteException} will be thrown if the destination file already * exists and was not last written by a previous save on that dataflow. (This is * typically checked using timestamps on the file). * </p> * <p> * A dataflow can be closed using {@link #closeDataflow(Dataflow, boolean)}. A * closed dataflow is no longer monitored for changes and can no longer be used * with the other operations, except {@link #openDataflow(Dataflow)}. * </p> * <p> * If a dataflow has been changed using the * {@link net.sf.taverna.t2.workbench.edits.EditManager}, * {@link #isDataflowChanged(Dataflow)} will return true until the next save. If * the close methods are used with failOnUnsaved=true, an * {@link UnsavedException} will be thrown if the dataflow has been changed. * </p> * <p> * The implementation of this FileManager can be discovered using * {@link #getInstance()}. * </p> * * @author Stian Soiland-Reyes * */ public interface FileManager extends Observable<FileManagerEvent> { /** * True if {@link #saveDataflow(Dataflow, boolean)} can save the workflow, * ie. that there exists an SPI implementation of * {@link DataflowPersistenceHandler} that can save to * {@link #getDataflowSource(Dataflow)} using * {@link #getDataflowType(Dataflow)}. * * @see #saveDataflow(Dataflow, boolean) * @param dataflow * The dataflow to check * @return <code>true</code> if the given dataflow can be saved without * providing a destination and filetype */ public boolean canSaveWithoutDestination(Dataflow dataflow); /** * Close the specified dataflow. * <p> * A closed dataflow can no longer be used with the save methods, and will * disappear from the UI's list of open dataflows. * </p> * <p> * If no more dataflows would be open after the close, a new empty dataflow * is opened as through {@link #newDataflow()}. * </p> * <p> * If the failOnUnsaved parameters is <code>true</code>, and * {@link #isDataflowChanged(Dataflow)} is <code>true</code>, an * {@link UnsavedException} will be thrown, typically because the workflow * has been changed using the {@link EditManager} since the last change. * </p> * <p> * Listeners registered using {@link Observable#addObserver(Observer)} will * be notified with an {@link ClosedDataflowEvent}. * </p> * * @param dataflow * {@link Dataflow} to close * @param failOnUnsaved * If <code>true</code>, fail on unsaved changes * @throws UnsavedException * If failOnUnsaved was <code>true</code> and there has been * changes to the dataflow since the last save */ public void closeDataflow(Dataflow dataflow, boolean failOnUnsaved) throws UnsavedException; /** * Get the current dataflow. * <p> * The current workflow is typically the one currently showed on the screen, * and is also in {@link #getOpenDataflows()}. * </p> * <p> * The current dataflow is set through {@link #setCurrentDataflow(Dataflow)} * or the {@link net.sf.taverna.t2.lang.ui.ModelMap} using the key * {@link net.sf.taverna.t2.workbench.ModelMapConstants#CURRENT_DATAFLOW}. * </p> * * @return The current dataflow, or <code>null</code> if no dataflow is * current */ public Dataflow getCurrentDataflow(); /** * Get the dataflow that was opened from or last saved to the given source. * * @param source * The source as opened with or saved to * {@link #openDataflow(FileType, Object)} * @return The opened {@link Dataflow} or <code>null</code> if no matching * dataflow found. */ public Dataflow getDataflowBySource(Object source); /** * Get the last opened/saved source/destination for the given dataflow. * <p> * The source is the last source used with * {@link #saveDataflow(Dataflow, FileType, Object, boolean)} for the given * dataflow, or {@link #openDataflow(FileType, Object)} if it has not yet * been saved. * <p> * If the given dataflow's last opened/saved location was unknown (opened * with {@link #newDataflow()} or {@link #openDataflow(Dataflow)}), return * <code>null</code>. * </p> * * @param dataflow * {@link Dataflow} which file is to be returned * @return The last opened/saved source for the given dataflow, or * <code>null</code> if unknown. */ public Object getDataflowSource(Dataflow dataflow); /** * Get the last opened/saved source/destination FileType for the given * dataflow. * <p> * The type is the last {@link FileType} used with * {@link #saveDataflow(Dataflow, FileType, Object, boolean)} for the given * dataflow, or {@link #openDataflow(FileType, Object)} if it has not yet * been saved. * <p> * If the given dataflow's last opened/saved file type was unknown (opened * with {@link #newDataflow()} or {@link #openDataflow(Dataflow)}), return * <code>null</code>. * </p> * * @param dataflow * {@link Dataflow} which file is to be returned * @return The last opened/saved {@link FileType} for the given dataflow, or * <code>null</code> if unknown. */ public FileType getDataflowType(Dataflow dataflow); /** * Get the list of currently open dataflows. This list of dataflows are * typically displayed in the UI in the "Workflows" menu to allow switching * the {@link #getCurrentDataflow() current dataflow}. * * @return A copy of the {@link List} of open {@link Dataflow}s */ public List<Dataflow> getOpenDataflows(); /** * Get a list of {@link FileFilter}s for supported {@link FileType}s that * can be opened with any source class. * * @return A {@link List} of {@link FileFilter}s supported by * {@link #openDataflow(FileType, Object)} */ public List<FileFilter> getOpenFileFilters(); /** * Get a list of {@link FileFilter}s for supported {@link FileType}s that * can be opened with given source class. * * @param sourceClass * Source class that can be opened from * @return A {@link List} of {@link FileFilter}s supported by * {@link #openDataflow(FileType, Object)} */ public List<FileFilter> getOpenFileFilters(Class<?> sourceClass); /** * Get a list of {@link FileFilter}s for supported {@link FileType}s that * can be saved to any destination class. * * @return A {@link List} of {@link FileFilter}s supported by * {@link #saveDataflow(Dataflow, FileType, Object, boolean) */ public List<FileFilter> getSaveFileFilters(); /** * Get a list of {@link FileFilter}s for supported {@link FileType}s that * can be saved to the given destination class. * * @param destinationClass * Destination class that can be saved to * @return A {@link List} of {@link FileFilter}s supported by * {@link #saveDataflow(Dataflow, FileType, Object, boolean) */ public List<FileFilter> getSaveFileFilters(Class<?> destinationClass); /** * Return <code>true</code> if the dataflow has been changed (through the * {@link EditManager} or {@link #setDataflowChanged(Dataflow, boolean)}) * since last save. * * @param dataflow * Dataflow which changed status is to be checked * @return <code>true</code> if the dataflow has been changed since last * save. */ public boolean isDataflowChanged(Dataflow dataflow); /** * True if the given dataflow has been opened and is in * {@link #getOpenDataflows()}. * * @param dataflow * Dataflow to check * @return <code>true</code> if dataflow is open */ public boolean isDataflowOpen(Dataflow dataflow); /** * Create and open a new, blank dataflow. The dataflow will not initially be * marked as changed. * <p> * Listeners registered using {@link Observable#addObserver(Observer)} will * be notified with an {@link OpenedDataflowEvent}. * </p> * <p> * Note, if the dataflow is later changed, it will not be possible to save * it to any original location using * {@link #saveDataflow(Dataflow, boolean)}, only * {@link #saveDataflow(Dataflow, FileType, Object, boolean)}. * </p> * * @return The newly opened blank {@link Dataflow} */ public Dataflow newDataflow(); /** * Open a {@link Dataflow} instance that has been created outside the * {@link FileManager}. The dataflow will not initially be marked as * changed. * <p> * Listeners registered using {@link Observable#addObserver(Observer)} will * be notified with an {@link OpenedDataflowEvent}. * </p> * <p> * Note, if the dataflow is later changed, it will not be possible to save * it to its original location using * {@link #saveDataflow(Dataflow, boolean)}, only * {@link #saveDataflow(Dataflow, FileType, Object, boolean)}. * </p> * <p> * Instead of using this option it is recommended to create your own * {@link FileType} and/or source type and a * {@link DataflowPersistenceHandler} to implement save and/or reopen * (revert). * <p> * If there is only one workflow open before opening this workflow, and it * is an unchanged blank workflow, the blank workflow will be closed. * </p> * * @param dataflow * {@link Dataflow} instance that is to be added as an open * dataflow */ public void openDataflow(Dataflow dataflow); /** * Open a dataflow from a source. The dataflow will not initially be marked * as changed. * <p> * The file manager will find implementations of the SPI * {@link DataflowPersistenceHandler} to perform the save for the given file * type and destination class. * </p> * <p> * Listeners registered using {@link Observable#addObserver(Observer)} will * be notified with an {@link OpenedDataflowEvent}. * </p> * <p> * If there is only one workflow open before opening this workflow, and it * is an unchanged blank workflow, the blank workflow will be closed. * </p> * * @param fileType * The filetype, for instance * {@link net.sf.taverna.t2.workbench.file.impl.T2FlowFileType}. * The file type must be supported by an implementation of the * SPI DataflowPersistenceHandler. * @param source * The source, for instance a {@link File} or {@link URL}. The * source type must be supported by an implementation of * DataflowPersistenceHandler. * * @return The opened {@link Dataflow}. * @throws OpenException * If there was no matching DataflowPersistenceHandler found or * the source could not be opened for any other reason, such as * IO errors or syntax errors. */ public Dataflow openDataflow(FileType fileType, Object source) throws OpenException; /** * Save the dataflow to the last saved destination and FileType from * {@link #saveDataflow(Dataflow, FileType, Object, boolean)} or the last * opened source and FileType from {@link #openDataflow(FileType, Object)}. * </p> * <p> * Listeners registered using {@link Observable#addObserver(Observer)} will * be notified with an {@link SavedDataflowEvent}. * </p> * * @param dataflow * Dataflow to save. Dataflow must have been opened with * {@link #openDataflow(FileType, Object)} or saved using * {@link #saveDataflow(Dataflow, FileType, Object, boolean)}. * @param failOnOverwrite * If <code>true</code>, an {@link OverwriteException} is thrown * if a save would overwrite the destination because it has been * changed since last open/save. * @throws OverwriteException * if failOnOverwrite was true, and a save would overwrite the * destination because it has been changed since last open/save. * The save was not performed. * @throws SaveException * If any other error occurs during saving, including the case * that a dataflow is not connected to a source or destination, * that there are no handlers (some source types can't be saved * to, such as HTTP URLs), or any other IO error occurring while * saving. */ public void saveDataflow(Dataflow dataflow, boolean failOnOverwrite) throws SaveException, OverwriteException; /** * Save the dataflow to the given destination using the given filetype. * <p> * The file manager will find implementations of the SPI * {@link DataflowPersistenceHandler} to perform the save for the given file * type and destination class. * </p> * <p> * Listeners registered using {@link Observable#addObserver(Observer)} will * be notified with an {@link SavedDataflowEvent}. * </p> * * @param dataflow * {@link Dataflow} to be saved * @param fileType * {@link FileType} to save dataflow as, for instance * {@link net.sf.taverna.t2.workbench.file.impl.T2FlowFileType}. * The file type must be supported by an SPI implementation of * {@link DataflowPersistenceHandler}. * @param destination * Destination to save dataflow to, for instance a {@link File} * @param failOnOverwrite * If <code>true</code>, an {@link OverwriteException} is thrown * if a save would overwrite the destination because it already * exists, but was not opened or save to using the file manager * for the given dataflow. (ie. a repeated call to this function * should not throw an OverwriteException unless someone outside * has modified the file) * @throws OverwriteException * if failOnOverwrite was true, and a save would overwrite the * destination because it already existed, and was not last * written to by a previous save. The save was not performed. * @throws SaveException * If any other error occurs during saving, including the case * that a dataflow is not connected to a source or destination, * that there are no handlers (some source types can't be saved * to, such as HTTP URLs), or any other IO error occurring while * saving. */ public void saveDataflow(Dataflow dataflow, FileType fileType, Object destination, boolean failOnOverwrite) throws SaveException, OverwriteException; /** * Set the current dataflow to the one provided. * <p> * The current dataflow can be retrieved using {@link #getCurrentDataflow()} * . Note that opening a dataflow will normally also set it as the current * dataflow. * </p> * <p> * Listeners registered using {@link Observable#addObserver(Observer)} will * be notified with an {@link SetCurrentDataflowEvent}. * </p> * <p> * Note, the dataflow must already be open. If this is not the case, use one * of the openDataflow() methods or * {@link #setCurrentDataflow(Dataflow, boolean)}. * * @see #setCurrentDataflow(Dataflow, boolean) * @param dataflow * {@link Dataflow} to be made current */ public void setCurrentDataflow(Dataflow dataflow); /** * Set the current dataflow to the one provided. * <p> * The current dataflow can be retrieved using {@link #getCurrentDataflow()} * . Note that opening a dataflow will normally also set it as the current * dataflow. * </p> * <p> * Listeners registered using {@link Observable#addObserver(Observer)} will * be notified with an {@link SetCurrentDataflowEvent}. * </p> * <p> * Unless <code>openIfNeeded</code> is <code>true</code>, the dataflow must * already be open. * * @see #setCurrentDataflow(Dataflow, boolean) * @param dataflow * {@link Dataflow} to be made current * @param openIfNeeded * If <code>true</code>, open the dataflow if needed */ public void setCurrentDataflow(Dataflow dataflow, boolean openIfNeeded); /** * Set a dataflow as changed or not. This changes the value returned by * {@link #isDataflowChanged(Dataflow)}. * <p> * This method can be used if the dataflow has been changed outside the * {@link EditManager}. * </p> * * @param dataflow * Dataflow which is to be marked * @param isChanged * <code>true</code> if the dataflow is to be marked as changed, * <code>false</code> if it is to be marked as not changed. */ public void setDataflowChanged(Dataflow dataflow, boolean isChanged); /** * Returns the canonical form of the source where the dataflow was opened * from or saved to. The code for this method was devised based on * {@link net.sf.taverna.t2.workbench.file.impl.T2DataflowOpener#openDataflow(FileType fileType, Object source)} * . */ public Object getCanonical(Object source); } --- NEW FILE: FileType.java --- /******************************************************************************* * Copyright (C) 2007 The University of Manchester * * Modifications to the initial code base are copyright of their * respective authors, or their employers as appropriate. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 ******************************************************************************/ package net.sf.taverna.t2.workbench.file; import net.sf.taverna.t2.workflowmodel.Dataflow; /** * A filetype to identify a way to (de)serialise a {@link Dataflow} with the * {@link FileManager}. * <p> * Two filetypes are considered equal if they share an extension or mime type or * are the same instance. * </p> * * @see net.sf.taverna.t2.workbench.file.impl.T2FlowFileType * @author Stian Soiland-Reyes * */ public abstract class FileType { public abstract String getExtension(); public abstract String getMimeType(); public abstract String getDescription(); /** * {@inheritDoc} */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof FileType)) { return false; } FileType other = (FileType) obj; if (getMimeType() != null && other.getMimeType() != null) { return getMimeType().equalsIgnoreCase(other.getMimeType()); } if (getExtension() != null && other.getExtension() != null) { return getExtension().equalsIgnoreCase(other.getExtension()); } return false; } /** * {@inheritDoc} */ @Override public int hashCode() { int hash = 7; hash = 31 * hash + getExtension().hashCode(); hash = 31 * hash + getMimeType().hashCode(); return hash; } } --- NEW FILE: AbstractDataflowPersistenceHandler.java --- /******************************************************************************* * Copyright (C) 2007 The University of Manchester * * Modifications to the initial code base are copyright of their * respective authors, or their employers as appropriate. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 ******************************************************************************/ package net.sf.taverna.t2.workbench.file; import java.util.Collections; import java.util.List; import net.sf.taverna.t2.workbench.file.exceptions.OpenException; import net.sf.taverna.t2.workbench.file.exceptions.SaveException; import net.sf.taverna.t2.workflowmodel.Dataflow; public abstract class AbstractDataflowPersistenceHandler implements DataflowPersistenceHandler { public List<FileType> getOpenFileTypes() { return Collections.emptyList(); } public List<FileType> getSaveFileTypes() { return Collections.emptyList(); } public List<Class<?>> getOpenSourceTypes() { return Collections.emptyList(); } public List<Class<?>> getSaveDestinationTypes() { return Collections.emptyList(); } public DataflowInfo openDataflow(FileType fileType, Object source) throws OpenException { throw new UnsupportedOperationException(); } public DataflowInfo saveDataflow(Dataflow dataflow, FileType fileType, Object destination) throws SaveException { throw new UnsupportedOperationException(); } public boolean wouldOverwriteDataflow(Dataflow dataflow, FileType fileType, Object destination, DataflowInfo lastDataflowInfo) { throw new UnsupportedOperationException(); } } |