Source code: javax/ide/extension/spi/FeatureHook.java
1 package javax.ide.extension.spi;
2
3 import java.util.HashMap;
4 import java.util.Map;
5 import javax.ide.extension.BooleanVisitor;
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
14 public final class FeatureHook extends ExtensionHook
15 {
16 public static final ElementName ELEMENT = new ElementName(
17 MANIFEST_XMLNS, "feature-hook" );
18 private static final ElementName LICENSE = new ElementName(
19 MANIFEST_XMLNS, "license" );
20 private static final ElementName COPYRIGHT = new ElementName(
21 MANIFEST_XMLNS, "copyright" );
22 private static final ElementName ICONPATH = new ElementName(
23 MANIFEST_XMLNS, "iconpath" );
24 private static final ElementName DESCRIPTION = new ElementName(
25 MANIFEST_XMLNS, "description" );
26 private static final ElementName OPTIONAL = new ElementName(
27 MANIFEST_XMLNS, "optional" );
28 private static final ElementName PART_OF = new ElementName(
29 MANIFEST_XMLNS, "part-of" );
30
31 private ElementVisitor _copyrightHandler = new CopyrightHandler();
32 private ElementVisitor _descriptionHandler = new DescriptionHandler();
33 private ElementVisitor _licenseHandler = new LicenseHandler();
34 private ElementVisitor _iconpathHandler = new IconPathHandler();
35 private ElementVisitor _optionalHandler = new OptionalHandler();
36 private ElementVisitor _partOfHandler = new PartOfHandler();
37
38 private String KEY_FEATURE = "featurehook.feature";
39
40
41 private Map _featureMap = new HashMap();
42
43 public Map getFeatures()
44 {
45 return _featureMap;
46 }
47
48 /**
49 * Handle the start of an XML element.
50 *
51 * @param context a context object.
52 */
53 public void start( ElementStartContext context )
54 {
55 context.registerChildVisitor( COPYRIGHT, _copyrightHandler );
56 context.registerChildVisitor( DESCRIPTION, _descriptionHandler );
57 context.registerChildVisitor( ICONPATH, _iconpathHandler );
58 context.registerChildVisitor( LICENSE, _licenseHandler );
59 context.registerChildVisitor( OPTIONAL, _optionalHandler );
60 context.registerChildVisitor( PART_OF, _partOfHandler );
61
62 Feature feature = new Feature();
63 context.getScopeData().put( KEY_FEATURE, feature );
64 }
65
66 /**
67 * Handle the end of an XML element.
68 *
69 * @param context a context object.
70 */
71 public void end( ElementEndContext context )
72 {
73 _featureMap.put( super.getExtension( context ).getID(),
74 getFeature( context ) );
75 }
76
77 private Feature getFeature( ElementContext context )
78 {
79 return (Feature)context.getScopeData().get( KEY_FEATURE );
80 }
81
82 class LicenseHandler extends I18NStringVisitor
83 {
84 protected void string( ElementContext context,
85 String translatedString )
86 {
87 getFeature( context ).setLicense( translatedString );
88 }
89 }
90
91 class CopyrightHandler extends I18NStringVisitor
92 {
93 protected void string( ElementContext context,
94 String translatedString )
95 {
96 getFeature( context ).setCopyright( translatedString );
97 }
98 }
99
100
101 class DescriptionHandler extends I18NStringVisitor
102 {
103 protected void string( ElementContext context,
104 String translatedString )
105 {
106 getFeature( context ).setDescription( translatedString );
107 }
108 }
109
110
111 class IconPathHandler extends I18NStringVisitor
112 {
113 protected void string( ElementContext context,
114 String translatedString )
115 {
116 //TODO: Assign Image
117 }
118 }
119
120 class PartOfHandler extends ElementVisitor
121 {
122 public void end( ElementEndContext context )
123 {
124 getFeature( context ).setPartOf( context.getText() );
125 }
126 }
127
128 class OptionalHandler extends BooleanVisitor
129 {
130 public void booleanValue( ElementContext context, boolean value )
131 {
132 getFeature( context ).setOptional( value );
133 }
134 }
135
136 }