1 22 23 package org.xquark.xquery.xdbc; 24 25 import java.util.Collections ; 26 import java.util.Iterator ; 27 28 import org.xml.sax.helpers.AttributesImpl ; 29 import org.xquark.util.XMLDocumentFragmentor; 30 import org.xquark.xml.xdbc.*; 31 import org.xquark.xpath.XTreeReader; 32 33 36 public abstract class AbstractXMLDataSourceMetaData implements XMLDataSourceMetaData { 37 private static final String RCSRevision = "$Revision: 1.1 $"; 38 private static final String RCSName = "$Name: $"; 39 public static final String METADATA_ELEMENT_NAME = "metadata"; 40 public static final String SOURCE_ATTR = "source"; 41 public static final String SCHEMAS_ELEMENT_NAME = "schemas"; 42 public static final String COLLECTIONS_ELEMENT_NAME = "collections"; 43 44 public static final String [] 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 getCapabilities() { 66 return Collections.EMPTY_SET; 67 } 68 69 public XMLDocument getMetaData() throws XMLDBCException { 70 return new MetaDataDocument(); 71 } 72 73 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 [] getPropertyList() { 87 return PROPERTY_LIST; 88 } 89 90 private class MetaDataDocument extends AbstractXMLDocument { 94 private static final String RCSRevision = "$Revision: 1.1 $"; 95 private static final String RCSName = "$Name: $"; 96 97 private static final String 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 { 108 AttributesImpl atts = new AttributesImpl (); 109 110 contentHandler.startDocument(); 112 113 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 contentHandler.startElement("", SCHEMAS_ELEMENT_NAME, "", atts); 121 122 XMLDocumentFragmentor fragmentor = new XMLDocumentFragmentor(contentHandler, lexicalHandler); 123 124 Iterator it = AbstractXMLDataSourceMetaData.this.getSchemaNamespaces().iterator(); 125 XMLDocument fragment; 126 127 while (it.hasNext()) { 128 fragment = AbstractXMLDataSourceMetaData.this.getSchema((String )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 contentHandler.startElement("", COLLECTIONS_ELEMENT_NAME, "", atts); 139 140 it = AbstractXMLDataSourceMetaData.this.getCollectionNames().iterator(); 141 142 while (it.hasNext()) { 143 fragment = AbstractXMLDataSourceMetaData.this.getPathSet((String )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 contentHandler.endElement(XTreeReader.SOURCE_METADATA_NAMESPACE, METADATA_ELEMENT_NAME, ""); 155 contentHandler.endPrefixMapping(XTreeReader.SOURCE_METADATA_PREFIX); 156 157 contentHandler.endDocument(); 159 } 160 161 } 162 } 163 | Popular Tags |