KickJava   Java API By Example, From Geeks To Geeks.

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


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.IdentityConstraint;
28 import org.xquark.schema.SchemaConstants;
29 import org.xquark.schema.SchemaException;
30 import org.xquark.util.DefaultElementHandler;
31 import org.xquark.util.ElementHandler;
32
33 class IdentityConstraintHandler extends DefaultElementHandler implements SchemaConstants {
34 private static final String JavaDoc RCSRevision = "$Revision: 1.1 $";
35 private static final String JavaDoc RCSName = "$Name: $";
36   private Loader loader = null;
37   private IdentityConstraint identityConstraint = null;
38   
39   IdentityConstraintHandler(Loader loader, IdentityConstraint identityConstraint)
40   throws SAXException JavaDoc {
41     this.loader = loader;
42     this.identityConstraint = identityConstraint;
43   }
44   
45   public ElementHandler startElement(String JavaDoc namespaceURI, String JavaDoc localName, Attributes JavaDoc atts)
46   throws SAXException JavaDoc {
47         if ( namespaceURI.equals(XMLSCHEMA_URI) ) {
48             // selector
49
if ( localName.equals(SELECTOR_TAG) ) {
50               String JavaDoc xpath = atts.getValue("", XPATH_ATTR);
51               try {
52                   identityConstraint.setSelector(loader.buildXPaths(xpath));
53               }
54               catch ( SchemaException se ) {
55                   String JavaDoc errMsg = "Error while processing localName -> " + localName;
56                   loader.reportLoadingError(errMsg, se);
57               }
58               return this;
59             }
60
61             // field
62
if ( localName.equals(FIELD_TAG) ) {
63               String JavaDoc xpath = atts.getValue("", XPATH_ATTR);
64               try {
65                   identityConstraint.addField(loader.buildXPaths(xpath));
66               }
67               catch ( SchemaException se ) {
68                   String JavaDoc errMsg = "Error while processing localName -> " + localName;
69                   loader.reportLoadingError(errMsg, se);
70                }
71               return this;
72             }
73
74             if ( localName.equals(ANNOTATION_TAG) ) {
75               return new AnnotationHandler();
76             }
77         }
78
79         loader.notifyUnknownElement(namespaceURI, localName);
80         return this;
81   }
82   
83 }
84
Popular Tags