KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > schema > SchemaAnnotationHandler


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

11
12 package org.eclipse.pde.internal.core.schema;
13
14 import org.xml.sax.Attributes JavaDoc;
15 import org.xml.sax.SAXException JavaDoc;
16
17
18 /**
19  * SchemaAnnotationHandler
20  *
21  */

22 public class SchemaAnnotationHandler extends BaseSchemaHandler {
23
24     private final static String JavaDoc[] DESC_NESTED_ELEM = { "documentation", //$NON-NLS-1$
25
"annotation", "schema" }; //$NON-NLS-1$ //$NON-NLS-2$
26

27     private final static String JavaDoc META_SCHEMA_ELEM = "meta.schema"; //$NON-NLS-1$
28

29     private final static String JavaDoc APP_INFO_ELEM = "appInfo"; //$NON-NLS-1$
30

31     private final static String JavaDoc NAME_ATTR = "name"; //$NON-NLS-1$
32

33     private StringBuffer JavaDoc fDescription;
34     
35     private String JavaDoc fName;
36     
37     private boolean fMetaSchemaElemFlag;
38
39     private boolean fAppInfoElemFlag;
40     
41     /**
42      *
43      */

44     public SchemaAnnotationHandler() {
45         super();
46     }
47     
48     protected void reset() {
49         super.reset();
50         fName = null;
51         fDescription = new StringBuffer JavaDoc();
52         fMetaSchemaElemFlag = false;
53         fAppInfoElemFlag = false;
54     }
55
56     public void startElement(String JavaDoc uri, String JavaDoc localName, String JavaDoc qName, Attributes JavaDoc attributes) throws SAXException JavaDoc {
57         super.startElement(uri, localName, qName, attributes);
58         
59         if ((fElementList.size() >= 2) &&
60                 (((String JavaDoc)fElementList.get(1)).compareTo(APP_INFO_ELEM) == 0)) {
61             fAppInfoElemFlag = true;
62             if (qName.compareTo(META_SCHEMA_ELEM) == 0) {
63                 // Case: <appInfo><meta.schema>
64
fMetaSchemaElemFlag = true;
65                 if (attributes != null) {
66                     fName = attributes.getValue(NAME_ATTR);
67                 }
68             } else {
69                 // Case: <appInfo><xxxxx>
70
fMetaSchemaElemFlag = false;
71             }
72         }
73     }
74
75     public void characters(char[] ch, int start, int length) throws SAXException JavaDoc {
76         
77         if (onTarget()) {
78             for (int i = 0; i < length; i++) {
79                 fDescription.append(ch[start + i]);
80             }
81         }
82     }
83     
84     protected boolean onTarget() {
85         if (fElementList.size() >= DESC_NESTED_ELEM.length) {
86             for (int i = 0; i < DESC_NESTED_ELEM.length; i++) {
87                 String JavaDoc currentElement = (String JavaDoc)fElementList.get(i);
88                 if (currentElement.compareTo(DESC_NESTED_ELEM[i]) != 0) {
89                     return false;
90                 }
91             }
92             if (fMetaSchemaElemFlag || !fAppInfoElemFlag) {
93                 return true;
94             }
95         }
96         return false;
97     }
98     
99     public String JavaDoc getDescription() {
100         return fDescription.toString();
101     }
102
103     public String JavaDoc getName() {
104         return fName;
105     }
106 }
107
Popular Tags