| Home >> All >> javax >> ide >> extension >> [ spi Javadoc ] |
Source code: javax/ide/extension/spi/DependenciesVisitor.java
1 package javax.ide.extension.spi; 2 3 import javax.ide.extension.ElementEndContext; 4 import javax.ide.extension.ElementName; 5 import javax.ide.extension.ElementStartContext; 6 import javax.ide.extension.ElementVisitor; 7 import javax.ide.extension.ExtensionDependency; 8 import javax.ide.extension.ExtensionHook; 9 import javax.ide.util.Version; 10 11 /** 12 * Visitor implementation for <dependencies> 13 */ 14 public final class DependenciesVisitor extends ElementVisitor 15 { 16 public final static ElementName ELEMENT = new ElementName( 17 ExtensionHook.MANIFEST_XMLNS, "dependencies" ); 18 private final static ElementName IMPORT = new ElementName( 19 ExtensionHook.MANIFEST_XMLNS, "import" ); 20 21 private ElementVisitor _importVisitor = new ImportVisitor(); 22 23 private static final String MIN_VERSION = "minVersion"; 24 private static final String MAX_VERSION = "maxVersion"; 25 26 public void start( ElementStartContext context ) 27 { 28 context.registerChildVisitor( IMPORT, _importVisitor ); 29 } 30 31 public void end( ElementEndContext context ) 32 { 33 34 } 35 36 private class ImportVisitor extends ElementVisitor 37 { 38 public void start( ElementStartContext context ) 39 { 40 String minVersion = context.getAttributeValue( "minVersion" ); 41 String maxVersion = context.getAttributeValue( "maxVersion" ); 42 43 Version vMinVersion = null; 44 if ( minVersion != null ) 45 { 46 vMinVersion = new Version( minVersion ); 47 } 48 49 Version vMaxVersion = null; 50 if ( maxVersion != null ) 51 { 52 vMaxVersion = new Version( maxVersion ); 53 } 54 55 context.getScopeData().put( MIN_VERSION, vMinVersion ); 56 context.getScopeData().put( MAX_VERSION, vMaxVersion ); 57 } 58 59 public void end( ElementEndContext context ) 60 { 61 String id = context.getText().trim(); 62 if ( id.length() == 0 ) 63 { 64 context.getLogger().severe( 65 "Missing extension id." 66 ); 67 return; 68 } 69 ExtensionDependency dep = new ExtensionDependency( id, 70 (Version) context.getScopeData().get( MIN_VERSION ), 71 (Version) context.getScopeData().get( MAX_VERSION ) 72 ); 73 74 DefaultExtension ext = (DefaultExtension) context.getScopeData().get( 75 ExtensionHook.KEY_EXTENSION 76 ); 77 ext.addDependency( dep ); 78 } 79 } 80 }