FileDocCategorySizeDatePackage
SAXModelBuilder.javaAPI DocExample1998Sat Apr 23 22:35:42 BST 2005None

SAXModelBuilder

public class SAXModelBuilder extends DefaultHandler

Fields Summary
Stack
stack
SimpleElement
element
Constructors Summary
Methods Summary
public voidcharacters(char[] ch, int start, int len)

		String text = new String( ch, start, len );
		stack.peek().addText( text );
	
public voidendElement(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 SimpleElementgetModel()

 return element; 
voidsetProperty(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 voidstartElement(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 );