KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > debug > model > AntLineBreakpoint


1 /*******************************************************************************
2  * Copyright (c) 2004, 2006 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.ant.internal.ui.debug.model;
12
13 import com.ibm.icu.text.MessageFormat;
14 import java.util.HashMap JavaDoc;
15 import java.util.Map JavaDoc;
16
17 import org.eclipse.ant.internal.ui.debug.IAntDebugConstants;
18 import org.eclipse.core.resources.IMarker;
19 import org.eclipse.core.resources.IResource;
20 import org.eclipse.core.resources.IWorkspaceRunnable;
21 import org.eclipse.core.runtime.CoreException;
22 import org.eclipse.core.runtime.IProgressMonitor;
23 import org.eclipse.debug.core.DebugException;
24 import org.eclipse.debug.core.DebugPlugin;
25 import org.eclipse.debug.core.model.IBreakpoint;
26 import org.eclipse.debug.core.model.LineBreakpoint;
27
28 /**
29  * Ant line breakpoint
30  */

31 public class AntLineBreakpoint extends LineBreakpoint {
32     
33     /**
34      * Default constructor is required for the breakpoint manager
35      * to re-create persisted breakpoints. After instantiating a breakpoint,
36      * the <code>setMarker(...)</code> method is called to restore
37      * this breakpoint's attributes.
38      */

39     public AntLineBreakpoint() {
40     }
41     
42     /**
43      * Constructs a line breakpoint on the given resource at the given
44      * line number. The line number is 1-based (i.e. the first line of a
45      * file is line number 1).
46      *
47      * @param resource file on which to set the breakpoint
48      * @param lineNumber 1-based line number of the breakpoint
49      * @throws CoreException if unable to create the breakpoint
50      */

51     public AntLineBreakpoint(IResource resource, int lineNumber) throws CoreException {
52         this(resource, lineNumber, new HashMap JavaDoc(), true);
53     }
54     
55     /**
56      * Constructs a line breakpoint on the given resource at the given
57      * line number. The line number is 1-based (i.e. the first line of a
58      * file is line number 1).
59      *
60      * @param resource file on which to set the breakpoint
61      * @param lineNumber 1-based line number of the breakpoint
62      * @param attributes the marker attributes to set
63      * @param register whether to add this breakpoint to the breakpoint manager
64      * @throws CoreException if unable to create the breakpoint
65      */

66     public AntLineBreakpoint(final IResource resource, final int lineNumber, final Map JavaDoc attributes, final boolean register) throws CoreException {
67         IWorkspaceRunnable wr= new IWorkspaceRunnable() {
68             public void run(IProgressMonitor monitor) throws CoreException {
69                 IMarker marker = resource.createMarker(IAntDebugConstants.ID_ANT_LINE_BREAKPOINT_MARKER);
70                 setMarker(marker);
71                 attributes.put(IBreakpoint.ENABLED, Boolean.TRUE);
72                 attributes.put(IMarker.LINE_NUMBER, new Integer JavaDoc(lineNumber));
73                 attributes.put(IBreakpoint.ID, IAntDebugConstants.ID_ANT_DEBUG_MODEL);
74                 attributes.put(IMarker.MESSAGE, MessageFormat.format(DebugModelMessages.AntLineBreakpoint_0, new String JavaDoc[] {Integer.toString(lineNumber)}));
75                 ensureMarker().setAttributes(attributes);
76                 
77                 register(register);
78             }
79         };
80         run(getMarkerRule(resource), wr);
81     }
82     
83     /* (non-Javadoc)
84      * @see org.eclipse.debug.core.model.IBreakpoint#getModelIdentifier()
85      */

86     public String JavaDoc getModelIdentifier() {
87         return IAntDebugConstants.ID_ANT_DEBUG_MODEL;
88     }
89
90     /**
91      * @return whether this breakpoint is a run to line breakpoint
92      */

93     public boolean isRunToLine() {
94         try {
95             return ensureMarker().getAttribute(IAntDebugConstants.ANT_RUN_TO_LINE, false);
96         } catch (DebugException e) {
97            return false;
98         }
99     }
100     
101     /**
102      * Add this breakpoint to the breakpoint manager,
103      * or sets it as unregistered.
104      */

105     private void register(boolean register) throws CoreException {
106         if (register) {
107             DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(this);
108         } else {
109             setRegistered(false);
110         }
111     }
112 }
113
Popular Tags