KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > java > plugin > registry > xml > ManifestInfoHandler


1 /*****************************************************************************
2  * Java Plug-in Framework (JPF)
3  * Copyright (C) 2004-2006 Dmitry Olshansky
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *****************************************************************************/

19 package org.java.plugin.registry.xml;
20
21 import org.java.plugin.registry.PluginPrerequisite;
22 import org.xml.sax.Attributes JavaDoc;
23 import org.xml.sax.EntityResolver JavaDoc;
24 import org.xml.sax.SAXException JavaDoc;
25
26 /**
27  * @version $Id: ManifestInfoHandler.java,v 1.2 2006/06/05 18:16:43 ddimon Exp $
28  */

29 final class ManifestInfoHandler extends BaseHandler {
30     private ModelManifestInfo manifest = null;
31
32     ManifestInfoHandler(final EntityResolver JavaDoc anEntityResolver) {
33         super(anEntityResolver);
34     }
35     
36     /**
37      * @see org.xml.sax.ContentHandler#startElement(java.lang.String,
38      * java.lang.String, java.lang.String, org.xml.sax.Attributes)
39      */

40     public void startElement(final String JavaDoc uri, final String JavaDoc localName,
41             final String JavaDoc qName, final Attributes JavaDoc attributes)
42             throws SAXException JavaDoc {
43         if (log.isDebugEnabled()) {
44             log.debug("startElement - [" + uri + "]/[" //$NON-NLS-1$ //$NON-NLS-2$
45
+ localName + "]/[" + qName + "]"); //$NON-NLS-1$ //$NON-NLS-2$
46
}
47         String JavaDoc name = qName;
48         if ("plugin".equals(name)) { //$NON-NLS-1$
49
if (manifest != null) {
50                 throw new SAXException JavaDoc("unexpected [" + name //$NON-NLS-1$
51
+ "] element (manifest already defined)"); //$NON-NLS-1$
52
}
53             manifest = new ModelManifestInfo();
54             manifest.setId(attributes.getValue("id")); //$NON-NLS-1$
55
manifest.setVersion(attributes.getValue("version")); //$NON-NLS-1$
56
manifest.setVendor(attributes.getValue("vendor")); //$NON-NLS-1$
57
} else if ("plugin-fragment".equals(name)) { //$NON-NLS-1$
58
if (manifest != null) {
59                 throw new SAXException JavaDoc("unexpected [" + name //$NON-NLS-1$
60
+ "] element (manifest already defined)"); //$NON-NLS-1$
61
}
62             manifest = new ModelManifestInfo();
63             manifest.setId(attributes.getValue("id")); //$NON-NLS-1$
64
manifest.setVersion(attributes.getValue("version")); //$NON-NLS-1$
65
manifest.setVendor(attributes.getValue("vendor")); //$NON-NLS-1$
66
manifest.setPluginId(attributes.getValue("plugin-id")); //$NON-NLS-1$
67
if (attributes.getValue("plugin-version") != null) { //$NON-NLS-1$
68
manifest.setPluginVersion(
69                         attributes.getValue("plugin-version")); //$NON-NLS-1$
70
}
71             if (attributes.getValue("match") != null) { //$NON-NLS-1$
72
manifest.setMatch(attributes.getValue("match")); //$NON-NLS-1$
73
} else {
74                 manifest.setMatch(PluginPrerequisite.MATCH_COMPATIBLE);
75             }
76         } else {
77             // ignore all other elements
78
}
79     }
80
81     /**
82      * @see org.xml.sax.ContentHandler#endElement(java.lang.String,
83      * java.lang.String, java.lang.String)
84      */

85     public void endElement(final String JavaDoc uri, final String JavaDoc localName,
86             final String JavaDoc qName) {
87         if (log.isDebugEnabled()) {
88             log.debug("endElement - [" + uri + "]/[" + localName //$NON-NLS-1$ //$NON-NLS-2$
89
+ "]/[" + qName + "]"); //$NON-NLS-1$ //$NON-NLS-2$
90
}
91         // no-op
92
}
93
94     /**
95      * @see org.xml.sax.ContentHandler#characters(char[], int, int)
96      */

97     public void characters(final char[] ch, final int start, final int length) {
98         // ignore all characters
99
}
100     
101     ModelManifestInfo getResult() {
102         return manifest;
103     }
104 }
105
Popular Tags