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

Quick Search    Search Deep

Source code: javax/ide/property/spi/PropertyHook.java


1   package javax.ide.property.spi;
2   
3   import java.util.ArrayList;
4   import java.util.Collection;
5   import java.util.logging.Level;
6   import javax.ide.extension.ElementContext;
7   import javax.ide.extension.ElementEndContext;
8   import javax.ide.extension.ElementName;
9   import javax.ide.extension.ElementStartContext;
10  import javax.ide.extension.ElementVisitor;
11  import javax.ide.extension.ExtensionHook;
12  import javax.ide.extension.I18NStringVisitor;
13  import javax.ide.extension.spi.ExtensionVisitor;
14  import javax.ide.property.PropertyPageRegistry;
15  import javax.ide.util.MetaClass;
16  
17  /**
18   * IDE property pages information gathered from processing the 
19   * <b>property-hook</b> section of an extension manifest.
20   * The information recorded here describes property pages which are
21   * generally given to the {@link javax.ide.property.PropertyPageRegistry} for 
22   * registration.<p>
23   */
24  public final class PropertyHook extends ExtensionHook
25  {
26    public static final ElementName ELEMENT = new ElementName( 
27      ExtensionHook.MANIFEST_XMLNS, "property-hook"
28    );
29    
30    private static final ElementName PROPERTY_PAGES = new ElementName(
31      ExtensionHook.MANIFEST_XMLNS, "property-pages" );
32    private static final ElementName PROPERTY_PAGE = new ElementName(
33      ExtensionHook.MANIFEST_XMLNS, "property-page" );
34    private static final ElementName LABEL = new ElementName(
35      ExtensionHook.MANIFEST_XMLNS, "label" );
36    private static final ElementName OBJECT_CLASS = new ElementName(
37      ExtensionHook.MANIFEST_XMLNS, "object-class" );
38      
39    private static final String KEY_INFO = "propertyInfo";
40  
41  
42    private final ElementVisitor _propertyPagesVisitor = new PropertyPagesVisitor();
43    private final ElementVisitor _propertyPageVisitor = new PropertyPageVisitor();
44    private final ElementVisitor _labelVisitor = new LabelVisitor();
45    private final ElementVisitor _objectClassVisitor = new ObjectClassVisitor();
46    
47    private Collection _propertyPageInfos = new ArrayList();
48  
49    public Collection getPropertyPageInfos()
50    {
51      return _propertyPageInfos;
52    }
53  
54    public void start( ElementStartContext context )
55    {
56      context.registerChildVisitor( PROPERTY_PAGES, _propertyPagesVisitor );
57    }
58    
59    private class PropertyPagesVisitor extends ElementVisitor
60    {
61      public void start( ElementStartContext context )
62      {
63        context.registerChildVisitor( PROPERTY_PAGE, _propertyPageVisitor );
64      }
65    }
66    
67    private final class PropertyPageVisitor extends ElementVisitor
68    {
69      public void start( ElementStartContext context )
70      {
71        String clz = context.getAttributeValue( "property-page-class" );
72        if ( clz == null || (clz=clz.trim()).length() == 0 )
73        {
74          log( context, Level.SEVERE, 
75            "Missing required attribute 'property-page-class'" );
76          return;
77        }
78        
79        ClassLoader cl = (ClassLoader)context.getScopeData().get( 
80          ExtensionVisitor.KEY_CLASSLOADER
81        );
82        MetaClass pageClass = new MetaClass( cl, clz );
83        
84        PropertyPageInfo info = new PropertyPageInfo();
85        info.setPageClass( pageClass );
86        context.getScopeData().put( KEY_INFO, info );
87        
88        context.registerChildVisitor( LABEL, _labelVisitor );
89        context.registerChildVisitor( OBJECT_CLASS, _objectClassVisitor );
90      }
91      
92      public void end( ElementEndContext context )
93      {
94        PropertyPageInfo info = getInfo( context );
95        if ( info.getLabel() == null )
96        {
97          log( context, Level.SEVERE, "Label required.");
98          return;
99        }
100       if ( info.getObjectClass() == null )
101       {
102         log( context, Level.SEVERE, "Object class required.");
103         return;
104       }
105       _propertyPageInfos.add( info );
106     }
107   }
108   
109   private final class LabelVisitor extends I18NStringVisitor
110   {
111     public void string( ElementContext context, String value )
112     {
113       PropertyPageInfo info = getInfo( context );
114       info.setLabel( value );
115     }
116   }
117   
118   private final class ObjectClassVisitor extends ElementVisitor
119   {
120     public void end( ElementEndContext context )
121     {
122       String text = context.getText();
123       if ( text != null && (text=text.trim()).length() > 0 )
124       {
125         if ( !PropertyPageRegistry.IDE_CLASS_NAME.equals( text ) &&
126              !PropertyPageRegistry.PROJECT_CLASS_NAME.equals( text ) )
127         {
128           log( context, Level.SEVERE, 
129             "Must be either '"+PropertyPageRegistry.IDE_CLASS_NAME+"' or '"+
130             PropertyPageRegistry.PROJECT_CLASS_NAME+"'." );
131           return;
132         }
133         getInfo( context ).setObjectClass( text );
134       }
135     }
136   }
137   
138   private PropertyPageInfo getInfo( ElementContext context )
139   {
140     return (PropertyPageInfo) context.getScopeData().get( KEY_INFO );
141   }
142   
143   
144 }