Java Code Examples for com.sun.xml.internal.bind.v2.runtime.XMLSerializer#getInstance()

The following examples show how to use com.sun.xml.internal.bind.v2.runtime.XMLSerializer#getInstance() . 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: ListTransducedAccessorImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public String print(BeanT o) throws AccessorException, SAXException {
    ListT list = acc.get(o);

    if(list==null)
        return null;

    StringBuilder buf = new StringBuilder();
    XMLSerializer w = XMLSerializer.getInstance();
    ListIterator<ItemT> itr = lister.iterator(list, w);

    while(itr.hasNext()) {
        try {
            ItemT item = itr.next();
            if (item != null) {
                if(buf.length()>0)  buf.append(' ');
                buf.append(xducer.print(item));
            }
        } catch (JAXBException e) {
            w.reportError(null,e);
        }
    }
    return buf.toString();
}
 
Example 2
Source File: ListTransducedAccessorImpl.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public String print(BeanT o) throws AccessorException, SAXException {
    ListT list = acc.get(o);

    if(list==null)
        return null;

    StringBuilder buf = new StringBuilder();
    XMLSerializer w = XMLSerializer.getInstance();
    ListIterator<ItemT> itr = lister.iterator(list, w);

    while(itr.hasNext()) {
        try {
            ItemT item = itr.next();
            if (item != null) {
                if(buf.length()>0)  buf.append(' ');
                buf.append(xducer.print(item));
            }
        } catch (JAXBException e) {
            w.reportError(null,e);
        }
    }
    return buf.toString();
}
 
Example 3
Source File: ListTransducedAccessorImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public String print(BeanT o) throws AccessorException, SAXException {
    ListT list = acc.get(o);

    if(list==null)
        return null;

    StringBuilder buf = new StringBuilder();
    XMLSerializer w = XMLSerializer.getInstance();
    ListIterator<ItemT> itr = lister.iterator(list, w);

    while(itr.hasNext()) {
        try {
            ItemT item = itr.next();
            if (item != null) {
                if(buf.length()>0)  buf.append(' ');
                buf.append(xducer.print(item));
            }
        } catch (JAXBException e) {
            w.reportError(null,e);
        }
    }
    return buf.toString();
}
 
Example 4
Source File: ListTransducedAccessorImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public String print(BeanT o) throws AccessorException, SAXException {
    ListT list = acc.get(o);

    if(list==null)
        return null;

    StringBuilder buf = new StringBuilder();
    XMLSerializer w = XMLSerializer.getInstance();
    ListIterator<ItemT> itr = lister.iterator(list, w);

    while(itr.hasNext()) {
        try {
            ItemT item = itr.next();
            if (item != null) {
                if(buf.length()>0)  buf.append(' ');
                buf.append(xducer.print(item));
            }
        } catch (JAXBException e) {
            w.reportError(null,e);
        }
    }
    return buf.toString();
}
 
Example 5
Source File: RuntimeBuiltinLeafInfoImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
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 6
Source File: ListTransducedAccessorImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public String print(BeanT o) throws AccessorException, SAXException {
    ListT list = acc.get(o);

    if(list==null)
        return null;

    StringBuilder buf = new StringBuilder();
    XMLSerializer w = XMLSerializer.getInstance();
    ListIterator<ItemT> itr = lister.iterator(list, w);

    while(itr.hasNext()) {
        try {
            ItemT item = itr.next();
            if (item != null) {
                if(buf.length()>0)  buf.append(' ');
                buf.append(xducer.print(item));
            }
        } catch (JAXBException e) {
            w.reportError(null,e);
        }
    }
    return buf.toString();
}
 
Example 7
Source File: RuntimeBuiltinLeafInfoImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
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 8
Source File: TransducedAccessor.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public String print(BeanT bean) throws AccessorException, SAXException {
    TargetT target = acc.get(bean);
    if(target==null)    return null;

    XMLSerializer w = XMLSerializer.getInstance();
    try {
        String id = w.grammar.getBeanInfo(target,true).getId(target,w);
        if(id==null)
            w.errorMissingId(target);
        return id;
    } catch (JAXBException e) {
        w.reportError(null,e);
        return null;
    }
}
 
Example 9
Source File: RuntimeBuiltinLeafInfoImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public String print(Date v) {
    XMLSerializer xs = XMLSerializer.getInstance();
    QName type = xs.getSchemaType();
    GregorianCalendar cal = new GregorianCalendar(0,0,0);
    cal.setTime(v);
    if ((type != null) && (WellKnownNamespace.XML_SCHEMA.equals(type.getNamespaceURI())) &&
            DATE.equals(type.getLocalPart())) {
        return DatatypeConverterImpl._printDate(cal);
    } else {
        return DatatypeConverterImpl._printDateTime(cal);
    }
}
 
Example 10
Source File: TransducedAccessor.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public String print(BeanT bean) throws AccessorException, SAXException {
    TargetT target = acc.get(bean);
    if(target==null)    return null;

    XMLSerializer w = XMLSerializer.getInstance();
    try {
        String id = w.grammar.getBeanInfo(target,true).getId(target,w);
        if(id==null)
            w.errorMissingId(target);
        return id;
    } catch (JAXBException e) {
        w.reportError(null,e);
        return null;
    }
}
 
Example 11
Source File: TransducedAccessor.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public String print(BeanT bean) throws AccessorException, SAXException {
    TargetT target = acc.get(bean);
    if(target==null)    return null;

    XMLSerializer w = XMLSerializer.getInstance();
    try {
        String id = w.grammar.getBeanInfo(target,true).getId(target,w);
        if(id==null)
            w.errorMissingId(target);
        return id;
    } catch (JAXBException e) {
        w.reportError(null,e);
        return null;
    }
}
 
Example 12
Source File: RuntimeBuiltinLeafInfoImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public String print(Date v) {
    XMLSerializer xs = XMLSerializer.getInstance();
    QName type = xs.getSchemaType();
    GregorianCalendar cal = new GregorianCalendar(0,0,0);
    cal.setTime(v);
    if ((type != null) && (WellKnownNamespace.XML_SCHEMA.equals(type.getNamespaceURI())) &&
            DATE.equals(type.getLocalPart())) {
        return DatatypeConverterImpl._printDate(cal);
    } else {
        return DatatypeConverterImpl._printDateTime(cal);
    }
}
 
Example 13
Source File: RuntimeBuiltinLeafInfoImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public String print(Date v) {
    XMLSerializer xs = XMLSerializer.getInstance();
    QName type = xs.getSchemaType();
    GregorianCalendar cal = new GregorianCalendar(0,0,0);
    cal.setTime(v);
    if ((type != null) && (WellKnownNamespace.XML_SCHEMA.equals(type.getNamespaceURI())) &&
            DATE.equals(type.getLocalPart())) {
        return DatatypeConverterImpl._printDate(cal);
    } else {
        return DatatypeConverterImpl._printDateTime(cal);
    }
}
 
Example 14
Source File: RuntimeBuiltinLeafInfoImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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 15
Source File: RuntimeBuiltinLeafInfoImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public String print(Date v) {
    XMLSerializer xs = XMLSerializer.getInstance();
    QName type = xs.getSchemaType();
    GregorianCalendar cal = new GregorianCalendar(0,0,0);
    cal.setTime(v);
    if ((type != null) && (WellKnownNamespace.XML_SCHEMA.equals(type.getNamespaceURI())) &&
            DATE.equals(type.getLocalPart())) {
        return DatatypeConverterImpl._printDate(cal);
    } else {
        return DatatypeConverterImpl._printDateTime(cal);
    }
}
 
Example 16
Source File: RuntimeBuiltinLeafInfoImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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 17
Source File: RuntimeBuiltinLeafInfoImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public String print(Date v) {
    XMLSerializer xs = XMLSerializer.getInstance();
    QName type = xs.getSchemaType();
    GregorianCalendar cal = new GregorianCalendar(0,0,0);
    cal.setTime(v);
    if ((type != null) && (WellKnownNamespace.XML_SCHEMA.equals(type.getNamespaceURI())) &&
            DATE.equals(type.getLocalPart())) {
        return DatatypeConverterImpl._printDate(cal);
    } else {
        return DatatypeConverterImpl._printDateTime(cal);
    }
}
 
Example 18
Source File: TransducedAccessor.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public String print(BeanT bean) throws AccessorException, SAXException {
    TargetT target = acc.get(bean);
    if(target==null)    return null;

    XMLSerializer w = XMLSerializer.getInstance();
    try {
        String id = w.grammar.getBeanInfo(target,true).getId(target,w);
        if(id==null)
            w.errorMissingId(target);
        return id;
    } catch (JAXBException e) {
        w.reportError(null,e);
        return null;
    }
}
 
Example 19
Source File: TransducedAccessor.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public String print(BeanT bean) throws AccessorException, SAXException {
    TargetT target = acc.get(bean);
    if(target==null)    return null;

    XMLSerializer w = XMLSerializer.getInstance();
    try {
        String id = w.grammar.getBeanInfo(target,true).getId(target,w);
        if(id==null)
            w.errorMissingId(target);
        return id;
    } catch (JAXBException e) {
        w.reportError(null,e);
        return null;
    }
}
 
Example 20
Source File: RuntimeBuiltinLeafInfoImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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;
}