org.apache.cayenne.project
Class ProjectFile

java.lang.Object
  extended by org.apache.cayenne.project.ProjectFile
Direct Known Subclasses:
ApplicationProjectFile, DataMapFile, DataNodeFile

public abstract class ProjectFile
extends Object

ProjectFile is an adapter from an object in Cayenne project to its representation in the file system.


Field Summary
protected  String location
           
protected  Project projectObj
           
protected  File tempFile
           
 
Constructor Summary
ProjectFile()
           
ProjectFile(Project project, String location)
          Constructor for ProjectFile.
 
Method Summary
abstract  boolean canHandle(Object obj)
          Returns true if this file wrapper can handle a specified object.
 boolean canHandleObject()
          Returns true if this file wrapper can handle an internally stored object.
protected  void checkWritePermissions(File file)
           
 String getLocation()
          Builds a filename from the object name and "file suffix".
 String getLocationSuffix()
          Returns suffix to append to object name when creating a file name.
abstract  Object getObject()
          Returns a project object associated with this file.
abstract  String getObjectName()
          Returns a name of associated object, that is also used as a file name.
 String getOldLocation()
          Returns saved location of a file.
 Project getProject()
          Returns the project.
 boolean isRenamed()
           
 File resolveFile()
          Returns a file which is a canonical representation of the file to store a wrapped object.
 File resolveOldFile()
          Returns a file which is a canonical representation of the file to store a wrapped object.
abstract  void save(PrintWriter out)
          Saves an underlying object to the file.
 File saveCommit()
          Finishes saving the underlying object.
 void saveTemp()
          Saves ProjectFile's underlying object to a temporary file, returning this file to the caller.
 void saveUndo()
          Cleans up after unsuccessful or canceled save attempt.
 void synchronizeLocation()
          Replaces internally stored filename with the current object name.
protected  File tempFileForFile(File f)
          Creates a temporary file for the master file.
 String toString()
           
 void willSave()
          This method is called by project to let file know that it will be saved.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

location

protected String location

tempFile

protected File tempFile

projectObj

protected Project projectObj
Constructor Detail

ProjectFile

public ProjectFile()

ProjectFile

public ProjectFile(Project project,
                   String location)
Constructor for ProjectFile.

Method Detail

getLocation

public String getLocation()
Builds a filename from the object name and "file suffix".


getOldLocation

public String getOldLocation()
Returns saved location of a file.


getLocationSuffix

public String getLocationSuffix()
Returns suffix to append to object name when creating a file name. Default implementation returns empty string.


getObject

public abstract Object getObject()
Returns a project object associated with this file.


getObjectName

public abstract String getObjectName()
Returns a name of associated object, that is also used as a file name.


save

public abstract void save(PrintWriter out)
                   throws Exception
Saves an underlying object to the file. The procedure is dependent on the type of object and is implemented by concrete subclasses.

Throws:
Exception

canHandle

public abstract boolean canHandle(Object obj)
Returns true if this file wrapper can handle a specified object.


canHandleObject

public boolean canHandleObject()
Returns true if this file wrapper can handle an internally stored object.


synchronizeLocation

public void synchronizeLocation()
Replaces internally stored filename with the current object name.


willSave

public void willSave()
This method is called by project to let file know that it will be saved. Default implementation is a noop.


saveTemp

public void saveTemp()
              throws Exception
Saves ProjectFile's underlying object to a temporary file, returning this file to the caller. If any problems are encountered during saving, an Exception is thrown.

Throws:
Exception

resolveFile

public File resolveFile()
Returns a file which is a canonical representation of the file to store a wrapped object. If an object was renamed, the new name is returned.


resolveOldFile

public File resolveOldFile()
Returns a file which is a canonical representation of the file to store a wrapped object. If an object was renamed, the old name is returned. Returns null if this file has never been saved before.


saveCommit

public File saveCommit()
                throws ProjectException
Finishes saving the underlying object.

Throws:
ProjectException

saveUndo

public void saveUndo()
Cleans up after unsuccessful or canceled save attempt.


getProject

public Project getProject()
Returns the project.

Returns:
Project

isRenamed

public boolean isRenamed()

tempFileForFile

protected File tempFileForFile(File f)
                        throws IOException
Creates a temporary file for the master file.

Throws:
IOException

checkWritePermissions

protected void checkWritePermissions(File file)
                              throws IOException
Throws:
IOException

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2001-2011 Apache Cayenne. All Rights Reserved.