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

Quick Search    Search Deep

Source code: javax/ide/extension/ElementVisitor.java


1   package javax.ide.extension;
2   import java.util.logging.Level;
3   import org.xml.sax.Locator;
4   
5   /**
6    * <tt>ElementVisitor</tt> is responsible for visiting elements in an XML file
7    * processed by an XML parser used by a JSR-198 compatible IDE.
8    * 
9    * Implementations of this class usually provide an implementation for the
10   * start() and end() methods.
11   */
12  public abstract class ElementVisitor 
13  {
14    /**
15     * A key that provides information about the position in the manifest file
16     * currently being processed. In the scope data map, this key will resolve
17     * to an instance of org.xml.sax.Locator, if the parser supports it.<p>
18     * You should always check whether the locator is null, since it is not
19     * required that every IDE provide a Locator in the parsing context.
20     */
21    public static final String KEY_LOCATOR = "xml.locator";
22  
23    /**
24     * Log a message. This is the recommended way to log errors while processing
25     * elements in the manifest file. It will ensure that positional information
26     * (if available) is passed to the logger as the first parameter of the 
27     * log message.
28     * 
29     * @param context the current context.
30     * @param level the level to log at.
31     * @param msg the message to log.
32     */
33    protected final void log( ElementContext context, Level level, String msg )
34    {
35      // TODO we should probably use logp() and pass in the caller's class and
36      // method name as arguments. All logging calls are going to come from
37      // the same class / method otherwise.
38      Locator locator = (Locator) context.getScopeData().get( KEY_LOCATOR );
39      if ( locator == null )
40      {
41        context.getLogger().log( level, msg );
42      }
43      else
44      {
45        context.getLogger().log( level, msg, new Object[] { locator } );
46      }
47    }
48  
49    /**
50     * Visit the start tag of an xml element.<p>
51     * 
52     * This implementation does nothing.
53     * 
54     * @param context information about the xml start tag.
55     */
56    public void start( ElementStartContext context )
57    {
58      
59    }
60    
61    /**
62     * Visit the end tag of an xml element.<p>
63     * 
64     * This implementation does nothing.
65     * 
66     * @param context information about the xml end tag.
67     */
68    public void end( ElementEndContext context )
69    {
70      
71    }
72  }