com.sun.xml.internal.bind.v2.runtime.XMLSerializer Java Examples

The following examples show how to use com.sun.xml.internal.bind.v2.runtime.XMLSerializer. 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: RuntimeBuiltinLeafInfoImpl.java    From hottub 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 #2
Source File: ArrayReferenceNodeProperty.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
protected final void serializeListBody(BeanT o, XMLSerializer w, ListT list) throws IOException, XMLStreamException, SAXException {
    ListIterator<ItemT> itr = lister.iterator(list, w);

    while(itr.hasNext()) {
        try {
            ItemT item = itr.next();
            if (item != null) {
                if(isMixed && item.getClass()==String.class) {
                    w.text((String)item,null);
                } else {
                    JaxBeanInfo bi = w.grammar.getBeanInfo(item,true);
                    if(bi.jaxbType==Object.class && domHandler!=null)
                        // even if 'v' is a DOM node, it always derive from Object,
                        // so the getBeanInfo returns BeanInfo for Object
                        w.writeDom(item,domHandler,o,fieldName);
                    else
                        bi.serializeRoot(item,w);
                }
            }
        } catch (JAXBException e) {
            w.reportError(fieldName,e);
            // recover by ignoring this item
        }
    }
}
 
Example #3
Source File: ArrayERProperty.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public final void serializeBody(BeanT o, XMLSerializer w, Object outerPeer) throws SAXException, AccessorException, IOException, XMLStreamException {
    ListT list = acc.get(o);

    if(list!=null) {
        if(wrapperTagName!=null) {
            w.startElement(wrapperTagName,null);
            w.endNamespaceDecls(list);
            w.endAttributes();
        }

        serializeListBody(o,w,list);

        if(wrapperTagName!=null)
            w.endElement();
    } else {
        // list is null
        if(isWrapperNillable) {
            w.startElement(wrapperTagName,null);
            w.writeXsiNilTrue();
            w.endElement();
        } // otherwise don't print the wrapper tag name
    }
}
 
Example #4
Source File: SingleReferenceNodeProperty.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public void serializeBody(BeanT o, XMLSerializer w, Object outerPeer) throws SAXException, AccessorException, IOException, XMLStreamException {
    ValueT v = acc.get(o);
    if(v!=null) {
        try {
            JaxBeanInfo bi = w.grammar.getBeanInfo(v,true);
            if(bi.jaxbType==Object.class && domHandler!=null)
                // even if 'v' is a DOM node, it always derive from Object,
                // so the getBeanInfo returns BeanInfo for Object
                w.writeDom(v,domHandler,o,fieldName);
            else
                bi.serializeRoot(v,w);
        } catch (JAXBException e) {
            w.reportError(fieldName,e);
            // recover by ignoring this property
        }
    }
}
 
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 void declareNamespace(BeanT bean, XMLSerializer w) throws AccessorException, SAXException {
    ListT list = acc.get(bean);

    if(list!=null) {
       ListIterator<ItemT> itr = lister.iterator(list, w);

        while(itr.hasNext()) {
            try {
                ItemT item = itr.next();
                if (item != null) {
                    xducer.declareNamespace(item,w);
                }
            } catch (JAXBException e) {
                w.reportError(null,e);
            }
        }
    }
}
 
Example #7
Source File: SingleReferenceNodeProperty.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void serializeBody(BeanT o, XMLSerializer w, Object outerPeer) throws SAXException, AccessorException, IOException, XMLStreamException {
    ValueT v = acc.get(o);
    if(v!=null) {
        try {
            JaxBeanInfo bi = w.grammar.getBeanInfo(v,true);
            if(bi.jaxbType==Object.class && domHandler!=null)
                // even if 'v' is a DOM node, it always derive from Object,
                // so the getBeanInfo returns BeanInfo for Object
                w.writeDom(v,domHandler,o,fieldName);
            else
                bi.serializeRoot(v,w);
        } catch (JAXBException e) {
            w.reportError(fieldName,e);
            // recover by ignoring this property
        }
    }
}
 
Example #8
Source File: RuntimeBuiltinLeafInfoImpl.java    From openjdk-8-source 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 #9
Source File: ListTransducedAccessorImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public void declareNamespace(BeanT bean, XMLSerializer w) throws AccessorException, SAXException {
    ListT list = acc.get(bean);

    if(list!=null) {
       ListIterator<ItemT> itr = lister.iterator(list, w);

        while(itr.hasNext()) {
            try {
                ItemT item = itr.next();
                if (item != null) {
                    xducer.declareNamespace(item,w);
                }
            } catch (JAXBException e) {
                w.reportError(null,e);
            }
        }
    }
}
 
Example #10
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 #11
Source File: PrimitiveArrayListerInteger.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public ListIterator<Integer> iterator(final int[] objects, XMLSerializer context) {
    return new ListIterator<Integer>() {
        int idx=0;
        public boolean hasNext() {
            return idx<objects.length;
        }

        public Integer next() {
            return objects[idx++];
        }
    };
}
 
Example #12
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 #13
Source File: ArrayElementNodeProperty.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void serializeItem(JaxBeanInfo expected, ItemT item, XMLSerializer w) throws SAXException, IOException, XMLStreamException {
    if(item==null) {
        w.writeXsiNilTrue();
    } else {
        w.childAsXsiType(item,fieldName,expected, false);
    }
}
 
Example #14
Source File: FastInfosetStreamWriterOutput.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void startDocument(XMLSerializer serializer, boolean fragment,
        int[] nsUriIndex2prefixIndex, NamespaceContextImpl nsContext)
        throws IOException, SAXException, XMLStreamException {
    super.startDocument(serializer, fragment, nsUriIndex2prefixIndex, nsContext);

    if (fragment)
        fiout.initiateLowLevelWriting();
}
 
Example #15
Source File: PrimitiveArrayListerInteger.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public ListIterator<Integer> iterator(final int[] objects, XMLSerializer context) {
    return new ListIterator<Integer>() {
        int idx=0;
        public boolean hasNext() {
            return idx<objects.length;
        }

        public Integer next() {
            return objects[idx++];
        }
    };
}
 
Example #16
Source File: FastInfosetStreamWriterOutput.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void startDocument(XMLSerializer serializer, boolean fragment,
        int[] nsUriIndex2prefixIndex, NamespaceContextImpl nsContext)
        throws IOException, SAXException, XMLStreamException {
    super.startDocument(serializer, fragment, nsUriIndex2prefixIndex, nsContext);

    if (fragment)
        fiout.initiateLowLevelWriting();
}
 
Example #17
Source File: PrimitiveArrayListerBoolean.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public ListIterator<Boolean> iterator(final boolean[] objects, XMLSerializer context) {
    return new ListIterator<Boolean>() {
        int idx=0;
        public boolean hasNext() {
            return idx<objects.length;
        }

        public Boolean next() {
            return objects[idx++];
        }
    };
}
 
Example #18
Source File: ArrayElementLeafProperty.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void serializeItem(JaxBeanInfo bi, ItemT item, XMLSerializer w) throws SAXException, AccessorException, IOException, XMLStreamException {
    xducer.declareNamespace(item,w);
    w.endNamespaceDecls(item);
    w.endAttributes();
    // this is leaf, so by definition there's no type substitution
    // if there's, we'll be using ArrayElementNodeProperty
    xducer.writeText(w,item,fieldName);
}
 
Example #19
Source File: PrimitiveArrayListerDouble.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public ListIterator<Double> iterator(final double[] objects, XMLSerializer context) {
    return new ListIterator<Double>() {
        int idx=0;
        public boolean hasNext() {
            return idx<objects.length;
        }

        public Double next() {
            return objects[idx++];
        }
    };
}
 
Example #20
Source File: PrimitiveArrayListerDouble.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public ListIterator<Double> iterator(final double[] objects, XMLSerializer context) {
    return new ListIterator<Double>() {
        int idx=0;
        public boolean hasNext() {
            return idx<objects.length;
        }

        public Double next() {
            return objects[idx++];
        }
    };
}
 
Example #21
Source File: UTF8XmlOutput.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void startDocument(XMLSerializer serializer, boolean fragment, int[] nsUriIndex2prefixIndex, NamespaceContextImpl nsContext) throws IOException, SAXException, XMLStreamException {
    super.startDocument(serializer, fragment,nsUriIndex2prefixIndex,nsContext);

    octetBufferIndex = 0;
    if(!fragment) {
        write(XML_DECL);
    }
    if(header!=null) {
        textBuffer.set(header);
        textBuffer.write(this);
    }
}
 
Example #22
Source File: PrimitiveArrayListerFloat.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public ListIterator<Float> iterator(final float[] objects, XMLSerializer context) {
    return new ListIterator<Float>() {
        int idx=0;
        public boolean hasNext() {
            return idx<objects.length;
        }

        public Float next() {
            return objects[idx++];
        }
    };
}
 
Example #23
Source File: PrimitiveArrayListerShort.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public ListIterator<Short> iterator(final short[] objects, XMLSerializer context) {
    return new ListIterator<Short>() {
        int idx=0;
        public boolean hasNext() {
            return idx<objects.length;
        }

        public Short next() {
            return objects[idx++];
        }
    };
}
 
Example #24
Source File: PrimitiveArrayListerLong.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public ListIterator<Long> iterator(final long[] objects, XMLSerializer context) {
    return new ListIterator<Long>() {
        int idx=0;
        public boolean hasNext() {
            return idx<objects.length;
        }

        public Long next() {
            return objects[idx++];
        }
    };
}
 
Example #25
Source File: PrimitiveArrayListerShort.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public ListIterator<Short> iterator(final short[] objects, XMLSerializer context) {
    return new ListIterator<Short>() {
        int idx=0;
        public boolean hasNext() {
            return idx<objects.length;
        }

        public Short next() {
            return objects[idx++];
        }
    };
}
 
Example #26
Source File: SingleElementNodeProperty.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void serializeBody(BeanT o, XMLSerializer w, Object outerPeer) throws SAXException, AccessorException, IOException, XMLStreamException {
    ValueT v = acc.get(o);
    if (v!=null) {
        Class vtype = v.getClass();
        TagAndType tt=typeNames.get(vtype); // quick way that usually works

        if(tt==null) {// slow way that always works
            for (Map.Entry<Class,TagAndType> e : typeNames.entrySet()) {
                if(e.getKey().isAssignableFrom(vtype)) {
                    tt = e.getValue();
                    break;
                }
            }
        }

        boolean addNilDecl = (o instanceof JAXBElement) && ((JAXBElement)o).isNil();
        if(tt==null) {
            // actually this is an error, because the actual type was not a sub-type
            // of any of the types specified in the annotations,
            // but for the purpose of experimenting with simple type substitution,
            // it's convenient to marshal this anyway (for example so that classes
            // generated from simple types like String can be marshalled as expected.)
            w.startElement(typeNames.values().iterator().next().tagName,null);
            w.childAsXsiType(v,fieldName,w.grammar.getBeanInfo(Object.class), addNilDecl && nillable);
        } else {
            w.startElement(tt.tagName,null);
            w.childAsXsiType(v,fieldName,tt.beanInfo, addNilDecl && nillable);
        }
        w.endElement();
    } else if (nillable) {
        w.startElement(nullTagName,null);
        w.writeXsiNilTrue();
        w.endElement();
    }
}
 
Example #27
Source File: PrimitiveArrayListerFloat.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public ListIterator<Float> iterator(final float[] objects, XMLSerializer context) {
    return new ListIterator<Float>() {
        int idx=0;
        public boolean hasNext() {
            return idx<objects.length;
        }

        public Float next() {
            return objects[idx++];
        }
    };
}
 
Example #28
Source File: TransducedAccessor.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void writeLeafElement(XMLSerializer w, Name tagName, BeanT o, String fieldName) throws SAXException, AccessorException, IOException, XMLStreamException {
    w.startElement(tagName,null);
    declareNamespace(o,w);
    w.endNamespaceDecls(null);
    w.endAttributes();
    xducer.writeText(w,acc.get(o),fieldName);
    w.endElement();
}
 
Example #29
Source File: TransducedAccessor.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void writeLeafElement(XMLSerializer w, Name tagName, BeanT o, String fieldName) throws SAXException, AccessorException, IOException, XMLStreamException {
    w.startElement(tagName,null);
    declareNamespace(o,w);
    w.endNamespaceDecls(null);
    w.endAttributes();
    xducer.writeText(w,acc.get(o),fieldName);
    w.endElement();
}
 
Example #30
Source File: Lister.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public ListIterator<ItemT> iterator(final ItemT[] objects, XMLSerializer context) {
    return new ListIterator<ItemT>() {
        int idx=0;
        public boolean hasNext() {
            return idx<objects.length;
        }

        public ItemT next() {
            return objects[idx++];
        }
    };
}