public void serializeURIs(BeanT bean, XMLSerializer target) throws SAXException { try { if (retainPropertyInfo) { final Property parentProperty = target.getCurrentProperty(); for( Property<BeanT> p : uriProperties ) { target.currentProperty.set(p); p.serializeURIs(bean,target); } target.currentProperty.set(parentProperty); } else { for( Property<BeanT> p : uriProperties ) { p.serializeURIs(bean,target); } } if(inheritedAttWildcard!=null) { Map<QName,String> map = inheritedAttWildcard.get(bean); target.attWildcardAsURIs(map,null); } } catch (AccessorException e) { target.reportError(null,e); } }
public Base64Data print(Image v) { ByteArrayOutputStreamEx imageData = new ByteArrayOutputStreamEx(); XMLSerializer xs = XMLSerializer.getInstance(); String mimeType = xs.getXMIMEContentType(); if(mimeType==null || mimeType.startsWith("image/*")) } else { xs.handleEvent(new ValidationEventImpl( ValidationEvent.ERROR, Messages.NO_IMAGE_WRITER.format(mimeType), xs.getCurrentLocation(null) )); xs.handleError(e);
/** * @param assoc * non-null if the marshaller is working inside {@link BinderImpl}. */ public MarshallerImpl( JAXBContextImpl c, AssociationMap assoc ) { context = c; serializer = new XMLSerializer(this); c14nSupport = context.c14nSupport; try { setEventHandler(this); } catch (JAXBException e) { throw new AssertionError(e); // impossible } }
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); } } }
public void marshal(T value, XMLSerializer out) throws IOException, SAXException, XMLStreamException { out.startElement(tagName,null); if(value==null) { out.writeXsiNilTrue(); } else { out.childAsXsiType(value,null,bi,false); } out.endElement(); }
@Override public CharSequence print(V o) throws AccessorException { XMLSerializer w = XMLSerializer.getInstance(); MimeType old = w.setExpectedMimeType(expectedMimeType); try { return core.print(o); } finally { w.setExpectedMimeType(old); } }
handleMissingObjectError(fieldName); } else { child = pushObject(child,fieldName); if(child==null) { // error recovery endNamespaceDecls(null); endAttributes(); return; fireBeforeMarshalEvents(actual, child); actual = grammar.getBeanInfo(child,true); if (actual.lookForLifecycleMethods()) { fireBeforeMarshalEvents(actual, child); reportError(fieldName,e); endNamespaceDecls(null); endAttributes(); return; // recover by ignore actualTypeName = actual.getTypeName(child); if(actualTypeName==null) { reportError(new ValidationEventImpl( ValidationEvent.ERROR, Messages.SUBSTITUTED_BY_ANONYMOUS_TYPE.format( child.getClass().getName(), actual.jaxbType.getName()), getCurrentLocation(fieldName)));
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(); } }
try { prewrite(out, true, postInitAction); serializer.startElement(rootTagName,null); if(bi.jaxbType==Void.class || bi.jaxbType==void.class) { serializer.endNamespaceDecls(null); serializer.endAttributes(); } else { // normal cases if(obj==null) serializer.writeXsiNilTrue(); else serializer.childAsXsiType(obj,"root",bi, false); serializer.endElement(); postwrite(); } catch( SAXException e ) { throw new MarshalException(e); } finally { serializer.close();
serializer.startElementForce(namespaceURI,localName,p,null); else serializer.startElement(namespaceURI,localName, p,null); serializer.getNamespaceContext().force( prefixMap.get(i + 1), prefixMap.get(i)); String prefix = getPrefix(qname); serializer.getNamespaceContext().declareNamespace( atts.getURI(i), prefix, true ); serializer.endNamespaceDecls(null); serializer.attribute( atts.getURI(i), atts.getLocalName(i), atts.getValue(i)); serializer.endAttributes(); } catch (IOException e) { throw new SAXException2(e);
/** * Short for the following call sequence: * * <pre> getNamespaceContext().declareNamespace(WellKnownNamespace.XML_SCHEMA_INSTANCE,"xsi",true); endNamespaceDecls(); attribute(WellKnownNamespace.XML_SCHEMA_INSTANCE,"nil","true"); endAttributes(); * </pre> */ public final void writeXsiNilTrue() throws SAXException, IOException, XMLStreamException { getNamespaceContext().declareNamespace(WellKnownNamespace.XML_SCHEMA_INSTANCE,"xsi",true); endNamespaceDecls(null); attribute(WellKnownNamespace.XML_SCHEMA_INSTANCE,"nil","true"); endAttributes(); }
public void serializeAttributes(BeanT bean, XMLSerializer target) throws SAXException, IOException, XMLStreamException { for( AttributeProperty<BeanT> p : attributeProperties ) try { if (retainPropertyInfo) { final Property parentProperty = target.getCurrentProperty(); target.currentProperty.set(p); p.serializeAttributes(bean,target); target.currentProperty.set(parentProperty); } else { p.serializeAttributes(bean,target); } if (p.attName.equals(WellKnownNamespace.XML_SCHEMA_INSTANCE, "nil")) { isNilIncluded = true; } } catch (AccessorException e) { target.reportError(null,e); } try { if(inheritedAttWildcard!=null) { Map<QName,String> map = inheritedAttWildcard.get(bean); target.attWildcardAsAttributes(map,null); } } catch (AccessorException e) { target.reportError(null,e); } }
private RuntimePropertyInfo getCurrentElementRuntimePropertyInfo() { final XMLSerializer xs = XMLSerializer.getInstance(); final Property cp = (xs == null) ? null : xs.getCurrentProperty(); return (cp == null) ? null : cp.getInfo(); }
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(); }
private void prewrite(XmlOutput out, boolean fragment, Runnable postInitAction) throws IOException, SAXException, XMLStreamException { serializer.startDocument(out,fragment,getSchemaLocation(),getNoNSSchemaLocation()); if(postInitAction!=null) postInitAction.run(); if(prefixMapper!=null) { // be defensive as we work with the user's code String[] decls = prefixMapper.getContextualNamespaceDecls(); if(decls!=null) { // defensive check for( int i=0; i<decls.length; i+=2 ) { String prefix = decls[i]; String nsUri = decls[i+1]; if(nsUri!=null && prefix!=null) // defensive check serializer.addInscopeBinding(nsUri,prefix); } } } serializer.setPrefixMapper(prefixMapper); }
public Base64Data print(Source v) { XMLSerializer xs = XMLSerializer.getInstance(); Base64Data bd = new Base64Data(); String contentType = xs.getXMIMEContentType(); MimeType mt = null; if(contentType!=null) mt = new MimeType(contentType); } catch (MimeTypeParseException e) { xs.handleError(e); Transformer tr = xs.getIdentityTransformer(); String defaultEncoding = tr.getOutputProperty(OutputKeys.ENCODING); tr.setOutputProperty(OutputKeys.ENCODING, charset); } catch (TransformerException e) { xs.handleError(e); } catch (UnsupportedEncodingException e) { xs.handleError(e);
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; } }
serializer.childAsRoot(obj); postwrite(); } catch( SAXException e ) { throw new MarshalException(e); } finally { serializer.close();
@Override public @NotNull CharSequence print(@NotNull V o) throws AccessorException { XMLSerializer w = XMLSerializer.getInstance(); boolean old = w.setInlineBinaryFlag(true); try { return core.print(o); } finally { w.setInlineBinaryFlag(old); } }
public Base64Data print(byte[] v) { XMLSerializer w = XMLSerializer.getInstance(); Base64Data bd = new Base64Data(); String mimeType = w.getXMIMEContentType(); bd.set(v,mimeType); return bd; } });