类javax.xml.bind.helpers.ValidationEventImpl源码实例Demo

下面列出了怎么用javax.xml.bind.helpers.ValidationEventImpl的API类实例代码及写法,或者点击链接到github查看源代码。

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();
}
 
源代码2 项目: TencentKona-8   文件: ClassBeanInfoImpl.java
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();
        }
    }
}
 
源代码3 项目: openjdk-8   文件: RuntimeBuiltinLeafInfoImpl.java
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();
}
 
源代码4 项目: openjdk-jdk9   文件: Coordinator.java
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;
    }
}
 
源代码5 项目: jdk8u60   文件: RuntimeBuiltinLeafInfoImpl.java
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();
}
 
源代码6 项目: hottub   文件: ClassBeanInfoImpl.java
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();
        }
    }
}
 
源代码7 项目: openjdk-8   文件: ClassBeanInfoImpl.java
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();
        }
    }
}
 
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();
}
 
源代码9 项目: openjdk-jdk8u   文件: Coordinator.java
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;
    }
}
 
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();
}
 
源代码11 项目: openjdk-jdk8u-backup   文件: ClassBeanInfoImpl.java
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();
        }
    }
}
 
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();
}
 
源代码13 项目: openjdk-8-source   文件: ClassBeanInfoImpl.java
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();
        }
    }
}
 
源代码14 项目: openjdk-8   文件: Coordinator.java
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;
    }
}
 
源代码15 项目: openjdk-jdk9   文件: LeafBeanInfoImpl.java
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();
    }
}
 
源代码16 项目: hottub   文件: ArrayBeanInfoImpl.java
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));
}
 
源代码17 项目: openjdk-8-source   文件: Loader.java
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 );
}
 
源代码18 项目: TencentKona-8   文件: XMLSerializer.java
/**
 * 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;
}
 
源代码19 项目: TencentKona-8   文件: XMLSerializer.java
public boolean handleError(Exception e,Object source,String fieldName) {
    return handleEvent(
        new ValidationEventImpl(
            ValidationEvent.ERROR,
            e.getMessage(),
            new ValidationEventLocatorExImpl(source,fieldName),
                e));
}
 
源代码20 项目: TencentKona-8   文件: XMLSerializer.java
private void reportMissingObjectError(String fieldName) throws SAXException {
    reportError(new ValidationEventImpl(
        ValidationEvent.ERROR,
        Messages.MISSING_OBJECT.format(fieldName),
            getCurrentLocation(fieldName),
        new NullPointerException() ));
}
 
源代码21 项目: TencentKona-8   文件: XMLSerializer.java
/**
 * 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)) );
}
 
源代码22 项目: hottub   文件: XMLSerializer.java
private void reportMissingObjectError(String fieldName) throws SAXException {
    reportError(new ValidationEventImpl(
        ValidationEvent.ERROR,
        Messages.MISSING_OBJECT.format(fieldName),
            getCurrentLocation(fieldName),
        new NullPointerException() ));
}
 
源代码23 项目: TencentKona-8   文件: UnmarshallingContext.java
/**
 * 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;
}
 
源代码24 项目: openjdk-jdk9   文件: AnyTypeBeanInfo.java
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));
}
 
源代码25 项目: jdk8u60   文件: RuntimeBuiltinLeafInfoImpl.java
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;
}
 
源代码26 项目: jdk8u60   文件: CompositeStructureBeanInfo.java
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));
}
 
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));
}
 
源代码28 项目: hottub   文件: CompositeStructureBeanInfo.java
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));
}
 
源代码29 项目: jdk8u60   文件: XMLSerializer.java
/**
 * 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;
}
 
源代码30 项目: jdk8u60   文件: XMLSerializer.java
public boolean handleError(Exception e,Object source,String fieldName) {
    return handleEvent(
        new ValidationEventImpl(
            ValidationEvent.ERROR,
            e.getMessage(),
            new ValidationEventLocatorExImpl(source,fieldName),
                e));
}