1 16 19 package org.apache.xalan.extensions; 20 21 import java.lang.reflect.Constructor ; 22 23 import javax.xml.transform.TransformerException ; 24 25 30 public class ExtensionNamespaceSupport 31 { 32 String m_namespace = null; 35 String m_handlerClass = null; 36 Class [] m_sig = null; 37 Object [] m_args = null; 38 39 public ExtensionNamespaceSupport(String namespace, 40 String handlerClass, 41 Object [] constructorArgs) 42 { 43 m_namespace = namespace; 44 m_handlerClass = handlerClass; 45 m_args = constructorArgs; 46 m_sig = new Class [m_args.length]; 48 for (int i = 0; i < m_args.length; i++) 49 { 50 if (m_args[i] != null) 51 m_sig[i] = m_args[i].getClass(); else { 54 m_sig = null; 55 break; 56 } 57 } 58 } 59 60 public String getNamespace() 61 { 62 return m_namespace; 63 } 64 65 68 public ExtensionHandler launch() 69 throws TransformerException 70 { 71 ExtensionHandler handler = null; 72 try 73 { 74 Class cl = ExtensionHandler.getClassForName(m_handlerClass); 75 Constructor con = null; 76 if (m_sig != null) 78 con = cl.getConstructor(m_sig); 79 else { 81 Constructor [] cons = cl.getConstructors(); 82 for (int i = 0; i < cons.length; i ++) 83 { 84 if (cons[i].getParameterTypes().length == m_args.length) 85 { 86 con = cons[i]; 87 break; 88 } 89 } 90 } 91 if (con != null) 93 handler = (ExtensionHandler)con.newInstance(m_args); 94 else 95 throw new TransformerException ("ExtensionHandler constructor not found"); 96 } 97 catch (Exception e) 98 { 99 throw new TransformerException (e); 100 } 101 return handler; 102 } 103 104 } 105 | Popular Tags |