FileDocCategorySizeDatePackage
DeploymentFileRepository.javaAPI DocJBoss 4.2.15375Fri Jul 13 21:02:16 BST 2007org.jboss.console.manager

DeploymentFileRepository

public class DeploymentFileRepository extends org.jboss.system.ServiceMBeanSupport implements DeploymentFileRepositoryMBean
This class wraps the file system for deployments. It gives a file-based persistence mechanism for deployments. Used by web-console to store -service.xml files, -ds.xml files, etc..., really anything text based. Deployments are tied to a specific name and that name corresponds to the base file name.
author
Bill Burke
author
Dimitris Andreadis
version
$Revision: 58459 $

Fields Summary
private String
baseDir
private File
base
protected File
serverHome
The server's home directory, for relative paths.
Constructors Summary
Methods Summary
public java.lang.StringgetBaseDir()

      return baseDir;
   
private java.io.FilegetFile(java.io.File parent, java.lang.String child)
Wrap the File(File parent, String child) CTOR to make sure the resulting child is indeed under the parent hierarchy, i.e. don't allow a ../../../rogue-child.txt see JBAS-3861

      File childFile = new File(parent, child);
      
      if (childFile.getCanonicalPath().indexOf(parent.getCanonicalPath()) != 0)
         throw new IllegalArgumentException("child '" + child + "' should be a child of parent '" + parent + "'");
      
      return childFile;
   
public booleanisStored(java.lang.String folder, java.lang.String name, java.lang.String fileExtension)

      File dir = getFile(base, folder);
      String filename = name.replace(' ", '_") + fileExtension;
      File file = getFile(dir, filename);
      return file.exists();
   
public javax.management.ObjectNamepreRegister(javax.management.MBeanServer server, javax.management.ObjectName name)

      // get server's home for relative paths, need this for setting
      // attribute final values, so we need to do it here
      ServerConfig serverConfig = ServerConfigLocator.locate();
      serverHome = serverConfig.getServerHomeDir();
      return super.preRegister(server, name);
   
public voidremove(java.lang.String folder, java.lang.String name, java.lang.String fileExtension)

      File dir = getFile(base, folder);
      String filename = name.replace(' ", '_") + fileExtension;
      File file = getFile(dir, filename);
      file.delete();
   
public voidsetBaseDir(java.lang.String baseDir)

      this.base = getFile(serverHome, baseDir);      
      this.baseDir = baseDir;
      
      log.debug("BaseDir set to: " + this.base);
   
public voidstore(java.lang.String folder, java.lang.String name, java.lang.String fileExtension, java.lang.String data, boolean noHotDeploy)

param
folder relative directory
param
name base name of file. Whitespace will be removed from name and replaced with '_'
param
fileExtension must have a '.' in ext
param
data
param
noHotDeploy keep timestamp of file so it doesn't do a redeploy
throws
IOException

      log.debug("store called");
      File dir = getFile(base, folder);
      log.debug("repository folder: " + dir.toString());
      log.debug("absolute: " + dir.getAbsolutePath());
      if (!dir.exists())
      {
         if (!dir.mkdirs())
         {
            throw new RuntimeException("Failed to create directory: " + dir.toString());
         }
      }
      String filename = name.replace(' ", '_") + fileExtension;
      File file = getFile(dir, filename);
      
      File tmpfile = new File(dir, filename + ".tmp");
      PrintWriter writer = new PrintWriter(new FileOutputStream(tmpfile));
      writer.write(data);
      writer.close();
      
      if (file.exists() && noHotDeploy)
      {
         long modified = file.lastModified();
         tmpfile.setLastModified(modified);
         file.delete();
      }
      if (!tmpfile.renameTo(file))
      {
         throw new RuntimeException("Failed to rename tmpfile to " + file.toString());
      }