You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Tom Bradford <br...@dbxmlgroup.com> on 2001/06/01 00:05:01 UTC

Re: Casting down from Document

"Lors, Ben" wrote:
> Obviously before I call the process method I need to convert my Document object to its specific implementation (which could change depending on what the factory gives me).  I'm rather stumped as to how to do this.  Conceptually, I'm thinking something along the lines of:
> 
> String className = doc.getClass().getName();
> //Now cast the doc object to my className
> return process( (className)doc);
> 
> However, obviously that is not legal.  But hopefully you get the idea of what I'm trying to do--it's a little difficult to explain.  This is probably a little off-topic because it's not necessarily a Xerces specific question, but I thought that with all the Java/Document experience out there someone might have an idea for me.  Thanks in advance!

Try the instanceof operator.  

	if ( doc instanceof DocumentImpl ) 
		return process((DocumentImpl)doc);

If you won't know the classes ahead of time, you can always create an
interface, implement a handler for specific class types and then map the
class name to the handler.

-- 
Tom Bradford --- The dbXML Project --- http://www.dbxml.org/
We store your XML data a hell of a lot better than /dev/null

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org