1 22 23 package org.xquark.xquery.metadata; 24 25 import java.lang.reflect.Constructor ; 26 import java.lang.reflect.InvocationTargetException ; 27 import java.util.Date ; 28 import java.util.TimeZone ; 29 30 import org.xquark.xquery.JavaModule; 31 import org.xquark.xquery.parser.*; 32 33 public class DynamicContext { 34 35 private Date currentDateTime = null; 36 private TimeZone currentTimeZone = null; 37 38 private JavaInvoker javaInvoker = new JavaInvoker(); 39 40 public DynamicContext() {} 41 42 public Object invoke(LibraryFunctionCall lfc, Object [] params) throws XQueryException { 43 QName funcName = lfc.getFuncName(); 44 int index = funcName.getNameSpace().indexOf(':'); 45 String type = funcName.getNameSpace().substring(0,index); 46 if (type.equals("java")) 47 return javaInvoker.invoke(lfc,params); 48 return null; 49 } 50 51 public void addImportModule(XQueryModule module) throws XQueryException { 52 if (module instanceof JavaModule) { 53 try { 54 JavaModule mod = (JavaModule) module; 55 Class javaClass = mod.getJavaClass(); 56 Class [] classes = null; 57 Constructor constructor = javaClass.getConstructor(classes); 58 Object obj = constructor.newInstance(null); 59 javaInvoker.addClass(javaClass.getName(), obj); 60 } catch (InvocationTargetException e) { 61 throw new XQueryException("Could not import module " + module.getNamespace()); 62 } catch (IllegalAccessException e) { 63 throw new XQueryException("Could not import module " + module.getNamespace()); 64 } catch (InstantiationException e) { 65 throw new XQueryException("Could not import module " + module.getNamespace()); 66 } catch (NoSuchMethodException e) { 67 throw new XQueryException("Could not import module " + module.getNamespace()); 68 } 69 } 70 } 71 } 72 | Popular Tags |