KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ixenon > free > nodes > SimpleCopyFile


1 /* $Id$
2  *
3  * Copyright (c) 1999 Xenonsoft Limited. All Rights Reserved.
4  *
5  * This software is protected by copyright. You are hereby notified from
6  * now by reading this message. This software is also the confidential
7  * and proprietary information of Xenonsoft Limited. ("Confidential
8  * Information").
9  *
10  * This software is distributed under the Xenonsoft Public end user
11  * License ("XPeL"), where the machine-readable source code is provided
12  * under the "Open Source" model.
13  * For more information, please read the file "LICENSE-XPL.txt"
14  */

15
16 //
17
// DESCRIPTION
18
//
19
// Peter Pilgrim
20
// Sun Jan 17 22:01:06 GMT 1999
21
//
22
// RCS HEADER ``InstallFilterFile.java''
23
//
24
// $Author$
25
// $Date$
26
// $Source$
27
// $Revision$ $State$ $Locker$
28
//
29

30 package ixenon.free.nodes;
31
32 import java.io.*;
33 import java.util.*;
34 import java.awt.*;
35 import java.awt.event.*;
36
37 import javax.swing.*; // for JTree
38
import javax.swing.event.*; // for events
39
import javax.swing.tree.*; // MutableTreeNode
40

41 import ixenon.free.swing.*; // for `ResetProgressBar' & `UpdateProgressBar'
42
import ixenon.free.install.*; // for FreeInstallerApplication
43

44 /**
45  * An <code>Installable</code> tree node that simply copy a source file
46  * to a target file.
47  */

48 public class SimpleCopyFile extends AbstractInstallable
49 implements Installable
50 {
51     /** the source directory */
52     protected File sourceFile;
53     /** the target directory */
54     protected File targetFile;
55     /** the permissions */
56     protected int perms;
57
58     /**
59      * Construct a installable
60      *
61      * @param nodeName the name of the installable node
62      * @param srcDir the source directory
63      * @param destDir the target directory
64      * @param filenameFilter the filename filter object
65      */

66     public SimpleCopyFile( String JavaDoc nodeName,
67                int perms,
68                String JavaDoc sourceFile,
69                String JavaDoc targetFile )
70     {
71     this( nodeName, perms, new File(sourceFile), new File(targetFile) );
72     }
73
74     /**
75      * Construct a installable
76      *
77      * @param nodeName the name of the installable node
78      * @param srcDir the source directory
79      * @param destDir the target directory
80      * @param filenameFilter the filename filter object
81      */

82     public SimpleCopyFile( String JavaDoc nodeName,
83                int perms,
84                File sourceFile,
85                File targetFile )
86     {
87     super( nodeName, null, true /*allowsChildren*/ );
88     this.sourceFile = sourceFile;
89     this.targetFile = targetFile;
90     this.perms = perms;
91     }
92     
93     /**
94      * create or retrieve the visual component of the installable
95      * if one exists. Otherwise return null.
96      */

97     public Component getVisualComponent()
98     {
99     return (null);
100     }
101     
102     /**
103      * create or retrieve the configurable component of the installable
104      * if one exists. Otherwise return null object.
105      */

106     public Component getConfigurableComponent()
107     {
108     return (null);
109     }
110
111
112     /**
113      * method to install by copy a source files to target file
114      *
115      * @exception <code>InstallException</code> if there is an
116      * problem trying to install the entity.
117      */

118     public void install() throws InstallException
119     {
120     FreeInstallerApplication theApp =
121         FreeInstallerApplication.getInstance();
122
123     JProgressBar pbarFile = theApp.getProgressFrame().getProgressBarFile();
124
125     if ( !sourceFile.exists() )
126         throw new InstallException("no such file:`"+sourceFile.getAbsolutePath()+"'" );
127     if ( sourceFile.isDirectory() )
128         throw new InstallException("cannot copy a directory:`"+sourceFile.getAbsolutePath()+"'" );
129     if ( targetFile.isDirectory() )
130         throw new InstallException("cannot copy a directory:`"+targetFile.getAbsolutePath()+"'" );
131
132     theApp.printInfo( "simple file copy:`" + sourceFile.getPath() + "' to `" + targetFile.getPath()+"'" );
133     boolean status = InstallUtilities.copyFile(
134         pbarFile, sourceFile, targetFile, true );
135     if (status) {
136         InstallUtilities.setFilePermissions( targetFile, perms );
137
138         // Add target directory to the uninstallable
139
uninstallable.addFile( targetFile );
140     }
141     else {
142         theApp.printWarning( "failure to copy:`" + sourceFile.getPath() + "' to `" + targetFile.getPath()+"'" );
143         if (pedantic)
144         throw new InstallException( "failure to copy:`" + sourceFile.getPath() + "' to `" + targetFile.getPath()+"'" );
145     }
146     }
147
148     /**
149      * method to perform the cleanup of content if cancelled, or aborted
150      */

151     public void cleanup() throws InstallException
152     {
153     // empty
154
}
155     
156 }
157
Popular Tags