
com.sun.tools.xjc.reader.xmlschema.bindinfo.DomHandlerEx Maven / Gradle / Ivy
Go to download
Old JAXB Binding Compiler. Contains source code needed for binding customization files into java sources.
In other words: the *tool* to generate java classes for the given xml representation.
package com.sun.tools.xjc.reader.xmlschema.bindinfo;
import javax.xml.bind.ValidationEventHandler;
import javax.xml.bind.annotation.DomHandler;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXResult;
import com.sun.xml.bind.marshaller.SAX2DOMEx;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.Locator;
import org.xml.sax.helpers.LocatorImpl;
import org.xml.sax.helpers.XMLFilterImpl;
/**
* {@link DomHandler} that produces a W3C DOM but with a location information.
*
* @author Kohsuke Kawaguchi
*/
final class DomHandlerEx implements DomHandler {
public static final class DomAndLocation {
public final Element element;
public final Locator loc;
public DomAndLocation(Element element, Locator loc) {
this.element = element;
this.loc = loc;
}
}
public ResultImpl createUnmarshaller(ValidationEventHandler errorHandler) {
return new ResultImpl();
}
public DomAndLocation getElement(ResultImpl r) {
return new DomAndLocation( ((Document)r.s2d.getDOM()).getDocumentElement(), r.location );
}
public Source marshal(DomAndLocation domAndLocation, ValidationEventHandler errorHandler) {
return new DOMSource(domAndLocation.element);
}
public static final class ResultImpl extends SAXResult {
final SAX2DOMEx s2d;
Locator location = null;
ResultImpl() {
try {
s2d = new SAX2DOMEx();
} catch (ParserConfigurationException e) {
throw new AssertionError(e); // impossible
}
XMLFilterImpl f = new XMLFilterImpl() {
public void setDocumentLocator(Locator locator) {
super.setDocumentLocator(locator);
location = new LocatorImpl(locator);
}
};
f.setContentHandler(s2d);
setHandler(f);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy