|
What this is
Other links
The source code/*
* Sun Public License Notice
*
* The contents of this file are subject to the Sun Public License
* Version 1.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://www.sun.com/
*
* The Original Code is NetBeans. The Initial Developer of the Original
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
* Microsystems, Inc. All Rights Reserved.
*/
package org.openide.loaders;
import java.beans.*;
import java.awt.event.*;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import org.openide.*;
import org.openide.ErrorManager.Annotation;
import org.openide.execution.*;
import org.openide.explorer.propertysheet.*;
import org.openide.filesystems.*;
import org.openide.cookies.ExecCookie;
import org.openide.cookies.ArgumentsCookie;
import org.openide.nodes.Sheet;
import org.openide.nodes.PropertySupport;
import org.openide.util.NbBundle;
import org.openide.util.Mutex;
import org.openide.util.Utilities;
import org.openide.util.Lookup;
/** Support for execution of a data object.
* @author Jaroslav Tulach, Jesse Glick
* @since 3.14
*/
public class ExecutionSupport extends Object
implements ExecCookie, ArgumentsCookie {
/** extended attribute for the type of executor */
private static final String EA_EXECUTOR = "NetBeansAttrExecutor"; // NOI18N
/** extended attribute for attributes */
private static final String EA_ARGUMENTS = "NetBeansAttrArguments"; // NOI18N
// copy from JavaNode
/** Name of property providing argument parameter list. */
public static final String PROP_FILE_PARAMS = "params"; // NOI18N
/** Name of property providing a custom {@link Executor} for a file. */
public static final String PROP_EXECUTION = "execution"; // NOI18N
/** entry to be associated with */
private MultiDataObject.Entry entry;
/** readOnlyAttrs is name of virtual attribute. This name of virtual attribute
* is shared between classes (and should be changed everywhere):
* - org.openide.filesystems.DefaultAttributes
* - org.openide.loaders.ExecutionSupport
* - org.openide.loaders.CompilerSupport
* - org.netbeans.core.ExJarFileSystem
*/
protected final static String READONLY_ATTRIBUTES = "readOnlyAttrs"; //NOI18N
/** Create new support for given entry. The file is taken from the
* entry and is updated if the entry moves or renames itself.
* @param entry entry to create instance from
*/
public ExecutionSupport (MultiDataObject.Entry entry) {
this.entry = entry;
}
/** Get the associated file that can be executed.
* @return the file that can be executed
*/
protected MultiDataObject.Entry getEntry() {
return entry;
}
/* Starts the class.
*/
public void start () {
Executor exec = getExecutor (entry);
if (exec == null) {
exec = defaultExecutor ();
}
try {
exec.execute(entry.getDataObject());
} catch (final IOException ex) {
Mutex.EVENT.readAccess (new Runnable () {
public void run () {
if (startFailed (ex)) {
// restart
ExecutionSupport.this.start ();
}
}
});
}
}
/** Called when invocation of the executor fails. Allows to do some
* modifications to the type of execution and try it again.
*
* @param ex exeception that occured during execution
* @return true if the execution should be restarted
*/
protected boolean startFailed (IOException ex) {
Executor orig = getExecutor(entry);
if (orig == null) { // #33078
orig = defaultExecutor();
}
Executor e = (Executor)choose(orig, Executor.class, ex);
if (e == null) {
return false;
} else {
try {
setExecutor (entry, e);
return true;
} catch (IOException exc) {
return false;
}
}
}
/** This method allows subclasses to override the default
* executor they want to use for debugging.
*
* @return current implementation returns Executor.getDefault ()
*/
protected Executor defaultExecutor () {
return Executor.getDefault ();
}
/** Set the executor for a given file object.
* Uses file attributes to store this information.
* @param entry entry to set the executor for
* @param exec executor to use
* @exception IOException if executor cannot be set
*/
public static void setExecutor (MultiDataObject.Entry entry, Executor exec) throws IOException {
entry.getFile ().setAttribute (EA_EXECUTOR,
exec == null ? null : new ServiceType.Handle (exec)
);
}
/** Get the executor for a given file object.
* @param entry entry to obtain the executor for
* @return executor associated with the file, or
|
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.