KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > standalone > ScriptedCommand


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.update.standalone;
12 import org.eclipse.core.runtime.*;
13 import org.eclipse.update.configuration.*;
14 import org.eclipse.update.core.*;
15 import org.eclipse.update.internal.core.*;
16 import org.eclipse.update.operations.*;
17
18 /**
19  * Parent class for all the update manager standalone commands.
20  * Subclasses will provide specific operations and the implementation of the run() method.
21  * <p>
22  * <b>Note:</b> This class/interface is part of an interim API that is still under development and expected to
23  * change significantly before reaching stability. It is being made available at this early stage to solicit feedback
24  * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken
25  * (repeatedly) as the API evolves.
26  * </p>
27  * @since 3.0
28  */

29 public abstract class ScriptedCommand implements IOperationListener {
30
31     private IInstallConfiguration config;
32     protected boolean verifyOnly;
33
34     /**
35      * Constructor
36      *
37      */

38     public ScriptedCommand() {
39         this(null);
40     }
41
42     /**
43      * Constructor.
44      *
45      * @param verifyOnly if true, the command is not executed, but will only attempt to run the command.
46      * This is mostly used when wanted to know if the command would fail.
47      */

48     public ScriptedCommand(String JavaDoc verifyOnly) {
49         this.verifyOnly = "true".equals(verifyOnly); //$NON-NLS-1$
50
}
51
52     /**
53      * @return true if the command should only be run in simulation mode,
54      * to verify if it can execute.
55      */

56     protected final boolean isVerifyOnly() {
57         return verifyOnly;
58     }
59
60     /**
61      * Convenience method that executes the command with a null progress monitor.
62      */

63     public final boolean run() {
64         return run(new NullProgressMonitor());
65     }
66     
67     /**
68      * Executes the command. Subclasses are responsible for implementing this method.
69      * If the command was constructed with verifyOnly=true, the command should not execute, but only verify it can execute.
70      * @param monitor progress monitor during command execution.
71      */

72     public abstract boolean run(IProgressMonitor monitor);
73
74     /**
75      * Applies the changes made to the current configuration.
76      */

77     public void applyChangesNow() {
78         OperationsManager.applyChangesNow();
79     }
80     
81     /* (non-Javadoc)
82      * @see org.eclipse.update.operations.IOperationListener#afterExecute(org.eclipse.update.operations.IOperation)
83      */

84     public boolean afterExecute(IOperation operation, Object JavaDoc data) {
85         return true;
86     }
87
88     /* (non-Javadoc)
89      * @see org.eclipse.update.operations.IOperationListener#beforeExecute(org.eclipse.update.operations.IOperation)
90      */

91     public boolean beforeExecute(IOperation operation, Object JavaDoc data) {
92         return true;
93     }
94
95     /**
96      * @return the installation configuration affected by the command
97      */

98     public final IInstallConfiguration getConfiguration() {
99         try {
100             ILocalSite localSite = SiteManager.getLocalSite();
101             config = localSite.getCurrentConfiguration();
102         } catch (CoreException e) {
103             StandaloneUpdateApplication.exceptionLogged();
104             UpdateCore.log(e);
105         }
106         return config;
107     }
108
109 }
110
Popular Tags