Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: netscape/jsdebug/JSSourceTextProvider.java


1   /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2    *
3    * The contents of this file are subject to the Netscape Public
4    * License Version 1.1 (the "License"); you may not use this file
5    * except in compliance with the License. You may obtain a copy of
6    * the License at http://www.mozilla.org/NPL/
7    *
8    * Software distributed under the License is distributed on an "AS
9    * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
10   * implied. See the License for the specific language governing
11   * rights and limitations under the License.
12   *
13   * The Original Code is mozilla.org code.
14   *
15   * The Initial Developer of the Original Code is Netscape
16   * Communications Corporation.  Portions created by Netscape are
17   * Copyright (C) 1998 Netscape Communications Corporation. All
18   * Rights Reserved.
19   *
20   * Contributor(s): 
21   */
22  
23  package netscape.jsdebug;
24  
25  import netscape.util.Vector;
26  import netscape.security.PrivilegeManager;
27  import netscape.security.ForbiddenTargetException;
28  
29  /**
30  * This class provides access to SourceText items.
31  * <p>
32  * This class is meant to be a singleton and has a private constructor.
33  * Call the static <code>getSourceTextProvider()</code> to get this object.
34  * <p>
35  * Note that all functions use netscape.security.PrivilegeManager to verify 
36  * that the caller has the "Debugger" privilege. The exception 
37  * netscape.security.ForbiddenTargetException will be throw if this is 
38  * not enabled.
39  *
40  * @author  John Bandhauer
41  * @version 1.0
42  * @since   1.0
43  * @see netscape.security.PrivilegeManager
44  * @see netscape.security.ForbiddenTargetException
45  */
46  public final class JSSourceTextProvider extends SourceTextProvider
47  {
48      private JSSourceTextProvider( long nativeContext )
49      {
50          _sourceTextVector = new Vector();
51          _nativeContext    = nativeContext;
52      }
53      
54  
55      /**
56       * Get the SourceTextProvider object for the current VM.
57       * <p>
58       * @return the singleton SourceTextProvider
59       */
60      public static synchronized SourceTextProvider getSourceTextProvider()
61          throws ForbiddenTargetException
62      {
63          PrivilegeManager.checkPrivilegeEnabled("Debugger");
64          if( null == _sourceTextProvider )
65          {
66              long nativeContext = DebugController.getDebugController().getNativeContext();
67              if( 0 != nativeContext )
68                  _sourceTextProvider = new JSSourceTextProvider(nativeContext);
69          }
70          return _sourceTextProvider;
71      }
72  
73      /**
74      * Get the SourceText item for the given URL
75      */
76      public SourceTextItem findSourceTextItem( String url )
77          throws ForbiddenTargetException
78      {
79          PrivilegeManager.checkPrivilegeEnabled("Debugger");
80          return findSourceTextItem0(url);
81      }
82  
83      // also called from native code...
84      private SourceTextItem findSourceTextItem0( String url )
85      {
86          synchronized( _sourceTextVector )
87          {
88              for (int i = 0; i < _sourceTextVector.size(); i++)
89              {
90                  SourceTextItem src = (SourceTextItem) _sourceTextVector.elementAt(i);
91              
92                  if( src.getURL().equals(url) )
93                      return src;
94              }
95              return null;
96          }
97      }
98  
99      /**
100     * Return the vector of SourceTextItems. 
101     * <p>
102     * This is NOT a copy. nor is it necessarily current
103     */
104     public Vector getSourceTextVector()
105         throws ForbiddenTargetException
106     {
107         PrivilegeManager.checkPrivilegeEnabled("Debugger");
108         return _sourceTextVector;
109     }
110 
111     /**
112     * Load the SourceText item for the given URL
113     * <p>
114     * <B>This is not guaranteed to be implemented</B>
115     */
116     public synchronized SourceTextItem   loadSourceTextItem( String url )
117         throws ForbiddenTargetException
118     {
119         PrivilegeManager.checkPrivilegeEnabled("Debugger");
120         return loadSourceTextItem0( url );
121     }
122 
123     private native SourceTextItem   loadSourceTextItem0( String url );
124 
125     /**
126     * Refresh the vector to reflect any changes made in the 
127     * underlying native system
128     */
129     public synchronized native void refreshSourceTextVector();
130 
131     private static SourceTextProvider   _sourceTextProvider = null;
132     private Vector                      _sourceTextVector;
133     private long                        _nativeContext;
134 }