KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > ant > debugger > breakpoints > BreakpointsReader


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.ant.debugger.breakpoints;
21
22 import java.lang.IllegalArgumentException JavaDoc;
23 import java.lang.IndexOutOfBoundsException JavaDoc;
24 import java.net.MalformedURLException JavaDoc;
25 import java.net.URL JavaDoc;
26 import org.netbeans.api.debugger.Breakpoint;
27 import org.netbeans.api.debugger.DebuggerManager;
28 import org.netbeans.api.debugger.Properties;
29 import org.openide.cookies.LineCookie;
30 import org.openide.filesystems.FileObject;
31 import org.openide.filesystems.FileStateInvalidException;
32 import org.openide.filesystems.URLMapper;
33 import org.openide.loaders.DataObject;
34 import org.openide.loaders.DataObjectNotFoundException;
35 import org.openide.text.Line;
36
37
38 /**
39  *
40  * @author Jan Jancura
41  */

42 public class BreakpointsReader implements Properties.Reader {
43     
44     
45     public String JavaDoc [] getSupportedClassNames () {
46         return new String JavaDoc[] {
47             AntBreakpoint.class.getName (),
48         };
49     }
50     
51     public Object JavaDoc read (String JavaDoc typeID, Properties properties) {
52         if (!(typeID.equals (AntBreakpoint.class.getName ())))
53             return null;
54         
55         Line line = getLine (
56             properties.getString ("url", null),
57             properties.getInt ("lineNumber", 1));
58         if (line == null) return null;
59         return new AntBreakpoint (line);
60     }
61     
62     public void write (Object JavaDoc object, Properties properties) {
63         AntBreakpoint b = (AntBreakpoint) object;
64         FileObject fo = (FileObject) b.getLine ().getLookup ().
65             lookup (FileObject.class);
66         try {
67             properties.setString ("url", fo.getURL ().toString ());
68             properties.setInt (
69                 "lineNumber",
70                 b.getLine ().getLineNumber ()
71             );
72         } catch (FileStateInvalidException ex) {
73             ex.printStackTrace ();
74         }
75     }
76     
77
78     private Line getLine (String JavaDoc url, int lineNumber) {
79         FileObject file;
80         try {
81             file = URLMapper.findFileObject (new URL JavaDoc (url));
82         } catch (MalformedURLException JavaDoc e) {
83             return null;
84         }
85         if (file == null) return null;
86         DataObject dataObject = null;
87         try {
88             dataObject = DataObject.find (file);
89         } catch (DataObjectNotFoundException ex) {
90             return null;
91         }
92         if (dataObject == null) return null;
93         LineCookie lineCookie = (LineCookie) dataObject.getCookie
94             (LineCookie.class);
95         if (lineCookie == null) return null;
96         Line.Set ls = lineCookie.getLineSet ();
97         if (ls == null) return null;
98         try {
99             return ls.getCurrent (lineNumber);
100         } catch (IndexOutOfBoundsException JavaDoc e) {
101         } catch (IllegalArgumentException JavaDoc e) {
102         }
103         return null;
104     }
105 }
106
Popular Tags