List of usage examples for org.xml.sax ErrorHandler error
public abstract void error(SAXParseException exception) throws SAXException;
From source file:io.fares.bind.xjc.plugins.substitution.SubstitutionPlugin.java
@Override public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) throws SAXException { for (ClassOutline classOutline : outline.getClasses()) { // now in part 2 of the transformation we need to traverse the generated field declarations // find our plugin customization and swap @XmlElement for @XmlElementRef for (FieldOutline fieldOutline : classOutline.getDeclaredFields()) { // REVIEW AV: This does not feel quite right. You create a CElementPropertyInfo property // but then hack it to use another annotation. This is not good since your generated code does // not represent your model anymore. This may cause problem to other tools/plugins. CPropertyInfo propertyInfo = fieldOutline.getPropertyInfo(); // check field property customization boolean hasHeadRef = Customisation.hasCustomizationsInProperty(propertyInfo, SUBSTITUTION_HEAD_REF_NAME); // FIXME should not need to do this here but customization gets mixed up when we replace the Ref with // Element field in the model transformation. hasHeadRef = Customisation.hasCustomizationsInProperty(propertyInfo, SUBSTITUTION_HEAD_NAME) || hasHeadRef;//from w w w .j a va 2 s .co m // check if the referenced type is the subsctitution head // FIXME currently only able to add the customization on the complexType and not the element boolean hasHead = false; for (CTypeInfo typeInfo : propertyInfo.ref()) { hasHead = hasHead || Customisation.hasCustomizationsInType(typeInfo, SUBSTITUTION_HEAD_NAME); } if (hasHeadRef || hasHead) { // can be changed to containsKey and getKey for (JFieldVar field : classOutline.ref.fields().values()) { if (propertyInfo.getName(false).equals(field.name())) { JFieldVar jFieldVar = classOutline.ref.fields().get(propertyInfo.getName(false)); for (JAnnotationUse annotation : jFieldVar.annotations()) { JClass acl = annotation.getAnnotationClass(); if (XmlElement.class.getName().equals(acl.fullName())) { try { // swap XmlElement for XmlElementRef FieldUtils.writeField(annotation, "clazz", outline.getCodeModel().ref(XmlElementRef.class), true); // TODO inspect params to make sure we don't transfer [nillable|defaultValue] } catch (IllegalAccessException e) { errorHandler.error(new SAXParseException( "The substitution plugin is prevented from modifying an inaccessible field in the XJC model (generation time only). Please ensure your security manager is configured correctly.", propertyInfo.getLocator(), e)); return false; } catch (IllegalArgumentException e) { errorHandler.error(new SAXParseException( "The substitution plugin encountered an internal error extracting the generated field details.", propertyInfo.getLocator(), e)); return false; } } } } } } } } return true; }
From source file:nl.nn.adapterframework.align.ToXml.java
public void handleError(String msg) throws SAXException { ErrorHandler errorHandler = validatorHandler.getErrorHandler(); if (errorHandler != null) { errorHandler.error(new SAXParseException(msg, null)); } else {//from ww w . ja v a2 s .c om throw new SAXException(msg); } }
From source file:nl.nn.adapterframework.align.ToXml.java
public void handleError(SAXException e) throws SAXException { ErrorHandler errorHandler = validatorHandler.getErrorHandler(); if (errorHandler != null) { errorHandler.error(new SAXParseException(e.getMessage(), null)); } else {//from ww w. ja va 2 s . c o m throw e; } }
From source file:org.kalypso.gml.GMLSAXFactory.java
private void processValueType(final IValuePropertyType pt, final Object propertyValue, final QName prefixedQName) throws SAXException { final IMarshallingTypeHandler th = pt.getTypeHandler(); if (th instanceof ISimpleMarshallingTypeHandler<?>) { final String xmlString = printSimpleValue(pt, (ISimpleMarshallingTypeHandler<Object>) th, propertyValue);/* w w w .ja v a2 s . c o m*/ if (xmlString != null) { // FIXME: this is the right place to write CDATA stuff, but of course now it is a wild hack // to look for a specific value. This must of course be decided in a more general way. // Maybe we register extensions for specific qnames? // TODO: also, it should be only done for String, i.e. in the XsdBaseTypeHandlerString final boolean doCData = prefixedQName.equals(new QName(NS.OM, "result")); final LexicalHandler lexicalHandler = doCData ? (LexicalHandler) m_reader.getProperty("http://xml.org/sax/properties/lexical-handler") : null; if (doCData) lexicalHandler.startCDATA(); m_reader.getContentHandler().characters(xmlString.toCharArray(), 0, xmlString.length()); if (doCData) lexicalHandler.endCDATA(); } return; } if (propertyValue != null) { try { th.marshal(propertyValue, m_reader, null, m_gmlVersion); } catch (final Exception e) { // Catch any exception here: we should always continue to write data in order to minimise data loss here // TODO: we need an error handler! Else the user does not get any information about errors // TODO Distinguish between normal exceptions and SaxParseException final ErrorHandler errorHandler = m_reader.getErrorHandler(); if (errorHandler == null) KalypsoDeegreePlugin.getDefault().getLog().log(StatusUtilities.statusFromThrowable(e)); else errorHandler .error(new SAXParseException("Failed to write property: " + pt.getQName(), null, e)); } } }