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

Quick Search    Search Deep

Source code: javax/ide/extension/spi/DefaultHookVisitorFactory.java


1   package javax.ide.extension.spi;
2   
3   import java.util.HashMap;
4   import java.util.Map;
5   
6   import javax.ide.build.spi.BuildSystemHook;
7   import javax.ide.extension.ElementName;
8   import javax.ide.extension.ElementVisitor;
9   import javax.ide.extension.ElementVisitorFactory;
10  import javax.ide.extension.ExtensionHook;
11  import javax.ide.log.spi.LogHook;
12  import javax.ide.menu.spi.MenuHook;
13  import javax.ide.model.spi.DocumentHook;
14  import javax.ide.property.spi.PropertyHook;
15  import javax.ide.spi.IDEListenerHook;
16  import javax.ide.wizard.spi.WizardHook;
17  import javax.ide.net.spi.VFSHook;
18  import javax.ide.editor.spi.EditorHook;
19  
20  /**
21   * The default implementation of the visitor factory for hooks. This
22   * implementation returns the default implementations of all standard
23   * hooks defined by the JSR-198 spec and provides a registerHookVisitor()
24   * method used by the hook-handler-hook to register custom hooks declared
25   * in the manifest.
26   */
27  public class DefaultHookVisitorFactory implements ElementVisitorFactory 
28  {
29    private final Map _hookVisitors = new HashMap();
30  
31    /**
32     * Constructs the default hook visitor factory. This implementation calls
33     * {@link #registerStandardVisitors()}.
34     */
35    public DefaultHookVisitorFactory()
36    {
37      registerStandardVisitors();
38    }
39    
40    /**
41     * Register hooks defined in the JSR-198 spec. Unlike user defined hooks,
42     * these are always present and hence statically registered rather than
43     * registered via an extension manifest. <p>
44     * This implementation calls the following methods in sequence:<br />
45     * <ul>
46     * </ul>
47     */
48    protected final void registerStandardVisitors()
49    {
50      registerHook( HookHandlerHook.ELEMENT, createHookHandlerHook() );
51      registerHook( BuildSystemHook.ELEMENT, createBuildSystemHook() );
52      registerHook( FeatureHook.ELEMENT, createFeatureHook() );
53      registerHook( LogHook.ELEMENT, createLogHook() );
54      registerHook( MenuHook.ELEMENT, createMenuHook() );
55      registerHook( DocumentHook.ELEMENT, createDocumentHook() );
56      registerHook( PropertyHook.ELEMENT, createPropertyHook() );
57      registerHook( IDEListenerHook.ELEMENT, createIdeListenerHook() );
58      registerHook( WizardHook.ELEMENT, createWizardHook() );
59      registerHook( VFSHook.ELEMENT, createVFSHook() );
60      registerHook( EditorHook.ELEMENT, createEditorHook() );
61    }
62    
63    protected ExtensionHook createEditorHook()
64    {
65      return new EditorHook();
66    }
67    
68    /**
69     * Create the VFS hook. This implementation returns a new instance of
70     * javax.ide.net.spi.VFSHook.
71     * 
72     * @return the VFS hook.
73     */
74    protected ExtensionHook createVFSHook()
75    {
76      return new VFSHook();
77    }
78    
79    /**
80     * Create the hook handler hook. This implementation returns a new instance
81     * of javax.ide.extension.spi.HookHandlerHook.
82     * 
83     * @return the hook handler hook.
84     */
85    protected ExtensionHook createHookHandlerHook()
86    {
87      return new HookHandlerHook( this );
88    }
89    
90    /**
91     * Create the wizard hook. This implementation returns a new instance of 
92     * javax.ide.wizard.spi.WizardHook.
93     * 
94     * @return the wizard hook.
95     */
96    protected ExtensionHook createWizardHook()
97    {
98      return new WizardHook();
99    }
100   
101   /**
102    * Create the IDE Listener hook. This implementation returns a new instance of
103    * javax.ide.spi.IDEListenerHook.
104    * 
105    * @return the ide listener hook.
106    */
107   protected ExtensionHook createIdeListenerHook()
108   {
109     return new IDEListenerHook();
110   }
111   
112   /**
113    * Create the property hook. This implementation returns a new instance of
114    * javax.ide.property.spi.PropertyHook.
115    * 
116    * @return the property hook.
117    */
118   protected ExtensionHook createPropertyHook()
119   {
120     return new PropertyHook();
121   }
122   
123   /**
124    * Create the document hook. This implementation returns a new instance
125    * of javax.ide.model.spi.DocumentHook.
126    * 
127    * @return the document hook.
128    */
129   protected ExtensionHook createDocumentHook()
130   {
131     return new DocumentHook();
132   }
133   
134   /**
135    * Create the menu hook. This implementation returns a new instance of
136    * javax.ide.menu.spi.MenuHook.
137    * 
138    * @return the menu hook.
139    */
140   protected ExtensionHook createMenuHook()
141   {
142     return new MenuHook();
143   }
144   
145   /**
146    * Create the log hook. This implementation returns a new instance of
147    * javax.ide.extension.spi.LogHook.
148    * 
149    * @return the log hook.
150    */
151   protected ExtensionHook createLogHook()
152   {
153     return new LogHook();
154   }
155 
156   /**
157    * Create the feature hook. This implementation returns a new instance of
158    * javax.ide.extension.spi.FeatureHook.
159    * 
160    * @return the feature hook.
161    */
162   protected ExtensionHook createFeatureHook()
163   {
164     return new FeatureHook();
165   }
166 
167   /**
168    * Create the build system hook. This implementation returns a new instance
169    * of javax.ide.build.spi.BuildSystemHook.
170    * 
171    * @return the build system hook.
172    */
173   protected ExtensionHook createBuildSystemHook()
174   {
175     return new BuildSystemHook();
176   }
177 
178   public final ElementVisitor getVisitor( ElementName name )
179   {
180     return (ElementVisitor) _hookVisitors.get( name );
181   }
182   
183   /**
184    * Get whether there is a registered visitor for the specified hook
185    * element name.
186    * 
187    * @param name the element name of a hook.
188    * @return true if a visitor is registered for the specified element 
189    *    name.
190    */
191   boolean isNameRegistered( ElementName name )
192   {
193     return _hookVisitors.containsKey( name );
194   }
195   
196   /**
197    * Register the specified hook visitor. This is typically used by the 
198    * hook-handler-hook to register custom hooks provided by extension
199    * developers.
200    * 
201    * @param name a qualified element name.
202    * @param hook the hook visitor to use for the specified element name.
203    */
204   final void registerHook( ElementName name, ExtensionHook hook )
205   {
206     _hookVisitors.put( name, hook );
207   }
208 }