KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > scripting > php > dbginterface > 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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.scripting.php.dbginterface.breakpoints;
21
22 import java.net.MalformedURLException JavaDoc;
23 import java.net.URL JavaDoc;
24 import org.netbeans.api.debugger.Properties;
25 import org.openide.cookies.LineCookie;
26 import org.openide.filesystems.FileObject;
27 import org.openide.filesystems.FileStateInvalidException;
28 import org.openide.filesystems.URLMapper;
29 import org.openide.loaders.DataObject;
30 import org.openide.loaders.DataObjectNotFoundException;
31 import org.openide.text.Line;
32
33 /**
34  *
35  * @author Jan Jancura
36  */

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