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

Quick Search    Search Deep

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


1   package javax.ide.extension.spi;
2   
3   import javax.ide.extension.ElementVisitor;
4   import javax.ide.util.Version;
5   import javax.ide.extension.ExtensionHook;
6   import java.util.logging.Level;
7   import javax.ide.extension.ElementStartContext;
8   import javax.ide.extension.ElementName;
9   
10  /**
11   * A base class for ExtensionVisitor which processes the attributes of the 
12   * extension tag. This is also used by a minimal processor in DependencyTree.
13   */
14  public abstract class BaseExtensionVisitor extends ElementVisitor
15  {
16    public static final ElementName ELEMENT = 
17      new ElementName( ExtensionHook.MANIFEST_XMLNS, "extension" );
18        
19    /**
20     * The max ESDK version that this processor will accept. Any
21     * version greater than this will result in an error (earlier versions
22     * are OK).
23     */
24    private static final Version MAX_ESDK_VERSION = 
25      new Version( "1.0" );
26  
27    protected DefaultExtension processExtension( ElementStartContext context )
28    {
29      String id = context.getAttributeValue( "id" );
30      if ( id == null || (id = id.trim()) == "" )
31      {
32        log( context, Level.SEVERE, "Missing required attribute 'id'" );
33        return null;
34      }
35      
36      String version = context.getAttributeValue( "version" );
37      if ( version == null || ( version = version.trim()) == "" )
38      {
39        log( context, Level.SEVERE, "Missing required attribute 'version'" );
40        return null;
41      }
42      
43      Version parsedVersion;
44      try
45      {
46        parsedVersion = new Version( version );
47      }
48      catch ( NumberFormatException nfe )
49      {
50        log( context, Level.SEVERE, "Incorrectly formed version: " + version );
51        return null;
52      }
53      
54      
55      String esdkversion = context.getAttributeValue( "esdk-version" );
56      if ( esdkversion == null || ( esdkversion = esdkversion.trim()) == "" )
57      {
58        log( context, Level.SEVERE, "Missing required attribute 'esdk-version'" );
59        return null;
60      }
61      
62      Version parsedESDKVersion;
63      try
64      {
65        parsedESDKVersion = new Version( esdkversion );
66      }
67      catch ( NumberFormatException nfe )
68      {
69        log( context, Level.SEVERE, "Incorrectly formed version: " + esdkversion );
70        return null;
71      }
72      
73      if ( parsedESDKVersion.compareTo( MAX_ESDK_VERSION ) > 0 )
74      {
75        log( context, Level.SEVERE,  
76          "ESDK version "+esdkversion+" is too high. Maximum supported version is "+MAX_ESDK_VERSION );
77        return null;
78      }
79      
80      DefaultExtension theExtension = new DefaultExtension( id );
81      theExtension.setVersion( parsedVersion );
82      theExtension.setEDKVersion( parsedESDKVersion );
83      theExtension.setSource( (ExtensionSource)
84        context.getScopeData().get( ExtensionVisitor.KEY_EXTENSION_SOURCE )
85      );
86      
87      context.getScopeData().put( ExtensionHook.KEY_EXTENSION, theExtension );  
88      
89      return theExtension;
90    }
91  }