1 22 23 package org.xquark.mapper; 24 25 import java.lang.reflect.InvocationTargetException ; 26 import java.util.Collections ; 27 import java.util.HashMap ; 28 import java.util.Map ; 29 30 import org.xquark.xml.xdbc.XMLDBCException; 31 import org.xquark.xml.xdbc.XMLDataSource; 32 33 36 public final class RepositoryDriver implements org.xquark.xml.xdbc.XMLDriver 37 { 38 private static final String RCSRevision = "$Revision: 1.3 $"; 39 private static final String RCSName = "$Name: $"; 40 41 public static final String REPOSITORY_URL_PREFIX = "xdbc:xquark:repository:"; 42 43 private static RepositoryDriver instance = new RepositoryDriver(); 44 45 46 private Map openedSources = Collections.synchronizedMap(new HashMap ()); 47 48 50 private RepositoryDriver() { 51 org.xquark.xml.xdbc.XMLDriverManager.registerDriver(this); 52 } 53 54 public boolean acceptsURI(String uri) throws XMLDBCException 55 { 56 return (uri.startsWith(REPOSITORY_URL_PREFIX)); 57 } 58 59 public String getSpecificPart(String uri) throws XMLDBCException { 60 if (acceptsURI(uri)) return uri.substring(REPOSITORY_URL_PREFIX.length()); 61 else throw new XMLDBCException("Unrecognized URI "+uri); 62 } 63 64 71 public XMLDataSource getDataSource(String uri) throws XMLDBCException 72 { 73 if (!acceptsURI(uri)) 74 return null; 75 76 XMLDataSource ds = (XMLDataSource)openedSources.get(uri); 77 78 try 79 { 80 if (ds == null) 81 { 82 Class dsImpl = Class.forName("org.xquark.mapper.RepositoryDataSource"); 83 Class [] paramTypes = new Class [] {String .class}; 84 Object [] params = new Object [] { getSpecificPart(uri) }; 85 ds = (XMLDataSource)dsImpl.getConstructor(paramTypes).newInstance(params); 86 openedSources.put(uri, ds); 87 } 88 } 89 catch (InvocationTargetException e) 90 { 91 if (e.getTargetException() instanceof XMLDBCException) 92 throw (XMLDBCException)e.getTargetException(); 93 else 94 throw new RepositoryException(RepositoryException.INTERNAL_ERROR, 96 "Error while instantiating data source ", e.getTargetException()); 97 98 } 99 catch (Exception e) 100 { 101 throw new XMLDBCException("internal error : XMLDataSource implementation could not be loaded.", e); 102 } 103 return ds; 104 } 105 106 115 public XMLDataSource getDataSource(String uri, String user, String password) throws XMLDBCException { 116 return null; 117 } 118 119 } 120 | Popular Tags |