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

Quick Search    Search Deep

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


1   package javax.ide.extension;
2   
3   import java.util.logging.Level;
4   import javax.ide.util.MetaClass;
5   import javax.ide.extension.spi.ExtensionVisitor;
6   
7   /**
8    * An abstract implementation of a visitor for manifest elements which 
9    * represent meta classes.<p>
10   * 
11   * Subclasses provide an implementation of the 
12   * {@link #metaClass( ElementContext, MetaClass )} to process the meta class
13   * created for the visited xml element.
14   */
15  public abstract class MetaClassVisitor extends ElementVisitor
16  {
17    public final void start( ElementStartContext ctx )
18    {
19      // NO OP
20    }
21    
22    public final void end( ElementEndContext ctx )
23    {
24      String text = ctx.getText().trim();
25      if ( "".equals( text ) )
26      {
27        log( ctx, Level.SEVERE, "Class name is required" ); // Hmm. needs xlation
28        return;
29      }
30      
31      MetaClass mc = new MetaClass( getMetaClassLoader( ctx, text ), text );
32    
33      metaClass( ctx, mc );
34    }
35    
36    /**
37     * Called when a meta class is created. Subclasses will usually process or
38     * store this meta class object.
39     * 
40     * @param context the xml context in which the meta class was created. 
41     * @param mc the created meta class.
42     */
43    protected abstract void metaClass( ElementContext context, MetaClass mc );
44    
45    /**
46     * Get the classloader that should be associated with the specified class.
47     * 
48     * This implementation returns the current classloader from the context.
49     * 
50     * @param context the current parsing context.
51     * @param className the name of the class.
52     * @return a class loader to use.
53     */
54    protected ClassLoader getMetaClassLoader( ElementContext context, 
55      String className )
56    {
57      return (ClassLoader)
58        context.getScopeData().get( ExtensionVisitor.KEY_CLASSLOADER );
59    }
60  }