Java Code Examples for com.sun.xml.internal.bind.v2.runtime.XMLSerializer#startElement()
The following examples show how to use
com.sun.xml.internal.bind.v2.runtime.XMLSerializer#startElement() .
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: ListElementProperty.java From hottub with GNU General Public License v2.0 | 6 votes |
@Override public void serializeBody(BeanT o, XMLSerializer w, Object outerPeer) throws SAXException, AccessorException, IOException, XMLStreamException { ListT list = acc.get(o); if(list!=null) { if(xacc.useNamespace()) { w.startElement(tagName,null); xacc.declareNamespace(o,w); w.endNamespaceDecls(list); w.endAttributes(); xacc.writeText(w,o,fieldName); w.endElement(); } else { xacc.writeLeafElement(w, tagName, o, fieldName); } } }
Example 2
Source File: ArrayERProperty.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
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 3
Source File: ListElementProperty.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
@Override public void serializeBody(BeanT o, XMLSerializer w, Object outerPeer) throws SAXException, AccessorException, IOException, XMLStreamException { ListT list = acc.get(o); if(list!=null) { if(xacc.useNamespace()) { w.startElement(tagName,null); xacc.declareNamespace(o,w); w.endNamespaceDecls(list); w.endAttributes(); xacc.writeText(w,o,fieldName); w.endElement(); } else { xacc.writeLeafElement(w, tagName, o, fieldName); } } }
Example 4
Source File: ArrayERProperty.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
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 5
Source File: ArrayERProperty.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
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 6
Source File: ListElementProperty.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
@Override public void serializeBody(BeanT o, XMLSerializer w, Object outerPeer) throws SAXException, AccessorException, IOException, XMLStreamException { ListT list = acc.get(o); if(list!=null) { if(xacc.useNamespace()) { w.startElement(tagName,null); xacc.declareNamespace(o,w); w.endNamespaceDecls(list); w.endAttributes(); xacc.writeText(w,o,fieldName); w.endElement(); } else { xacc.writeLeafElement(w, tagName, o, fieldName); } } }
Example 7
Source File: ListElementProperty.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
@Override public void serializeBody(BeanT o, XMLSerializer w, Object outerPeer) throws SAXException, AccessorException, IOException, XMLStreamException { ListT list = acc.get(o); if(list!=null) { if(xacc.useNamespace()) { w.startElement(tagName,null); xacc.declareNamespace(o,w); w.endNamespaceDecls(list); w.endAttributes(); xacc.writeText(w,o,fieldName); w.endElement(); } else { xacc.writeLeafElement(w, tagName, o, fieldName); } } }
Example 8
Source File: SingleElementLeafProperty.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
@Override public void serializeBody(BeanT o, XMLSerializer w, Object outerPeer) throws SAXException, AccessorException, IOException, XMLStreamException { boolean hasValue = xacc.hasValue(o); Object obj = null; try { obj = acc.getUnadapted(o); } catch (AccessorException ae) { ; // noop } Class valueType = acc.getValueType(); // check for different type than expected. If found, add xsi:type declaration if (xsiTypeNeeded(o, w, obj, valueType)) { w.startElement(tagName, outerPeer); w.childAsXsiType(obj, fieldName, w.grammar.getBeanInfo(valueType), false); w.endElement(); } else { // current type is expected if (hasValue) { xacc.writeLeafElement(w, tagName, o, fieldName); } else if (nillable) { w.startElement(tagName, null); w.writeXsiNilTrue(); w.endElement(); } } }
Example 9
Source File: TransducedAccessor.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@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 10
Source File: SingleElementNodeProperty.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@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 11
Source File: TransducedAccessor.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
@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 12
Source File: SingleElementNodeProperty.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
@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 13
Source File: SingleElementNodeProperty.java From hottub with GNU General Public License v2.0 | 5 votes |
@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 14
Source File: SingleElementLeafProperty.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@Override public void serializeBody(BeanT o, XMLSerializer w, Object outerPeer) throws SAXException, AccessorException, IOException, XMLStreamException { boolean hasValue = xacc.hasValue(o); Object obj = null; try { obj = acc.getUnadapted(o); } catch (AccessorException ae) { ; // noop } Class valueType = acc.getValueType(); // check for different type than expected. If found, add xsi:type declaration if (xsiTypeNeeded(o, w, obj, valueType)) { w.startElement(tagName, outerPeer); w.childAsXsiType(obj, fieldName, w.grammar.getBeanInfo(valueType), false); w.endElement(); } else { // current type is expected if (hasValue) { xacc.writeLeafElement(w, tagName, o, fieldName); } else if (nillable) { w.startElement(tagName, null); w.writeXsiNilTrue(); w.endElement(); } } }
Example 15
Source File: ArrayElementProperty.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
protected void serializeListBody(BeanT beanT, XMLSerializer w, ListT list) throws IOException, XMLStreamException, SAXException, AccessorException { ListIterator<ItemT> itr = lister.iterator(list, w); boolean isIdref = itr instanceof Lister.IDREFSIterator; // UGLY while(itr.hasNext()) { try { ItemT item = itr.next(); if (item != null) { Class itemType = item.getClass(); if(isIdref) // This should be the only place where we need to be aware // that the iterator is iterating IDREFS. itemType = ((Lister.IDREFSIterator)itr).last().getClass(); // normally, this returns non-null TagAndType tt = typeMap.get(itemType); while(tt==null && itemType!=null) { // otherwise we'll just have to try the slow way itemType = itemType.getSuperclass(); tt = typeMap.get(itemType); } if(tt==null) { // item is not of the expected type. // w.reportError(new ValidationEventImpl(ValidationEvent.ERROR, // Messages.UNEXPECTED_JAVA_TYPE.format( // item.getClass().getName(), // getExpectedClassNameList() // ), // w.getCurrentLocation(fieldName))); // continue; // see the similar code in SingleElementNodeProperty. // for the purpose of simple type substitution, make it a non-error w.startElement(typeMap.values().iterator().next().tagName,null); w.childAsXsiType(item,fieldName,w.grammar.getBeanInfo(Object.class), false); } else { w.startElement(tt.tagName,null); serializeItem(tt.beanInfo,item,w); } w.endElement(); } else { if(nillableTagName!=null) { w.startElement(nillableTagName,null); w.writeXsiNilTrue(); w.endElement(); } } } catch (JAXBException e) { w.reportError(fieldName,e); // recover by ignoring this item } } }
Example 16
Source File: ArrayElementProperty.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
protected void serializeListBody(BeanT beanT, XMLSerializer w, ListT list) throws IOException, XMLStreamException, SAXException, AccessorException { ListIterator<ItemT> itr = lister.iterator(list, w); boolean isIdref = itr instanceof Lister.IDREFSIterator; // UGLY while(itr.hasNext()) { try { ItemT item = itr.next(); if (item != null) { Class itemType = item.getClass(); if(isIdref) // This should be the only place where we need to be aware // that the iterator is iterating IDREFS. itemType = ((Lister.IDREFSIterator)itr).last().getClass(); // normally, this returns non-null TagAndType tt = typeMap.get(itemType); while(tt==null && itemType!=null) { // otherwise we'll just have to try the slow way itemType = itemType.getSuperclass(); tt = typeMap.get(itemType); } if(tt==null) { // item is not of the expected type. // w.reportError(new ValidationEventImpl(ValidationEvent.ERROR, // Messages.UNEXPECTED_JAVA_TYPE.format( // item.getClass().getName(), // getExpectedClassNameList() // ), // w.getCurrentLocation(fieldName))); // continue; // see the similar code in SingleElementNodeProperty. // for the purpose of simple type substitution, make it a non-error w.startElement(typeMap.values().iterator().next().tagName,null); w.childAsXsiType(item,fieldName,w.grammar.getBeanInfo(Object.class), false); } else { w.startElement(tt.tagName,null); serializeItem(tt.beanInfo,item,w); } w.endElement(); } else { if(nillableTagName!=null) { w.startElement(nillableTagName,null); w.writeXsiNilTrue(); w.endElement(); } } } catch (JAXBException e) { w.reportError(fieldName,e); // recover by ignoring this item } } }
Example 17
Source File: SingleMapNodeProperty.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
private void bareStartTag(XMLSerializer w, Name tagName, Object peer) throws IOException, XMLStreamException, SAXException { w.startElement(tagName,peer); w.endNamespaceDecls(peer); w.endAttributes(); }
Example 18
Source File: SingleMapNodeProperty.java From hottub with GNU General Public License v2.0 | 4 votes |
private void bareStartTag(XMLSerializer w, Name tagName, Object peer) throws IOException, XMLStreamException, SAXException { w.startElement(tagName,peer); w.endNamespaceDecls(peer); w.endAttributes(); }
Example 19
Source File: SingleMapNodeProperty.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
private void bareStartTag(XMLSerializer w, Name tagName, Object peer) throws IOException, XMLStreamException, SAXException { w.startElement(tagName,peer); w.endNamespaceDecls(peer); w.endAttributes(); }
Example 20
Source File: ArrayElementProperty.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
protected void serializeListBody(BeanT beanT, XMLSerializer w, ListT list) throws IOException, XMLStreamException, SAXException, AccessorException { ListIterator<ItemT> itr = lister.iterator(list, w); boolean isIdref = itr instanceof Lister.IDREFSIterator; // UGLY while(itr.hasNext()) { try { ItemT item = itr.next(); if (item != null) { Class itemType = item.getClass(); if(isIdref) // This should be the only place where we need to be aware // that the iterator is iterating IDREFS. itemType = ((Lister.IDREFSIterator)itr).last().getClass(); // normally, this returns non-null TagAndType tt = typeMap.get(itemType); while(tt==null && itemType!=null) { // otherwise we'll just have to try the slow way itemType = itemType.getSuperclass(); tt = typeMap.get(itemType); } if(tt==null) { // item is not of the expected type. // w.reportError(new ValidationEventImpl(ValidationEvent.ERROR, // Messages.UNEXPECTED_JAVA_TYPE.format( // item.getClass().getName(), // getExpectedClassNameList() // ), // w.getCurrentLocation(fieldName))); // continue; // see the similar code in SingleElementNodeProperty. // for the purpose of simple type substitution, make it a non-error w.startElement(typeMap.values().iterator().next().tagName,null); w.childAsXsiType(item,fieldName,w.grammar.getBeanInfo(Object.class), false); } else { w.startElement(tt.tagName,null); serializeItem(tt.beanInfo,item,w); } w.endElement(); } else { if(nillableTagName!=null) { w.startElement(nillableTagName,null); w.writeXsiNilTrue(); w.endElement(); } } } catch (JAXBException e) { w.reportError(fieldName,e); // recover by ignoring this item } } }