1 22 23 package org.xquark.mediator; 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.*; 31 32 public class MediatorDriver implements XMLDriver { 33 private static final String RCSRevision = "$Revision: 1.10 $"; 37 private static final String RCSName = "$Name: $"; 38 39 public static final String MEDIATOR_URL_PREFIX = "xdbc:xquark:mediator:"; 40 private static MediatorDriver instance = new MediatorDriver(); 44 45 static private Map datasources = Collections.synchronizedMap(new HashMap ()); 46 47 private MediatorDriver() { 51 XMLDriverManager.registerDriver(this); 52 } 53 54 58 public boolean acceptsURI(String uri) throws XMLDBCException { 59 return uri != null && uri.startsWith(MEDIATOR_URL_PREFIX); 60 } 61 62 public String getSpecificPart(String uri) throws XMLDBCException { 63 if (acceptsURI(uri)) return uri.substring(MEDIATOR_URL_PREFIX.length()); 64 else throw new XMLDBCException("Unrecognized URI "+uri); 65 } 66 67 74 public XMLDataSource getDataSource(String uri) throws XMLDBCException { 75 if (!acceptsURI(uri)) return null; 76 String confURL = getSpecificPart(uri); 77 XMLDataSource source = (XMLDataSource) datasources.get(confURL); 78 if (source != null) return source; 79 try { 80 Class dsImpl = Class.forName("org.xquark.mediator.Mediator"); 81 if (confURL.length() == 0) { 82 source = (XMLDataSource)dsImpl.newInstance(); 83 } else { 84 Class [] paramTypes = new Class [] { String .class }; 85 Object [] params = new Object [] { confURL }; 86 source = (XMLDataSource)dsImpl.getConstructor(paramTypes).newInstance(params); 87 } 88 datasources.put(confURL, source); 89 return source; 90 } catch (ClassNotFoundException e) { 91 return null; 92 } catch (IllegalArgumentException e) { 93 return null; 94 } catch (SecurityException e) { 95 return null; 96 } catch (InstantiationException e) { 97 return null; 98 } catch (IllegalAccessException e) { 99 return null; 100 } catch (InvocationTargetException e) { 101 return null; 102 } catch (NoSuchMethodException e) { 103 return null; 104 } 105 } 106 107 116 public XMLDataSource getDataSource(String uri, String user, String password) throws XMLDBCException { 117 return null; 118 } 119 120 } 121 | Popular Tags |