KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > plugin > ExtensionsParser


1 /*******************************************************************************
2  * Copyright (c) 2003, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.core.plugin;
12
13 import java.util.*;
14
15 import org.eclipse.pde.core.plugin.*;
16 import org.xml.sax.*;
17 import org.xml.sax.helpers.*;
18
19 /**
20  * @author melhem
21  *
22  */

23 public class ExtensionsParser extends DefaultHandler {
24     
25     private Vector fExtensions;
26     private Vector fExtensionPoints;
27     
28     private Stack fOpenElements;
29     private Locator fLocator;
30     private boolean fIsLegacy = true;
31     private ISharedPluginModel fModel;
32     
33     /**
34      *
35      */

36     public ExtensionsParser(ISharedPluginModel model) {
37         super();
38         fExtensionPoints = new Vector();
39         fExtensions = new Vector();
40         fModel = model;
41     }
42     
43     /* (non-Javadoc)
44      * @see org.xml.sax.helpers.DefaultHandler#processingInstruction(java.lang.String, java.lang.String)
45      */

46     public void processingInstruction(String JavaDoc target, String JavaDoc data)
47             throws SAXException {
48         if ("eclipse".equals(target)) { //$NON-NLS-1$
49
fIsLegacy = false;
50         }
51     }
52     
53     /* (non-Javadoc)
54      * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
55      */

56     public void startElement(String JavaDoc uri, String JavaDoc localName, String JavaDoc qName, Attributes attributes) throws SAXException {
57         if (fOpenElements == null) {
58             if (qName.equals("plugin") || qName.equals("fragment")) { //$NON-NLS-1$ //$NON-NLS-2$
59
fOpenElements = new Stack();
60             }
61         } else if (fOpenElements.size() == 0) {
62             if (qName.equals("extension")) { //$NON-NLS-1$
63
createExtension(attributes);
64             } else if (qName.equals("extension-point")) { //$NON-NLS-1$
65
createExtensionPoint(attributes);
66             }
67         } else {
68             createElement(qName, attributes);
69         }
70     }
71     
72     /**
73      * @param attributes
74      */

75     private void createExtension(Attributes attributes) {
76         PluginExtension extension = new PluginExtension();
77         if (extension.load(attributes, fLocator.getLineNumber())) {
78             extension.setModel(fModel);
79             extension.setInTheModel(true);
80             fExtensions.add(extension);
81             String JavaDoc point = extension.getPoint();
82             if ("org.eclipse.pde.core.source".equals(point) || "org.eclipse.core.runtime.products".equals(point)) //$NON-NLS-1$ //$NON-NLS-2$
83
fOpenElements.push(extension);
84         }
85     }
86
87     /**
88      * @param attributes
89      */

90     private void createExtensionPoint(Attributes attributes) {
91         PluginExtensionPoint extPoint = new PluginExtensionPoint();
92         if (extPoint.load(attributes, fLocator.getLineNumber())) {
93             extPoint.setModel(fModel);
94             extPoint.setInTheModel(true);
95             fExtensionPoints.add(extPoint);
96         }
97     }
98     
99     private void createElement(String JavaDoc tagName, Attributes attributes) {
100         PluginElement element = new PluginElement();
101         PluginParent parent = (PluginParent)fOpenElements.peek();
102         element.setParent(parent);
103         element.setInTheModel(true);
104         element.setModel(fModel);
105         element.load(tagName, attributes);
106         parent.appendChild(element);
107         fOpenElements.push(element);
108     }
109     
110     /* (non-Javadoc)
111      * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
112      */

113     public void endElement(String JavaDoc uri, String JavaDoc localName, String JavaDoc qName)
114             throws SAXException {
115         if (fOpenElements != null && !fOpenElements.isEmpty())
116             fOpenElements.pop();
117     }
118
119     /* (non-Javadoc)
120      * @see org.xml.sax.helpers.DefaultHandler#setDocumentLocator(org.xml.sax.Locator)
121      */

122     public void setDocumentLocator(Locator locator) {
123         fLocator = locator;
124     }
125     
126     public boolean isLegacy() {
127         return fIsLegacy;
128     }
129     
130     public Vector getExtensions() {
131         return fExtensions;
132     }
133     
134     public Vector getExtensionPoints() {
135         return fExtensionPoints;
136     }
137 }
138
Popular Tags