org.jboss.virtual.plugins.copy
Class AbstractCopyMechanism

java.lang.Object
  extended by org.jboss.virtual.plugins.copy.AbstractCopyMechanism
All Implemented Interfaces:
CopyMechanism
Direct Known Subclasses:
ExactCopyMechanism, ExplodedCopyMechanism, UnjarCopyMechanism

public abstract class AbstractCopyMechanism
extends java.lang.Object
implements CopyMechanism

Copy mechanism to be used in VFSUtils.

Author:
Ales Justin

Constructor Summary
AbstractCopyMechanism()
           
 
Method Summary
protected  java.io.File copy(java.io.File guidDir, VirtualFileHandler handler)
          Copy handler.
 VirtualFile copy(VirtualFile file, VirtualFileHandler handler)
          Copy handler.
protected  java.io.File createCopy(java.io.File guidDir, VirtualFileHandler handler)
          Create copy destination.
protected static java.io.File createTempDirectory(java.io.File parent, java.lang.String name)
          Create the temp directory.
protected abstract  void doCopy(java.io.File copy, VirtualFileHandler handler)
          Do copy.
protected static void exactCopy(java.io.File copy, VirtualFileHandler root)
          Exact copy.
protected static void explode(java.io.File copy, VirtualFileHandler root)
          Explode the root into file.
static java.io.File getTempDirectory()
          Get temp directory.
protected abstract  java.lang.String getType()
          Get mechanism type.
protected abstract  boolean isAlreadyModified(VirtualFileHandler handler)
          Is handler already modified.
protected abstract  boolean replaceOldHandler(VirtualFileHandler parent, VirtualFileHandler oldHandler, VirtualFileHandler newHandler)
          Should we replace old handler with new.
protected static void rewrite(VirtualFileHandler handler, java.io.File file)
          Rewrite contents of handler into file.
protected static void unjar(java.io.File copy, VirtualFileHandler handler)
          Unjar to copy parameter.
protected static void unpack(java.io.File copy, VirtualFileHandler root, org.jboss.virtual.plugins.copy.AbstractCopyMechanism.WriteRootChecker checker)
          Unpack the root into file.
protected static VirtualFileHandler unwrap(VirtualFileHandler handler)
          Unwrap the handler from possible delegate handler.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractCopyMechanism

public AbstractCopyMechanism()
Method Detail

getTempDirectory

public static java.io.File getTempDirectory()
Get temp directory.

Returns:
the temp directory

getType

protected abstract java.lang.String getType()
Get mechanism type.

Returns:
the type

isAlreadyModified

protected abstract boolean isAlreadyModified(VirtualFileHandler handler)
                                      throws java.io.IOException
Is handler already modified.

Parameters:
handler - the handler
Returns:
true if already modified
Throws:
java.io.IOException - for any error

replaceOldHandler

protected abstract boolean replaceOldHandler(VirtualFileHandler parent,
                                             VirtualFileHandler oldHandler,
                                             VirtualFileHandler newHandler)
                                      throws java.io.IOException
Should we replace old handler with new.

Parameters:
parent - the parent handler
oldHandler - the old handler
newHandler - the new handler
Returns:
true if needs replacement
Throws:
java.io.IOException - for any error

unwrap

protected static VirtualFileHandler unwrap(VirtualFileHandler handler)
Unwrap the handler from possible delegate handler.

Parameters:
handler - the handler to unwrap
Returns:
unwrapped handler

copy

public VirtualFile copy(VirtualFile file,
                        VirtualFileHandler handler)
                 throws java.io.IOException,
                        java.net.URISyntaxException
Description copied from interface: CopyMechanism
Copy handler. If already modified, return handler's file.

Specified by:
copy in interface CopyMechanism
Parameters:
file - the original file
handler - the handler to copy
Returns:
handler's copy
Throws:
java.io.IOException - for any error
java.net.URISyntaxException - for any URI syntax error

copy

protected java.io.File copy(java.io.File guidDir,
                            VirtualFileHandler handler)
                     throws java.io.IOException
Copy handler.

Parameters:
guidDir - the guid directory
handler - the handler to copy
Returns:
handler's copy as file
Throws:
java.io.IOException - for any error

createCopy

protected java.io.File createCopy(java.io.File guidDir,
                                  VirtualFileHandler handler)
                           throws java.io.IOException
Create copy destination.

Parameters:
guidDir - the guid dir
handler - the handler to copy
Returns:
copy's destination
Throws:
java.io.IOException - for any error

doCopy

protected abstract void doCopy(java.io.File copy,
                               VirtualFileHandler handler)
                        throws java.io.IOException
Do copy.

Parameters:
copy - the copy destination
handler - the handler
Throws:
java.io.IOException - for any error

createTempDirectory

protected static java.io.File createTempDirectory(java.io.File parent,
                                                  java.lang.String name)
Create the temp directory.

Parameters:
parent - the parent
name - the dir name
Returns:
new directory

exactCopy

protected static void exactCopy(java.io.File copy,
                                VirtualFileHandler root)
                         throws java.io.IOException
Exact copy.

Parameters:
copy - the copy dest
root - the handler to copy
Throws:
java.io.IOException - for any error

explode

protected static void explode(java.io.File copy,
                              VirtualFileHandler root)
                       throws java.io.IOException
Explode the root into file.

Parameters:
copy - the copy dest
root - the root
Throws:
java.io.IOException - for any error

unpack

protected static void unpack(java.io.File copy,
                             VirtualFileHandler root,
                             org.jboss.virtual.plugins.copy.AbstractCopyMechanism.WriteRootChecker checker)
                      throws java.io.IOException
Unpack the root into file. Repeat this on the root's children.

Parameters:
copy - the copy dest
root - the root
checker - do we write the root checker
Throws:
java.io.IOException - for any error

unjar

protected static void unjar(java.io.File copy,
                            VirtualFileHandler handler)
                     throws java.io.IOException
Unjar to copy parameter.

Parameters:
copy - the dest to unjar
handler - the handler to unjar
Throws:
java.io.IOException - for any error

rewrite

protected static void rewrite(VirtualFileHandler handler,
                              java.io.File file)
                       throws java.io.IOException
Rewrite contents of handler into file.

Parameters:
handler - the handler
file - the file
Throws:
java.io.IOException - for any error