1 17 package org.apache.ws.jaxme.xs.parser.impl; 18 19 import java.lang.reflect.InvocationTargetException ; 20 import java.lang.reflect.Method ; 21 import java.lang.reflect.UndeclaredThrowableException ; 22 23 import org.apache.ws.jaxme.xs.XSParser; 24 import org.apache.ws.jaxme.xs.parser.XSContext; 25 import org.apache.ws.jaxme.xs.parser.TextSetter; 26 import org.apache.ws.jaxme.xs.parser.XsSAXParser; 27 import org.xml.sax.SAXException ; 28 29 30 33 public class TextSetterImpl implements TextSetter { 34 private static final Class [] ONE_STRING_CLASS = new Class []{String .class}; 35 36 protected XSContext getData() { 37 return XSParser.getRunningInstance().getContext(); 38 } 39 40 protected boolean isIgnorable(String pText) { 41 for (int i = 0; i < pText.length(); i++) { 42 if (!Character.isWhitespace(pText.charAt(i))) { 43 return false; 44 } 45 } 46 return true; 47 } 48 49 public void addText(String pText) throws SAXException { 50 XsSAXParser handler = (XsSAXParser) getData().getCurrentContentHandler(); 51 Object bean = handler.getBean(); 52 try { 53 Method m = bean.getClass().getMethod("addText", ONE_STRING_CLASS); 54 m.invoke(bean, new Object []{pText}); 55 } catch (NoSuchMethodException f) { 56 if (isIgnorable(pText)) { 57 return; 58 } 59 throw new IllegalStateException ("Embedded text is not supported in the '" + handler.getQName() + "' element:" + pText); 60 } catch (IllegalAccessException e) { 61 throw new IllegalStateException ("Embedded text is not supported in the '" + handler.getQName() + "' element:" + pText); 62 } catch (InvocationTargetException e) { 63 Throwable t = e.getTargetException(); 64 if (t instanceof RuntimeException ) { 65 throw (RuntimeException ) t; 66 } else if (t instanceof SAXException ) { 67 throw (SAXException ) t; 68 } else { 69 throw new UndeclaredThrowableException (t); 70 } 71 } 72 } 73 } 74 | Popular Tags |