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

Quick Search    Search Deep

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


1   package javax.ide.extension;
2   import java.net.URI;
3   import javax.ide.extension.spi.ExtensionSource;
4   import javax.ide.extension.spi.ExtensionVisitor;
5   
6   /**
7    * An extension hook is responsible for processing information from the 
8    * extension manifest for a particular feature and making this information
9    * available to the service responsible for managing the functionality 
10   * provided by the hook.<p>
11   */
12  public abstract class ExtensionHook extends ElementVisitor 
13  {
14    public static final String KEY_EXTENSION = "extension";
15    public static final String KEY_RSBUNDLE_CLASS = "rsbundleclass";
16    
17    /**
18     * The XML namespace for a JSR-198 extension manifest.
19     */
20    public static final String MANIFEST_XMLNS = 
21      "http://jcp.org/jsr/198/extension-manifest";
22  
23    protected final String getRSBundleClass( ElementContext context )
24    {
25      return (String) context.getScopeData().get( KEY_RSBUNDLE_CLASS );
26    }
27  
28    /**
29     * Get the extension that is currently being processed.
30     * 
31     * @param context the current context.
32     * @return the extension being processed.
33     */
34    protected final Extension getExtension( ElementContext context )
35    {
36      return (Extension) context.getScopeData().get( KEY_EXTENSION );
37    }
38    
39    /**
40     * Resolve a path in the manifest. Paths depend on the source of the 
41     * extension being processed. For JAR files, if the path starts with a 
42     * forward slash (/), it is a path inside the JAR file. Otherwise, it is a 
43     * path relative to the physical location of the JAR file.
44     * 
45     * @param context the xml processing context.
46     * @param path a path to resolve. Must not be null.
47     * @return the absolute path a resource. This may or may not exist.
48     */
49    protected final URI resolvePath( ElementContext context, String path )
50    {
51      if ( path == null )
52      {
53        throw new NullPointerException( "path is null" );
54      }
55      
56      ExtensionSource source = (ExtensionSource) context.getScopeData().get( 
57        ExtensionVisitor.KEY_EXTENSION_SOURCE
58      );
59      Extension extension = (Extension) context.getScopeData().get( 
60        ExtensionHook.KEY_EXTENSION
61      );
62      
63      return source.resolvePath( extension, path );
64    }
65  }