1 61 62 63 64 65 package org.jaxen.saxpath.helpers; 66 67 import org.jaxen.saxpath.SAXPathException; 68 import org.jaxen.saxpath.XPathReader; 69 70 81 public class XPathReaderFactory 82 { 83 84 public static final String DRIVER_PROPERTY = "org.saxpath.driver"; 85 86 87 protected static final String DEFAULT_DRIVER = "org.jaxen.saxpath.base.XPathReader"; 88 89 private XPathReaderFactory() {} 90 91 92 103 public static XPathReader createReader() throws SAXPathException 104 { 105 String className = null; 106 107 try 108 { 109 className = System.getProperty( DRIVER_PROPERTY ); 110 } 111 catch (SecurityException e) 112 { 113 } 115 116 if ( className == null 117 || 118 className.length() == 0 ) 119 { 120 className = DEFAULT_DRIVER; 121 } 122 123 return createReader( className ); 124 } 125 126 139 public static XPathReader createReader(String className) throws SAXPathException 140 { 141 Class readerClass = null; 142 XPathReader reader = null; 143 144 try 145 { 146 150 readerClass = Class.forName( className, 151 true, 152 XPathReaderFactory.class.getClassLoader() ); 153 154 157 if ( ! XPathReader.class.isAssignableFrom( readerClass ) ) 158 { 159 throw new SAXPathException( "Class [" + className 160 + "] does not implement the org.jaxen.saxpath.XPathReader interface." ); 161 } 162 } 163 catch (ClassNotFoundException e) 164 { 165 throw new SAXPathException( e ); 166 } 167 168 try 169 { 170 reader = (XPathReader) readerClass.newInstance(); 171 } 172 catch (IllegalAccessException e) 173 { 174 throw new SAXPathException( e ); 175 } 176 catch (InstantiationException e) 177 { 178 throw new SAXPathException( e ); 179 } 180 181 if ( reader == null ) 182 { 183 throw new SAXPathException( "Unable to create XPathReader" ); 184 } 185 186 return reader; 187 } 188 } 189 | Popular Tags |