SAXModelBuilderpublic class SAXModelBuilder extends DefaultHandler
Fields Summary |
---|
Stack | stack | SimpleElement | element |
Methods Summary |
---|
public void | characters(char[] ch, int start, int len)
String text = new String( ch, start, len );
stack.peek().addText( text );
| public void | endElement(java.lang.String namespace, java.lang.String localname, java.lang.String qname)
element = stack.pop();
if ( !stack.empty() )
try {
setProperty( qname, stack.peek(), element );
} catch ( Exception e ) { throw new SAXException( "Error: "+e ); }
| public SimpleElement | getModel() return element;
| void | setProperty(java.lang.String name, java.lang.Object target, java.lang.Object value)
Method method = null;
try {
method = target.getClass().getMethod("add"+name, value.getClass());
} catch ( NoSuchMethodException e ) { }
if ( method == null ) try {
method = target.getClass().getMethod("set"+name, value.getClass());
} catch ( NoSuchMethodException e ) { }
if ( method == null ) try {
value = ((SimpleElement)value).getText();
method = target.getClass().getMethod( "add"+name, String.class );
} catch ( NoSuchMethodException e ) { }
try {
if ( method == null )
method = target.getClass().getMethod("set"+name, String.class);
method.invoke( target, value );
} catch ( Exception e ) { throw new SAXException( e.toString() ); }
| public void | startElement(java.lang.String namespace, java.lang.String localname, java.lang.String qname, org.xml.sax.Attributes atts)
SimpleElement element = null;
try {
element = (SimpleElement)Class.forName(qname).newInstance();
} catch ( Exception e ) { }
if ( element == null )
element = new SimpleElement();
for(int i=0; i<atts.getLength(); i++)
element.setAttributeValue( atts.getQName(i), atts.getValue(i) );
stack.push( element );
|
|