alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

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.debugger.*;
import org.openide.execution.*;
import org.openide.explorer.propertysheet.*;
import org.openide.filesystems.*;
import org.openide.cookies.DebuggerCookie;
import org.openide.nodes.Sheet;
import org.openide.nodes.PropertySupport;
import org.openide.util.NbBundle;
import org.openide.util.Mutex;
import org.openide.util.Lookup;

/** Support for execution and debugging.
* Use {@link org.openide.loaders.ExecutionSupport} unless you need support for debugging too.
*
* @deprecated Use new Debugger API (http://www.netbeans.org/download/dev/javadoc/).
* @author Jaroslav Tulach, Jesse Glick
*/
public class ExecSupport extends ExecutionSupport
    implements DebuggerCookie {
    /** extended attribute for debugger type */
    private static final String EA_DEBUGGER_TYPE = "NetBeansAttrDebuggerType"; // NOI18N

    /** Name of property providing a custom {@link DebuggerType} for a file. */
    public static final String PROP_DEBUGGER_TYPE     = "debuggerType"; // NOI18N

    /** @deprecated use {@link #getEntry} */
    protected MultiDataObject.Entry entry;
    /** @deprecated useless */
    protected boolean isReadOnly;

    /** 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 ExecSupport (MultiDataObject.Entry entry) {
        super(entry);
        this.entry = entry;
        Boolean ro = (Boolean)entry.getFile().getAttribute(READONLY_ATTRIBUTES);
        isReadOnly = (ro == null)?false:(!ro.booleanValue());
    }

    /* Start debugging of associated object.
    * @param stopOnMain if true, debugger stops on the first line of debugged code
    * @exception DebuggerException if the session cannot be started
    */
    public void debug (final boolean stopOnMain) throws DebuggerException {
        DebuggerType t = getDebuggerType (entry);
        if (t == null) {
            t = defaultDebuggerType ();
        }

        try {
            t.startDebugger (entry.getDataObject(), stopOnMain);
            // ok, debugger started
            return;
        } catch (final DebuggerException ex) {
            try {
                Mutex.EVENT.readAccess (new Mutex.ExceptionAction () {
                                            public Object run () throws DebuggerException {
                                                if (debugFailed (ex)) {
                                                    // restart
                                                    debug (stopOnMain);
                                                }
                                                return null;
                                            }
                                        });
            } catch (org.openide.util.MutexException mx) {
                if (mx.getException() instanceof DebuggerException) {
                    throw (DebuggerException)mx.getException();
                } else {
                    throw new DebuggerException(mx.getException());
                }
            }
        }
    }

    /** Check if this object is up to date or in need of compilation.
    * Should compile it if necessary.
    * 

The default implementation checks whether {@link CompilerCookie} is provided and * if so, creates a job and compiles the object. This behavior may be * overridden by subclasses. * * @return true if the object was successfully brought up to date, false if the attempt failed (and it may be still be out of date) * @deprecated The check should be done in an action - ExecAction, ... */ protected boolean checkCompiled () { ErrorManager.getDefault().log(ErrorManager.WARNING, "This method does not do anything useful anymore. Will be deprecated completely soon."); //NOI18N return false; } /** Called when invocation of the debugger fails. Allows to do some * modifications to the type of debugging and try it again. * * @param ex exeception that occured during execution * @return true if the debugging should be started again */ protected boolean debugFailed (DebuggerException ex) { DebuggerType orig = getDebuggerType(entry); if (orig == null) { // #33078 orig = defaultDebuggerType(); } DebuggerType e = (DebuggerType)choose(orig, DebuggerType.class, ex); if (e == null) { return false; } else { try { setDebuggerType (entry, e); return true; } catch (IOException exc) { return false; } } } /** This method allows subclasses to override the default * debugger type they want to use for debugging. * * @return current implementation returns DebuggerType.getDefault () */ protected DebuggerType defaultDebuggerType () { return DebuggerType.getDefault (); } // // debugger support // /** Assignes a debugger type to an entry. * @param entry the object's entry * @param type the debugger type for this entry * @exception IOException if arguments cannot be set */ public static void setDebuggerType (MultiDataObject.Entry entry, DebuggerType type) throws IOException { entry.getFile ().setAttribute (EA_DEBUGGER_TYPE, type == null ? null : new ServiceType.Handle (type) ); } /** Retrieves the debugger type for this entry. * @param entry the entry * @return the debugger type or null if no type assigned */ public static DebuggerType getDebuggerType (MultiDataObject.Entry entry) { Object handle = entry.getFile ().getAttribute (EA_DEBUGGER_TYPE); if (handle != null && (handle instanceof ServiceType.Handle)) { ServiceType dbg = ((ServiceType.Handle) handle).getServiceType (); if (dbg instanceof DebuggerType) { return (DebuggerType) dbg; } } Lookup l = Environment.find (entry.getDataObject ()); DebuggerType dt = (DebuggerType)l.lookup (DebuggerType.class); if (dt != null) { return dt; } return null; } /** Helper method that creates default properties for execution of * a given support. * Includes properties to set the executor; debugger; and arguments. * * @param set sheet set to add properties to */ public void addProperties (Sheet.Set set) { super.addProperties(set); set.put(createDebuggerProperty ()); } /** Creates the debugger property for entry. * @return the property */ private PropertySupport createDebuggerProperty () { return new PropertySupport.ReadWrite ( PROP_DEBUGGER_TYPE, DebuggerType.class, NbBundle.getMessage(DebuggerType.class, "PROP_debuggerType"), NbBundle.getMessage(DebuggerType.class, "HINT_debuggerType") ) { public Object getValue() { DebuggerType dt = getDebuggerType (entry); if (dt == null) return defaultDebuggerType (); else return dt; } public void setValue (Object val) throws InvocationTargetException { try { setDebuggerType (entry, (DebuggerType) val); } catch (IOException ex) { throw new InvocationTargetException (ex); } } public boolean supportsDefaultValue () { return true; } public void restoreDefaultValue () throws InvocationTargetException { setValue (null); } public boolean canWrite () { Boolean isReadOnly = (Boolean)entry.getFile().getAttribute(READONLY_ATTRIBUTES); return (isReadOnly == null)?false:(!isReadOnly.booleanValue()); } }; } }

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

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.