KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > debug > 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-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.web.debug.breakpoints;
21
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import org.netbeans.api.debugger.Breakpoint;
25 import org.netbeans.api.debugger.DebuggerEngine;
26
27 import org.netbeans.api.debugger.DebuggerManager;
28 import org.netbeans.api.debugger.DebuggerManagerListener;
29 import org.netbeans.api.debugger.LazyDebuggerManagerListener;
30 import org.netbeans.api.debugger.Properties;
31 import org.netbeans.api.debugger.Session;
32 import org.netbeans.api.debugger.Watch;
33
34 /**
35  * Listens on DebuggerManager and:
36  * - loads all breakpoints & watches on startup
37  * - listens on all changes of breakpoints and watches (like breakoint / watch
38  * added / removed, or some property change) and saves a new values
39  *
40  * @author Libor Kotouc
41  */

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