KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > xquery > xdbc > AbstractXMLDataSourceMetaData


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.xquery.xdbc;
24
25 import java.util.Collections JavaDoc;
26 import java.util.Iterator JavaDoc;
27
28 import org.xml.sax.helpers.AttributesImpl JavaDoc;
29 import org.xquark.util.XMLDocumentFragmentor;
30 import org.xquark.xml.xdbc.*;
31 import org.xquark.xpath.XTreeReader;
32
33 /**
34  * Implementation of XMLDataSourceMetaData for the method getMetaData()
35  */

36 public abstract class AbstractXMLDataSourceMetaData implements XMLDataSourceMetaData {
37     private static final String JavaDoc RCSRevision = "$Revision: 1.1 $";
38     private static final String JavaDoc RCSName = "$Name: $";
39     public static final String JavaDoc METADATA_ELEMENT_NAME = "metadata";
40     public static final String JavaDoc SOURCE_ATTR = "source";
41     public static final String JavaDoc SCHEMAS_ELEMENT_NAME = "schemas";
42     public static final String JavaDoc COLLECTIONS_ELEMENT_NAME = "collections";
43     
44     public static final String JavaDoc[] PROPERTY_LIST = {
45         "xmldbc.maxConnections", "xmldbc.maxStatementLength",
46         "xmldbc.maxActiveStatements", "xmldbc.maxResultSetLength",
47         "xmldbc.maxUserNameLength", "xmldbc.dataSourceVersion",
48         "xmldbc.vendor.name", "xmldbc.vendor.product",
49         "xmldbc.vendor.version", "xmldbc.driver.version",
50         "xmldbc.driver.product", "xmldbc.xpath",
51         "xmldbc.xpath.version", "xmldbc.xquery",
52         "xmldbc.xquery.version", "xmldbc.xquery.outerJoin",
53         "xmldbc.twoPhaseCommit", "xmldbc.xquery.equality",
54         "xmldbc.xquery.result", "xmldbc.xmlCollection",
55         "xmldbc.xmlCollection.id", "xmldbc.xmlCollection.iterator",
56         "xmldbc.xquery.multiCollection"
57     };
58     
59     XMLConnection connection;
60     
61     protected AbstractXMLDataSourceMetaData(XMLConnection connection) {
62         this.connection = connection;
63     }
64     
65     public java.util.Set JavaDoc getCapabilities() {
66         return Collections.EMPTY_SET;
67     }
68     
69     public XMLDocument getMetaData() throws XMLDBCException {
70         return new MetaDataDocument();
71     }
72     
73     /**
74      * To get the XMLConnection object that produced this XMLDataSourceMetaData object.
75      * @return the XMLConnection object that produced this object.
76      * @throws XMLDBCException if a data source access error occurs.
77      */

78     public XMLConnection getConnection() throws XMLDBCException {
79         return connection;
80     }
81     
82     public void setConnection(XMLConnection connection) throws XMLDBCException {
83         this.connection = connection;
84     }
85     
86     public String JavaDoc[] getPropertyList() {
87         return PROPERTY_LIST;
88     }
89     
90     ///////////////////////////////////////////////////////////////////////////
91
// INNER CLASSES
92
///////////////////////////////////////////////////////////////////////////
93
private class MetaDataDocument extends AbstractXMLDocument {
94         private static final String JavaDoc RCSRevision = "$Revision: 1.1 $";
95         private static final String JavaDoc RCSName = "$Name: $";
96         
97         private static final String JavaDoc METADATA_ID = "XMLDBC DataSource Metadata";
98         
99         public MetaDataDocument() {
100             super(METADATA_ID, null, true);
101         }
102         
103         public void remove() throws XMLDBCException, XMLDBCNotSupportedException {
104             throw new XMLDBCNotSupportedException("This document is read-only");
105         }
106         
107         public void getAsSAX() throws XMLDBCException, org.xml.sax.SAXException JavaDoc {
108             AttributesImpl JavaDoc atts = new AttributesImpl JavaDoc();
109             
110             // start doc
111
contentHandler.startDocument();
112             
113             // start root element
114
contentHandler.startPrefixMapping(XTreeReader.SOURCE_METADATA_PREFIX, XTreeReader.SOURCE_METADATA_NAMESPACE);
115             atts.addAttribute("", SOURCE_ATTR, "", "CDATA", connection == null? "":connection.getURL());
116             contentHandler.startElement(XTreeReader.SOURCE_METADATA_NAMESPACE, METADATA_ELEMENT_NAME, "", atts);
117             atts.clear();
118             
119             // serialize schemas
120
contentHandler.startElement("", SCHEMAS_ELEMENT_NAME, "", atts);
121             
122             XMLDocumentFragmentor fragmentor = new XMLDocumentFragmentor(contentHandler, lexicalHandler);
123             
124             Iterator JavaDoc it = AbstractXMLDataSourceMetaData.this.getSchemaNamespaces().iterator();
125             XMLDocument fragment;
126             
127             while (it.hasNext()) {
128                 fragment = AbstractXMLDataSourceMetaData.this.getSchema((String JavaDoc)it.next());
129                 if (fragment == null) continue ;
130                 fragment.setContentHandler(fragmentor);
131                 fragment.setLexicalHandler(fragmentor);
132                 fragment.getAsSAX();
133             }
134             
135             contentHandler.endElement("", SCHEMAS_ELEMENT_NAME, "");
136             
137             // serialize path sets
138
contentHandler.startElement("", COLLECTIONS_ELEMENT_NAME, "", atts);
139             
140             it = AbstractXMLDataSourceMetaData.this.getCollectionNames().iterator();
141             
142             while (it.hasNext()) {
143                 fragment = AbstractXMLDataSourceMetaData.this.getPathSet((String JavaDoc)it.next());
144                 if (fragment == null)
145                     continue ;
146                 fragment.setContentHandler(fragmentor);
147                 fragment.setLexicalHandler(fragmentor);
148                 fragment.getAsSAX();
149             }
150             
151             contentHandler.endElement("", COLLECTIONS_ELEMENT_NAME, "");
152             
153             // end root element
154
contentHandler.endElement(XTreeReader.SOURCE_METADATA_NAMESPACE, METADATA_ELEMENT_NAME, "");
155             contentHandler.endPrefixMapping(XTreeReader.SOURCE_METADATA_PREFIX);
156             
157             // end doc
158
contentHandler.endDocument();
159         }
160         
161     }
162 }
163
Popular Tags