1 16 package scriptella.jdbc; 17 18 import scriptella.expression.Expression; 19 import scriptella.spi.DriverContext; 20 import scriptella.spi.ParametersCallback; 21 22 import java.net.MalformedURLException ; 23 import java.net.URL ; 24 25 43 public class ParametersParser { 44 private DriverContext driverContext; 45 46 47 51 public ParametersParser(DriverContext driverContext) { 52 this.driverContext = driverContext; 53 } 54 55 60 public Object evaluate(final String expression, final ParametersCallback parameters) { 61 if (expression.startsWith("file ")) { 62 try { 64 final Expression ex = Expression.compile(expression.substring(5)); final Object o = ex.evaluate(parameters); 66 if (o==null) { 67 throw new JdbcException("Failed to evaluate file URL", expression); 68 } 69 if (o instanceof URL ) { 70 return Lobs.newBlob((URL ) o); 71 } else { 72 try { 73 return Lobs.newBlob(driverContext.resolve(String.valueOf(o))); 74 } catch (MalformedURLException e) { 75 throw new JdbcException("Wrong file URL \""+o+"\"", e, expression); 76 } 77 } 78 } catch (Expression.ParseException e) { 79 } 81 } 82 return Expression.compile(expression).evaluate(parameters); 83 } 84 85 } 86 | Popular Tags |