KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > scripting > php > dbginterface > breakpoints > PersistenceManager


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.beans.PropertyChangeEvent JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.List JavaDoc;
25 import org.netbeans.api.debugger.Breakpoint;
26 import org.netbeans.api.debugger.DebuggerEngine;
27 import org.netbeans.api.debugger.DebuggerManager;
28 import org.netbeans.api.debugger.LazyDebuggerManagerListener;
29 import org.netbeans.api.debugger.Properties;
30 import org.netbeans.api.debugger.Session;
31 import org.netbeans.api.debugger.Watch;
32
33 /**
34  * Listens on DebuggerManager and:
35  * - loads all breakpoints & watches on startup
36  * - listens on all changes of breakpoints and watches (like breakoint / watch
37  * added / removed, or some property change) and saves a new values
38  *
39  * @author Jan Jancura
40  */

41 public class PersistenceManager implements LazyDebuggerManagerListener {
42
43     private static final String JavaDoc DEBUGGER = "debugger"; // NOI18N
44
private static final String JavaDoc PHP_DBG = "PHP-DBG"; // NOI18N
45

46     public Breakpoint[] initBreakpoints() {
47         Properties p = Properties.getDefault().getProperties(DEBUGGER).
48             getProperties(DebuggerManager.PROP_BREAKPOINTS);
49         return (Breakpoint[]) p.getArray(
50             PHP_DBG,
51             new Breakpoint [0]
52             );
53     }
54
55     public void initWatches() {
56     }
57
58     public String JavaDoc[] getProperties() {
59         return new String JavaDoc [] {
60             DebuggerManager.PROP_BREAKPOINTS_INIT,
61             DebuggerManager.PROP_BREAKPOINTS,
62         };
63     }
64
65     public void breakpointAdded(Breakpoint breakpoint) {
66         Properties p = Properties.getDefault().getProperties(DEBUGGER).
67             getProperties(DebuggerManager.PROP_BREAKPOINTS);
68         p.setArray(
69             PHP_DBG,
70             getBreakpoints()
71             );
72         breakpoint.addPropertyChangeListener(this);
73     }
74
75     public void breakpointRemoved(Breakpoint breakpoint) {
76         Properties p = Properties.getDefault().getProperties(DEBUGGER).
77             getProperties(DebuggerManager.PROP_BREAKPOINTS);
78         p.setArray(
79             PHP_DBG,
80             getBreakpoints()
81             );
82         breakpoint.removePropertyChangeListener(this);
83     }
84     public void watchAdded(Watch watch) {
85     }
86
87     public void watchRemoved(Watch watch) {
88     }
89     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
90         if (evt.getSource() instanceof Breakpoint) {
91             Properties.getDefault().getProperties(DEBUGGER).
92                 getProperties(DebuggerManager.PROP_BREAKPOINTS).setArray(
93                 PHP_DBG,
94                 getBreakpoints()
95                 );
96         }
97     }
98
99     public void sessionAdded(Session session) {}
100     public void sessionRemoved(Session session) {}
101     public void engineAdded(DebuggerEngine engine) {}
102     public void engineRemoved(DebuggerEngine engine) {}
103
104
105     private static Breakpoint[] getBreakpoints() {
106         Breakpoint[] bs = DebuggerManager.getDebuggerManager().
107             getBreakpoints();
108         int i, k = bs.length;
109         List JavaDoc<Breakpoint> bb = new ArrayList JavaDoc<Breakpoint>();
110         for (i = 0; i < k; i++) {
111             // Don't store hidden breakpoints
112
if (bs[i] instanceof PhpBreakpoint) {
113                 bb.add(bs[i]);
114             }
115         }
116         bs = new Breakpoint [bb.size()];
117         return (Breakpoint[]) bb.toArray(bs);
118     }
119 }
Popular Tags