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

Quick Search    Search Deep

Source code: javax/ide/build/spi/BuildSystemHook.java


1   package javax.ide.build.spi;
2   
3   import java.util.ArrayList;
4   import java.util.Collection;
5   import java.util.Iterator;
6   import java.util.List;
7   import javax.ide.extension.ElementContext;
8   import javax.ide.extension.ElementName;
9   import javax.ide.extension.ElementStartContext;
10  import javax.ide.extension.ElementVisitor;
11  import javax.ide.extension.ExtensionHook;
12  import javax.ide.extension.MetaClassVisitor;
13  import javax.ide.util.MetaClass;
14  
15  /**
16   * Build system information gathered from processing the 
17   * <b>build-system-hook</b> section of extension manifests. 
18   */
19  public final class BuildSystemHook extends ExtensionHook
20  {
21    private static final ElementName LISTENER_CLASS = 
22      new ElementName( MANIFEST_XMLNS, "listener-class" );
23  
24    private static final ElementName BUILD_LISTENERS =
25      new ElementName( MANIFEST_XMLNS, "build-listeners" );
26  
27    public static final ElementName ELEMENT = 
28      new ElementName( MANIFEST_XMLNS, "build-system-hook" );
29  
30    private final Collection _metaListeners = new ArrayList();
31  
32    private final ElementVisitor _listenerVisitor = new ListenerClassVisitor();
33    private final ElementVisitor _buildListenersVisitor = new BuildListenersVisitor();
34  
35    /**
36     * Get the list of build system listeners 
37     * declared in an extension manifest. This information records 
38     * the build system listener classes interested in receiving events from the 
39     * build system.
40     *
41     * @return a collection of {@link javax.ide.build.BuildListener}s.
42     */
43    public Collection getListeners()
44    {
45      List listeners = new ArrayList( _metaListeners.size() );
46      for ( Iterator i = _metaListeners.iterator(); i.hasNext(); )
47      {
48        MetaClass thisClass = (MetaClass) i.next();
49        try
50        {
51          listeners.add( thisClass.newInstance() );
52        }
53        catch ( Exception e )
54        {
55          // TODO: Decide what to do with exceptions like this...
56          e.printStackTrace();
57        }
58      }
59      return listeners;
60    }
61    
62    public void start( ElementStartContext ctx )
63    {
64      ctx.registerChildVisitor( BUILD_LISTENERS, _buildListenersVisitor );
65    }
66    
67    private class BuildListenersVisitor extends ElementVisitor
68    {
69      public void start( ElementStartContext context )
70      {
71        context.registerChildVisitor( LISTENER_CLASS, _listenerVisitor );
72      }
73    }
74    
75    private class ListenerClassVisitor extends MetaClassVisitor
76    {
77      protected void metaClass( ElementContext context, MetaClass mc )
78      {
79        _metaListeners.add( mc );
80      }
81    }
82    
83    
84  
85  }