javax.xml.bind.helpers.ValidationEventImpl Java Examples
The following examples show how to use
javax.xml.bind.helpers.ValidationEventImpl.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Coordinator.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
private void propagateEvent( int severity, SAXParseException saxException ) throws SAXException { ValidationEventImpl ve = new ValidationEventImpl( severity, saxException.getMessage(), getLocation() ); Exception e = saxException.getException(); if( e != null ) { ve.setLinkedException( e ); } else { ve.setLinkedException( saxException ); } // call the client's event handler. If it returns false, then bail-out // and terminate the unmarshal operation. boolean result = handleEvent( ve ); if( ! result ) { // bail-out of the parse with a SAX exception, but convert it into // an UnmarshalException back in in the AbstractUnmarshaller throw saxException; } }
Example #2
Source File: ClassBeanInfoImpl.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public void serializeRoot(BeanT bean, XMLSerializer target) throws SAXException, IOException, XMLStreamException { if(tagName==null) { Class beanClass = bean.getClass(); String message; if (beanClass.isAnnotationPresent(XmlRootElement.class)) { message = Messages.UNABLE_TO_MARSHAL_UNBOUND_CLASS.format(beanClass.getName()); } else { message = Messages.UNABLE_TO_MARSHAL_NON_ELEMENT.format(beanClass.getName()); } target.reportError(new ValidationEventImpl(ValidationEvent.ERROR,message,null, null)); } else { target.startElement(tagName,bean); target.childAsSoleContent(bean,null); target.endElement(); if (retainPropertyInfo) { target.currentProperty.remove(); } } }
Example #3
Source File: RuntimeBuiltinLeafInfoImpl.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
public String print(XMLGregorianCalendar cal) { XMLSerializer xs = XMLSerializer.getInstance(); QName type = xs.getSchemaType(); if (type != null) { try { checkXmlGregorianCalendarFieldRef(type, cal); String format = xmlGregorianCalendarFormatString.get(type); if (format != null) { return format(format, cal); } } catch (javax.xml.bind.MarshalException e) { // see issue 649 xs.handleEvent(new ValidationEventImpl(ValidationEvent.WARNING, e.getMessage(), xs.getCurrentLocation(null) )); return ""; } } return cal.toXMLFormat(); }
Example #4
Source File: RuntimeBuiltinLeafInfoImpl.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public String print(XMLGregorianCalendar cal) { XMLSerializer xs = XMLSerializer.getInstance(); QName type = xs.getSchemaType(); if (type != null) { try { checkXmlGregorianCalendarFieldRef(type, cal); String format = xmlGregorianCalendarFormatString.get(type); if (format != null) { return format(format, cal); } } catch (javax.xml.bind.MarshalException e) { // see issue 649 xs.handleEvent(new ValidationEventImpl(ValidationEvent.WARNING, e.getMessage(), xs.getCurrentLocation(null) )); return ""; } } return cal.toXMLFormat(); }
Example #5
Source File: Coordinator.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private void propagateEvent( int severity, SAXParseException saxException ) throws SAXException { ValidationEventImpl ve = new ValidationEventImpl( severity, saxException.getMessage(), getLocation() ); Exception e = saxException.getException(); if( e != null ) { ve.setLinkedException( e ); } else { ve.setLinkedException( saxException ); } // call the client's event handler. If it returns false, then bail-out // and terminate the unmarshal operation. boolean result = handleEvent( ve ); if( ! result ) { // bail-out of the parse with a SAX exception, but convert it into // an UnmarshalException back in in the AbstractUnmarshaller throw saxException; } }
Example #6
Source File: RuntimeBuiltinLeafInfoImpl.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
public String print(XMLGregorianCalendar cal) { XMLSerializer xs = XMLSerializer.getInstance(); QName type = xs.getSchemaType(); if (type != null) { try { checkXmlGregorianCalendarFieldRef(type, cal); String format = xmlGregorianCalendarFormatString.get(type); if (format != null) { return format(format, cal); } } catch (javax.xml.bind.MarshalException e) { // see issue 649 xs.handleEvent(new ValidationEventImpl(ValidationEvent.WARNING, e.getMessage(), xs.getCurrentLocation(null) )); return ""; } } return cal.toXMLFormat(); }
Example #7
Source File: ClassBeanInfoImpl.java From hottub with GNU General Public License v2.0 | 6 votes |
public void serializeRoot(BeanT bean, XMLSerializer target) throws SAXException, IOException, XMLStreamException { if(tagName==null) { Class beanClass = bean.getClass(); String message; if (beanClass.isAnnotationPresent(XmlRootElement.class)) { message = Messages.UNABLE_TO_MARSHAL_UNBOUND_CLASS.format(beanClass.getName()); } else { message = Messages.UNABLE_TO_MARSHAL_NON_ELEMENT.format(beanClass.getName()); } target.reportError(new ValidationEventImpl(ValidationEvent.ERROR,message,null, null)); } else { target.startElement(tagName,bean); target.childAsSoleContent(bean,null); target.endElement(); if (retainPropertyInfo) { target.currentProperty.remove(); } } }
Example #8
Source File: ClassBeanInfoImpl.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
public void serializeRoot(BeanT bean, XMLSerializer target) throws SAXException, IOException, XMLStreamException { if(tagName==null) { Class beanClass = bean.getClass(); String message; if (beanClass.isAnnotationPresent(XmlRootElement.class)) { message = Messages.UNABLE_TO_MARSHAL_UNBOUND_CLASS.format(beanClass.getName()); } else { message = Messages.UNABLE_TO_MARSHAL_NON_ELEMENT.format(beanClass.getName()); } target.reportError(new ValidationEventImpl(ValidationEvent.ERROR,message,null, null)); } else { target.startElement(tagName,bean); target.childAsSoleContent(bean,null); target.endElement(); if (retainPropertyInfo) { target.currentProperty.remove(); } } }
Example #9
Source File: RuntimeBuiltinLeafInfoImpl.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public String print(XMLGregorianCalendar cal) { XMLSerializer xs = XMLSerializer.getInstance(); QName type = xs.getSchemaType(); if (type != null) { try { checkXmlGregorianCalendarFieldRef(type, cal); String format = xmlGregorianCalendarFormatString.get(type); if (format != null) { return format(format, cal); } } catch (javax.xml.bind.MarshalException e) { // see issue 649 xs.handleEvent(new ValidationEventImpl(ValidationEvent.WARNING, e.getMessage(), xs.getCurrentLocation(null) )); return ""; } } return cal.toXMLFormat(); }
Example #10
Source File: Coordinator.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private void propagateEvent( int severity, SAXParseException saxException ) throws SAXException { ValidationEventImpl ve = new ValidationEventImpl( severity, saxException.getMessage(), getLocation() ); Exception e = saxException.getException(); if( e != null ) { ve.setLinkedException( e ); } else { ve.setLinkedException( saxException ); } // call the client's event handler. If it returns false, then bail-out // and terminate the unmarshal operation. boolean result = handleEvent( ve ); if( ! result ) { // bail-out of the parse with a SAX exception, but convert it into // an UnmarshalException back in in the AbstractUnmarshaller throw saxException; } }
Example #11
Source File: RuntimeBuiltinLeafInfoImpl.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
public String print(XMLGregorianCalendar cal) { XMLSerializer xs = XMLSerializer.getInstance(); QName type = xs.getSchemaType(); if (type != null) { try { checkXmlGregorianCalendarFieldRef(type, cal); String format = xmlGregorianCalendarFormatString.get(type); if (format != null) { return format(format, cal); } } catch (javax.xml.bind.MarshalException e) { // see issue 649 xs.handleEvent(new ValidationEventImpl(ValidationEvent.WARNING, e.getMessage(), xs.getCurrentLocation(null) )); return ""; } } return cal.toXMLFormat(); }
Example #12
Source File: ClassBeanInfoImpl.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
public void serializeRoot(BeanT bean, XMLSerializer target) throws SAXException, IOException, XMLStreamException { if(tagName==null) { Class beanClass = bean.getClass(); String message; if (beanClass.isAnnotationPresent(XmlRootElement.class)) { message = Messages.UNABLE_TO_MARSHAL_UNBOUND_CLASS.format(beanClass.getName()); } else { message = Messages.UNABLE_TO_MARSHAL_NON_ELEMENT.format(beanClass.getName()); } target.reportError(new ValidationEventImpl(ValidationEvent.ERROR,message,null, null)); } else { target.startElement(tagName,bean); target.childAsSoleContent(bean,null); target.endElement(); if (retainPropertyInfo) { target.currentProperty.remove(); } } }
Example #13
Source File: RuntimeBuiltinLeafInfoImpl.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
public String print(XMLGregorianCalendar cal) { XMLSerializer xs = XMLSerializer.getInstance(); QName type = xs.getSchemaType(); if (type != null) { try { checkXmlGregorianCalendarFieldRef(type, cal); String format = xmlGregorianCalendarFormatString.get(type); if (format != null) { return format(format, cal); } } catch (javax.xml.bind.MarshalException e) { // see issue 649 xs.handleEvent(new ValidationEventImpl(ValidationEvent.WARNING, e.getMessage(), xs.getCurrentLocation(null) )); return ""; } } return cal.toXMLFormat(); }
Example #14
Source File: ClassBeanInfoImpl.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
public void serializeRoot(BeanT bean, XMLSerializer target) throws SAXException, IOException, XMLStreamException { if(tagName==null) { Class beanClass = bean.getClass(); String message; if (beanClass.isAnnotationPresent(XmlRootElement.class)) { message = Messages.UNABLE_TO_MARSHAL_UNBOUND_CLASS.format(beanClass.getName()); } else { message = Messages.UNABLE_TO_MARSHAL_NON_ELEMENT.format(beanClass.getName()); } target.reportError(new ValidationEventImpl(ValidationEvent.ERROR,message,null, null)); } else { target.startElement(tagName,bean); target.childAsSoleContent(bean,null); target.endElement(); if (retainPropertyInfo) { target.currentProperty.remove(); } } }
Example #15
Source File: RuntimeBuiltinLeafInfoImpl.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public Base64Data print(Image v) { ByteArrayOutputStreamEx imageData = new ByteArrayOutputStreamEx(); XMLSerializer xs = XMLSerializer.getInstance(); String mimeType = xs.getXMIMEContentType(); if(mimeType==null || mimeType.startsWith("image/*")) // because PNG is lossless, it's a good default // // mime type can be a range, in which case we can't just pass that // to ImageIO.getImageWritersByMIMEType, so here I'm just assuming // the default of PNG. Not sure if this is complete. mimeType = "image/png"; try { Iterator<ImageWriter> itr = ImageIO.getImageWritersByMIMEType(mimeType); if(itr.hasNext()) { ImageWriter w = itr.next(); ImageOutputStream os = ImageIO.createImageOutputStream(imageData); w.setOutput(os); w.write(convertToBufferedImage(v)); os.close(); w.dispose(); } else { // no encoder xs.handleEvent(new ValidationEventImpl( ValidationEvent.ERROR, Messages.NO_IMAGE_WRITER.format(mimeType), xs.getCurrentLocation(null) )); // TODO: proper error reporting throw new RuntimeException("no encoder for MIME type "+mimeType); } } catch (IOException e) { xs.handleError(e); // TODO: proper error reporting throw new RuntimeException(e); } Base64Data bd = new Base64Data(); imageData.set(bd,mimeType); return bd; }
Example #16
Source File: ArrayBeanInfoImpl.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
public final void serializeRoot(Object array, XMLSerializer target) throws SAXException, IOException, XMLStreamException { target.reportError( new ValidationEventImpl( ValidationEvent.ERROR, Messages.UNABLE_TO_MARSHAL_NON_ELEMENT.format(array.getClass().getName()), null, null)); }
Example #17
Source File: UnmarshallingContext.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * Called when there's no corresponding ID value. */ public void errorUnresolvedIDREF(Object bean, String idref, LocatorEx loc) throws SAXException { handleEvent( new ValidationEventImpl( ValidationEvent.ERROR, Messages.UNRESOLVED_IDREF.format(idref), loc.getLocation()), true ); }
Example #18
Source File: XMLSerializer.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * Called when a referenced object doesn't have an ID. */ public void errorMissingId(Object obj) throws SAXException { reportError( new ValidationEventImpl( ValidationEvent.ERROR, Messages.MISSING_ID.format(obj), new ValidationEventLocatorImpl(obj)) ); }
Example #19
Source File: XMLSerializer.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
private void reportMissingObjectError(String fieldName) throws SAXException { reportError(new ValidationEventImpl( ValidationEvent.ERROR, Messages.MISSING_OBJECT.format(fieldName), getCurrentLocation(fieldName), new NullPointerException() )); }
Example #20
Source File: UnmarshallingContext.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * Based on current {@link Logger} {@link Level} and errorCounter value determines if error should be reported. * * If the method called and return true it is expected that error will be reported. And that's why * errorCounter is automatically decremented during the check. * * NOT THREAD SAFE!!! In case of heave concurrency access several additional errors could be reported. It's not expected to be the * problem. Otherwise add synchronization here. * * @return true in case if {@link Level#FINEST} is set OR we haven't exceed errors reporting limit. */ public boolean shouldErrorBeReported() throws SAXException { if (logger.isLoggable(Level.FINEST)) return true; if (errorsCounter >= 0) { --errorsCounter; if (errorsCounter == 0) // it's possible to miss this because of concurrency. If required add synchronization here handleEvent(new ValidationEventImpl(ValidationEvent.WARNING, Messages.ERRORS_LIMIT_EXCEEDED.format(), getLocator().getLocation(), null), true); } return errorsCounter >= 0; }
Example #21
Source File: Loader.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void reportError(String msg, Exception nested, boolean canRecover) throws SAXException { UnmarshallingContext context = UnmarshallingContext.getInstance(); context.handleEvent( new ValidationEventImpl( canRecover? ValidationEvent.ERROR : ValidationEvent.FATAL_ERROR, msg, context.getLocator().getLocation(), nested ), canRecover ); }
Example #22
Source File: XMLSerializer.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
private void reportMissingObjectError(String fieldName) throws SAXException { reportError(new ValidationEventImpl( ValidationEvent.ERROR, Messages.MISSING_OBJECT.format(fieldName), getCurrentLocation(fieldName), new NullPointerException() )); }
Example #23
Source File: AnyTypeBeanInfo.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public void serializeRoot(Object element, XMLSerializer target) throws SAXException { target.reportError( new ValidationEventImpl( ValidationEvent.ERROR, Messages.UNABLE_TO_MARSHAL_NON_ELEMENT.format(element.getClass().getName()), null, null)); }
Example #24
Source File: LeafBeanInfoImpl.java From hottub with GNU General Public License v2.0 | 5 votes |
public final void serializeRoot(BeanT bean, XMLSerializer target) throws SAXException, IOException, XMLStreamException { if(tagName==null) { target.reportError( new ValidationEventImpl( ValidationEvent.ERROR, Messages.UNABLE_TO_MARSHAL_NON_ELEMENT.format(bean.getClass().getName()), null, null)); } else { target.startElement(tagName,bean); target.childAsSoleContent(bean,null); target.endElement(); } }
Example #25
Source File: CompositeStructureBeanInfo.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
public void serializeRoot(CompositeStructure o, XMLSerializer target) throws SAXException, IOException, XMLStreamException { target.reportError( new ValidationEventImpl( ValidationEvent.ERROR, Messages.UNABLE_TO_MARSHAL_NON_ELEMENT.format(o.getClass().getName()), null, null)); }
Example #26
Source File: CompositeStructureBeanInfo.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public void serializeRoot(CompositeStructure o, XMLSerializer target) throws SAXException, IOException, XMLStreamException { target.reportError( new ValidationEventImpl( ValidationEvent.ERROR, Messages.UNABLE_TO_MARSHAL_NON_ELEMENT.format(o.getClass().getName()), null, null)); }
Example #27
Source File: XMLSerializer.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Pushes the object to {@link #cycleDetectionStack} and also * detect any cycles. * * When a cycle is found, this method tries to recover from it. * * @return * the object that should be marshalled instead of the given <tt>obj</tt>, * or null if the error is found and we need to avoid marshalling this object * to prevent infinite recursion. When this method returns null, the error * has already been reported. */ private Object pushObject(Object obj, String fieldName) throws SAXException { if(!cycleDetectionStack.push(obj)) return obj; // allow the object to nominate its replacement if(obj instanceof CycleRecoverable) { obj = ((CycleRecoverable)obj).onCycleDetected(new CycleRecoverable.Context(){ public Marshaller getMarshaller() { return marshaller; } }); if(obj!=null) { // object nominated its replacement. // we still need to make sure that the nominated. // this may cause inifinite recursion on its own. cycleDetectionStack.pop(); return pushObject(obj,fieldName); } else return null; } // cycle detected and no one is catching the error. reportError(new ValidationEventImpl( ValidationEvent.ERROR, Messages.CYCLE_IN_MARSHALLER.format(cycleDetectionStack.getCycleString()), getCurrentLocation(fieldName), null)); return null; }
Example #28
Source File: XMLSerializer.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Pushes the object to {@link #cycleDetectionStack} and also * detect any cycles. * * When a cycle is found, this method tries to recover from it. * * @return * the object that should be marshalled instead of the given {@code obj}, * or null if the error is found and we need to avoid marshalling this object * to prevent infinite recursion. When this method returns null, the error * has already been reported. */ private Object pushObject(Object obj, String fieldName) throws SAXException { if(!cycleDetectionStack.push(obj)) return obj; // allow the object to nominate its replacement if(obj instanceof CycleRecoverable) { obj = ((CycleRecoverable)obj).onCycleDetected(new CycleRecoverable.Context(){ public Marshaller getMarshaller() { return marshaller; } }); if(obj!=null) { // object nominated its replacement. // we still need to make sure that the nominated. // this may cause inifinite recursion on its own. cycleDetectionStack.pop(); return pushObject(obj,fieldName); } else return null; } // cycle detected and no one is catching the error. reportError(new ValidationEventImpl( ValidationEvent.ERROR, Messages.CYCLE_IN_MARSHALLER.format(cycleDetectionStack.getCycleString()), getCurrentLocation(fieldName), null)); return null; }
Example #29
Source File: CompositeStructureBeanInfo.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public void serializeRoot(CompositeStructure o, XMLSerializer target) throws SAXException, IOException, XMLStreamException { target.reportError( new ValidationEventImpl( ValidationEvent.ERROR, Messages.UNABLE_TO_MARSHAL_NON_ELEMENT.format(o.getClass().getName()), null, null)); }
Example #30
Source File: ArrayBeanInfoImpl.java From hottub with GNU General Public License v2.0 | 5 votes |
public final void serializeRoot(Object array, XMLSerializer target) throws SAXException, IOException, XMLStreamException { target.reportError( new ValidationEventImpl( ValidationEvent.ERROR, Messages.UNABLE_TO_MARSHAL_NON_ELEMENT.format(array.getClass().getName()), null, null)); }