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

Quick Search    Search Deep

Source code: javax/ide/wizard/spi/WizardHook.java


1   package javax.ide.wizard.spi;
2   
3   import java.util.Collection;
4   import java.util.Collections;
5   import java.util.HashMap;
6   import java.util.Map;
7   import java.util.logging.Level;
8   
9   import javax.ide.extension.ElementContext;
10  import javax.ide.extension.ElementEndContext;
11  import javax.ide.extension.ElementName;
12  import javax.ide.extension.ElementStartContext;
13  import javax.ide.extension.ElementVisitor;
14  import javax.ide.extension.ExtensionHook;
15  import javax.ide.extension.I18NStringVisitor;
16  import javax.ide.extension.IconVisitor;
17  import javax.ide.extension.spi.ExtensionVisitor;
18  import javax.ide.util.IconDescription;
19  import javax.ide.util.MetaClass;
20  
21  /**
22   * Wizard information gathered from processing the <b>wizard-hook</b>
23   * section of an extension deployment descriptor. The information recorded 
24   * here describes a new wizard and is generally given to the 
25   * {@link javax.ide.wizard.WizardManager} for registration.
26   */
27  public final class WizardHook extends ExtensionHook
28  {
29    public static final ElementName ELEMENT = new ElementName( MANIFEST_XMLNS, 
30      "wizard-hook" );
31      
32    private static final ElementName WIZARDS = new ElementName( MANIFEST_XMLNS, 
33      "wizards" );
34    private static final ElementName WIZARD = new ElementName( MANIFEST_XMLNS, 
35      "wizard" );
36    private static final ElementName LABEL = new ElementName(
37      MANIFEST_XMLNS, "label" );
38    private static final ElementName ICONPATH = new ElementName(
39      MANIFEST_XMLNS, "iconpath" );
40    private static final ElementName TOOLTIP = new ElementName(
41      MANIFEST_XMLNS, "tooltip" );
42      
43    private static final String KEY_WIZARD_INFO = "wizardInfo";
44      
45    private ElementVisitor _wizardsVisitor = new WizardsVisitor();
46    private ElementVisitor _wizardVisitor = new WizardVisitor();
47    private ElementVisitor _labelVisitor = new LabelVisitor();
48    private ElementVisitor _iconpathVisitor = new IconPathVisitor();
49    private ElementVisitor _tooltipVisitor = new ToolTipVisitor();
50  
51  
52    private final Map _wizardsByClass = new HashMap();
53    
54    
55    public WizardInfo getWizardInfo( String className )
56    {
57      final WizardInfo info = (WizardInfo)_wizardsByClass.get( className );
58      
59      if ( info == null )
60      {
61        throw new IllegalArgumentException( "Unknown wizard class " + className );
62      }
63      
64      return info;
65    }
66    
67    public Collection /*<String>*/ getAllWizardClasses()
68    {
69      return Collections.unmodifiableCollection( _wizardsByClass.keySet() );
70    }
71    
72    public void start( ElementStartContext context )
73    {
74      context.registerChildVisitor( WIZARDS, _wizardsVisitor );
75    }
76    
77    private static WizardInfo getWizardInfo( ElementContext context )
78    {
79      return (WizardInfo) context.getScopeData().get( KEY_WIZARD_INFO );
80    }
81    
82    private class WizardsVisitor extends ElementVisitor
83    {
84      public void start( ElementStartContext context )
85      {
86        context.registerChildVisitor( WIZARD, _wizardVisitor );
87      }
88    }
89    
90    private class WizardVisitor extends ElementVisitor
91    {
92      public void start( ElementStartContext context )
93      {
94        String className = context.getAttributeValue( "wizard-class" );
95        if ( className == null || (className = className.trim()).length() == 0 )
96        {
97          log( context, Level.SEVERE, "Missing required 'wizard-class' attribute." );
98        }
99        else
100       {
101         MetaClass clazz = new MetaClass( 
102           (ClassLoader) context.getScopeData().get( ExtensionVisitor.KEY_CLASSLOADER ),
103           className
104         );
105         WizardInfo info = new WizardInfo( clazz );
106         context.getScopeData().put( KEY_WIZARD_INFO, info );
107         
108         context.registerChildVisitor( LABEL, _labelVisitor );
109         context.registerChildVisitor( ICONPATH, _iconpathVisitor );
110         context.registerChildVisitor( TOOLTIP, _tooltipVisitor );
111       }
112     }
113     
114     public void end( ElementEndContext context )
115     {
116       WizardInfo wi = getWizardInfo( context );
117       _wizardsByClass.put( wi.getWizardClass().getClassName(), wi );
118     }
119   }
120   
121   private class LabelVisitor extends I18NStringVisitor
122   {
123     protected void string( ElementContext context, String value )
124     {
125       getWizardInfo( context ).setLabel( value );
126     }
127   }
128   
129   private class IconPathVisitor extends IconVisitor
130   {
131     protected void icon( ElementContext context, IconDescription icon )
132     {
133       getWizardInfo( context ).setIcon( icon );
134     }
135   }
136   
137   private class ToolTipVisitor extends I18NStringVisitor
138   {
139     protected void string( ElementContext context, String value )
140     {
141       getWizardInfo( context ).setToolTip( value );
142     }
143   }
144 
145 }