KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > mapper > storage > MappingSAXHandler


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 /*
24  * SchemaSAXHandler.java
25  *
26  * Created on 31 mai 2001, 16:55
27  */

28
29 package org.xquark.mapper.storage;
30
31 import java.sql.SQLException JavaDoc;
32
33 import org.xml.sax.InputSource JavaDoc;
34 import org.xquark.mapper.RepositoryException;
35 import org.xquark.mapper.dbms._RepositoryConnection;
36 import org.xquark.mapper.mapping.MappingFactory;
37 import org.xquark.mapper.util.DestructionToken;
38 import org.xquark.schema.validation.SchemaValidationContext;
39 import org.xquark.xml.xdbc.XMLDBCException;
40
41 /**
42  *
43  */

44 public class MappingSAXHandler extends CollectionFiler
45 {
46     private static final String JavaDoc RCSRevision = "$Revision: 1.1 $";
47     private static final String JavaDoc RCSName = "$Name: $";
48     
49     public MappingSAXHandler(_RepositoryCollection collection,
50     SchemaValidationContext schemaContext,
51     DestructionToken destructor)
52     throws XMLDBCException
53     {
54         super(collection, schemaContext, true, destructor);
55         // TO IMPROVE in the future prefix could not be stored if schema of mapping is available
56
}
57     
58     protected void startParsing() throws RepositoryException, SQLException JavaDoc
59     {
60         if (!performCommit)
61             throw new RepositoryException(RepositoryException.NOT_ALLOWED,
62             "The XML connection must be autocommit mode in order to store mapping files.");
63         super.startParsing();
64     }
65     protected void endParsing() throws Exception JavaDoc
66     {
67         super.endParsing();
68         flushBuffer(); // to be sure the mapping is stored before loading mapping
69
connection.commit(); // because Sybase throw an exception if autocommit(false)
70
// and access to metadata is performed
71

72         // Load the mapping in order to validate it
73
RepositoryReader reader = collection.getReader();
74         _RepositoryConnection repConn = collection.getRepositoryConnection();
75         try
76         {
77             
78             org.xquark.mapper.mapping.Loader loader =
79             new org.xquark.mapper.mapping.Loader
80             (
81             reader,
82             repConn.getConnection(),
83             repConn.getSchemaManager(),
84             false
85             );
86             
87             MappingFactory factory = new MappingFactory
88             (
89             collection.getMetadata().getRepository(),
90             repConn.getSchemaManager(),
91             repConn
92             );
93             factory.createTree();
94             loader.load(new InputSource JavaDoc(getDocumentId()), factory, getXMLErrorHandler(), false);
95         }
96         catch (Exception JavaDoc e) {
97             // IMPORTANT : With Oracle (8.1.6, 8.1.7, and Sybase) access to JDBC DataBaseMetadata forces a commit (even if autocommit is false)
98
((MappingXMLCollection)collection).removeDocument(getDocumentId());
99             throw e;
100         }
101         finally
102         {
103             if (reader != null)
104                 reader.close();
105             
106         }
107     }
108 }
109
Popular Tags