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

The following examples show how to use com.sun.xml.internal.bind.v2.runtime.XMLSerializer. These examples are extracted from open source projects. 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
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 2
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 3
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 4
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
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 Project: openjdk-8   Source File: ArrayERProperty.java    License: 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 7
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
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
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
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
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 12
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 13
@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 14
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 15
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 16
public ListIterator<Byte> iterator(final byte[] objects, XMLSerializer context) {
    return new ListIterator<Byte>() {
        int idx=0;
        public boolean hasNext() {
            return idx<objects.length;
        }

        public Byte next() {
            return objects[idx++];
        }
    };
}
 
Example 17
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 18
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 19
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 20
@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 21
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 22
@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 23
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 24
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 25
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 26
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 27
@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 28
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 29
@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 Project: hottub   Source File: TransducedAccessor.java    License: 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();
}