use of com.sun.istack.SAXParseException2 in project jaxb-ri by eclipse-ee4j.
the class SCDBasedBindingSet method reportError.
private void reportError(Element errorSource, String formattedMsg, Exception nestedException) {
SAXParseException e = new SAXParseException2(formattedMsg, forest.locatorTable.getStartLocation(errorSource), nestedException);
errorReceiver.error(e);
}
use of com.sun.istack.SAXParseException2 in project jaxb-ri by eclipse-ee4j.
the class AbstractReferenceFinderImpl method startElement.
@Override
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
super.startElement(namespaceURI, localName, qName, atts);
String relativeRef = findExternalResource(namespaceURI, localName, atts);
if (relativeRef == null) {
// not found
return;
}
try {
// absolutize URL.
String lsi = locator.getSystemId();
String ref;
URI relRefURI = new URI(relativeRef);
if (relRefURI.isAbsolute())
ref = relativeRef;
else {
if (lsi.startsWith("jar:")) {
int bangIdx = lsi.indexOf('!');
if (bangIdx > 0) {
ref = lsi.substring(0, bangIdx + 1) + new URI(lsi.substring(bangIdx + 1)).resolve(new URI(relativeRef));
} else {
ref = relativeRef;
}
} else {
ref = new URI(lsi).resolve(new URI(relativeRef)).toString();
}
}
// but don't mark this document as a root.
if (parent != null) {
// this is there to allow easier testing
parent.parse(ref, false);
}
} catch (URISyntaxException e) {
String msg = e.getMessage();
if (new File(relativeRef).exists()) {
msg = Messages.format(Messages.ERR_FILENAME_IS_NOT_URI) + ' ' + msg;
}
SAXParseException spe = new SAXParseException2(Messages.format(Messages.ERR_UNABLE_TO_PARSE, relativeRef, msg), locator, e);
fatalError(spe);
throw spe;
} catch (IOException e) {
SAXParseException spe = new SAXParseException2(Messages.format(Messages.ERR_UNABLE_TO_PARSE, relativeRef, e.getMessage()), locator, e);
fatalError(spe);
throw spe;
}
}
use of com.sun.istack.SAXParseException2 in project jaxb-ri by eclipse-ee4j.
the class TDTDReader method parse.
/**
* Parses DTD grammar and a binding information into BGM.
*
* <p>
* This method is just a utility method that covers 80% of the use
* cases.
*
* @param bindingInfo
* binding information file, if any. Can be null.
*/
public static Model parse(InputSource dtd, InputSource bindingInfo, ErrorReceiver errorReceiver, Options opts) {
try {
// set up a ring
final Ring old = Ring.begin();
try {
ErrorReceiverFilter ef = new ErrorReceiverFilter(errorReceiver);
JCodeModel cm = new JCodeModel();
Model model = new Model(opts, cm, NameConverter.standard, opts.classNameAllocator, null);
Ring.add(cm);
Ring.add(model);
Ring.add(ErrorReceiver.class, ef);
TDTDReader reader = new TDTDReader(ef, opts, bindingInfo);
DTDParser parser = new DTDParser();
parser.setDtdHandler(reader);
if (opts.entityResolver != null)
parser.setEntityResolver(opts.entityResolver);
try {
parser.parse(dtd);
} catch (SAXParseException e) {
// this error was already handled by GrammarReaderController
return null;
}
Ring.get(ModelChecker.class).check();
if (ef.hadError())
return null;
else
return model;
} finally {
Ring.end(old);
}
} catch (IOException | SAXException e) {
errorReceiver.error(new SAXParseException2(e.getMessage(), null, e));
return null;
} catch (AbortException e) {
// parsing was aborted but the error was already reported
return null;
}
}
use of com.sun.istack.SAXParseException2 in project jaxb-ri by eclipse-ee4j.
the class UnmarshallingContext method handleEvent.
//
//
// error handling
//
//
/**
* Reports an error to the user, and asks if s/he wants
* to recover. If the canRecover flag is false, regardless
* of the client instruction, an exception will be thrown.
*
* Only if the flag is true and the user wants to recover from an error,
* the method returns normally.
*
* The thrown exception will be catched by the unmarshaller.
*/
public void handleEvent(ValidationEvent event, boolean canRecover) throws SAXException {
ValidationEventHandler eventHandler = parent.getEventHandler();
boolean recover = eventHandler.handleEvent(event);
// from the unmarshaller.getResult()
if (!recover)
aborted = true;
if (!canRecover || !recover)
throw new SAXParseException2(event.getMessage(), locator, new UnmarshalException(event.getMessage(), event.getLinkedException()));
}
use of com.sun.istack.SAXParseException2 in project metro-jax-ws by eclipse-ee4j.
the class Internalizer method reportError.
private void reportError(Element errorSource, String formattedMsg, Exception nestedException) {
SAXParseException e = new SAXParseException2(formattedMsg, forest.locatorTable.getStartLocation(errorSource), nestedException);
errorReceiver.error(e);
}
Aggregations