KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > schema > loader > ElementTypeHandler


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  *
5  * This program 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 program 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 program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
18  * You can also get it at http://www.gnu.org/licenses/lgpl.html
19  *
20  * For more information on this software, see http://www.xquark.org.
21  */

22
23 package org.xquark.schema.loader;
24
25 import org.xml.sax.Attributes JavaDoc;
26 import org.xml.sax.SAXException JavaDoc;
27 import org.xquark.schema.*;
28 import org.xquark.util.DefaultElementHandler;
29 import org.xquark.util.ElementHandler;
30
31 class ElementTypeHandler extends DefaultElementHandler implements SchemaConstants
32 {
33 private static final String JavaDoc RCSRevision = "$Revision: 1.1 $";
34 private static final String JavaDoc RCSName = "$Name: $";
35     private Loader loader = null;
36     private ElementDeclaration decl;
37
38     ElementTypeHandler(Loader loader, ElementDeclaration decl) {
39         this.loader = loader;
40         this.decl = decl;
41     }
42   
43     public ElementHandler startElement(String JavaDoc namespaceURI, String JavaDoc localName, Attributes JavaDoc atts)
44     throws SAXException JavaDoc
45     {
46         if ( namespaceURI.equals(XMLSCHEMA_URI) ) {
47       if ( !localName.equals(ANNOTATION_TAG) ) {
48         if ( decl instanceof ElementDeclarationRef ) {
49           String JavaDoc errCode = "src-element.2.2";
50           String JavaDoc errMsg = "Error while processing localName -> " + localName;
51           loader.reportLoadingError(errMsg, new SchemaException(errCode));
52         }
53       }
54
55       if (localName.equals(COMPLEX_TYPE_TAG)) {
56         if (decl.getType() != null) {
57           String JavaDoc errCode = "src-element.3";
58           String JavaDoc errMsg = "Error while processing localName -> " + localName;
59           loader.reportLoadingError(errMsg, new SchemaException(errCode));
60         }
61         ComplexType type = null;
62         try {
63           type = loader.buildComplexType(atts);
64         }
65         catch ( SchemaException se ) {
66           String JavaDoc errMsg = "Error while processing localName -> " + localName;
67           loader.reportLoadingError(errMsg, se);
68         }
69         decl.setType(type);
70         return new ComplexTypeHandler(loader, type, false, false);
71       }
72
73       else if (localName.equals(SIMPLE_TYPE_TAG)) {
74         if (decl.getType() != null) {
75           String JavaDoc errCode = "src-element.3";
76           String JavaDoc errMsg = "Error while processing localName -> " + localName;
77           loader.reportLoadingError(errMsg, new SchemaException(errCode));
78         }
79         SimpleType type = null;
80         try {
81           type = loader.buildSimpleType(atts);
82         }
83         catch ( SchemaException se ) {
84           String JavaDoc errMsg = "Error while processing localName -> " + localName;
85           loader.reportLoadingError(errMsg, se);
86         }
87         decl.setType(type);
88         return new SimpleTypeHandler(loader, type, false, false);
89       }
90
91       else if ( localName.equals(KEY_TAG) ||
92                 localName.equals(KEYREF_TAG) ||
93                 localName.equals(UNIQUE_TAG) )
94       {
95           IdentityConstraint identityConstraint = null;
96           try {
97             identityConstraint = loader.buildIdentityConstraint(atts, localName, decl);
98               decl.register(identityConstraint);
99               decl.getSchema().register(identityConstraint);
100           }
101           catch ( SchemaException se ) {
102             String JavaDoc errMsg = "Error while processing localName -> " + localName;
103             loader.reportLoadingError(errMsg, se);
104           }
105           return new IdentityConstraintHandler(loader, identityConstraint);
106       }
107
108       else if (localName.equals(ANNOTATION_TAG)) {
109         return new AnnotationHandler();
110       }
111         }
112         
113         loader.notifyUnknownElement(namespaceURI, localName);
114         return this;
115     }
116 }
117     
118
Popular Tags