public String getId(BeanT bean, XMLSerializer target) throws SAXException { if(idProperty!=null) { try { return idProperty.getIdValue(bean); } catch (AccessorException e) { target.reportError(null,e); } } return null; }
public void serializeBody(Object array, XMLSerializer target) throws SAXException, IOException, XMLStreamException { int len = Array.getLength(array); for( int i=0; i<len; i++ ) { Object item = Array.get(array,i); try { xducer.writeText(target,item,"arrayItem"); } catch (AccessorException e) { target.reportError("arrayItem",e); } } }
public final void serializeBody(BeanT bean, XMLSerializer w) throws SAXException, IOException, XMLStreamException { // most of the times leaves are printed as leaf element/attribute property, // so this code is only used for example when you have multiple XmlElement on a property // and some of them are leaves. Hence this doesn't need to be super-fast. try { xducer.writeText(w,bean,null); } catch (AccessorException e) { w.reportError(null,e); } }
public void serializeBody(JAXBElement element, XMLSerializer target) throws SAXException, IOException, XMLStreamException { try { property.serializeBody(element,target,null); } catch (AccessorException x) { target.reportError(null,x); } }
public final void serializeRoot(Object array, XMLSerializer target) throws SAXException, IOException, XMLStreamException { target.reportError( new ValidationEventImpl( ValidationEvent.ERROR, Messages.UNABLE_TO_MARSHAL_NON_ELEMENT.format(array.getClass().getName()), null, null)); }
public void serializeRoot(CompositeStructure o, XMLSerializer target) throws SAXException, IOException, XMLStreamException { target.reportError( new ValidationEventImpl( ValidationEvent.ERROR, Messages.UNABLE_TO_MARSHAL_NON_ELEMENT.format(o.getClass().getName()), null, null)); }
public final void serializeRoot(Object array, XMLSerializer target) throws SAXException { target.reportError( new ValidationEventImpl( ValidationEvent.ERROR, Messages.UNABLE_TO_MARSHAL_NON_ELEMENT.format(array.getClass().getName()), null, null)); }
public void serializeRoot(Object element, XMLSerializer target) throws SAXException { target.reportError( new ValidationEventImpl( ValidationEvent.ERROR, Messages.UNABLE_TO_MARSHAL_NON_ELEMENT.format(element.getClass().getName()), null, null)); }
public final void serializeURIs(Object array, XMLSerializer target) throws SAXException { if(xducer.useNamespace()) { int len = Array.getLength(array); for( int i=0; i<len; i++ ) { Object item = Array.get(array,i); try { xducer.declareNamespace(item,target); } catch (AccessorException e) { target.reportError("arrayItem",e); } } } }
/** * Report an error found as an exception. * * @param fieldName * the name of the property being processed when an error is found. */ public final void reportError(String fieldName, Throwable t) throws SAXException { ValidationEvent ve = new ValidationEventImpl(ValidationEvent.ERROR, t.getMessage(), getCurrentLocation(fieldName), t); reportError(ve); }
public final void serializeURIs(BeanT bean, XMLSerializer target) throws SAXException { // TODO: maybe we should create another LeafBeanInfoImpl class for // context-dependent xducers? if(xducer.useNamespace()) { try { xducer.declareNamespace(bean,target); } catch (AccessorException e) { target.reportError(null,e); } } }
public <E> void writeDom(E element, DomHandler<E, ?> domHandler, Object parentBean, String fieldName) throws SAXException { Source source = domHandler.marshal(element,this); if(contentHandlerAdapter==null) contentHandlerAdapter = new ContentHandlerAdaptor(this); try { getIdentityTransformer().transform(source,new SAXResult(contentHandlerAdapter)); } catch (TransformerException e) { reportError(fieldName,e); } }
private void reportMissingObjectError(String fieldName) throws SAXException { reportError(new ValidationEventImpl( ValidationEvent.ERROR, Messages.MISSING_OBJECT.format(fieldName), getCurrentLocation(fieldName), new NullPointerException() )); }
public String onIDREF( Object obj ) throws SAXException { String id; try { id = getIdFromObject(obj); } catch (JAXBException e) { reportError(null,e); return null; // recover by returning null } idReferencedObjects.add(obj); if(id==null) { reportError( new NotIdentifiableEventImpl( ValidationEvent.ERROR, Messages.NOT_IDENTIFIABLE.format(), new ValidationEventLocatorImpl(obj) ) ); } return id; }
void reconcileID() throws SAXException { // find objects that were not a part of the object graph idReferencedObjects.removeAll(objectsWithId); for( Object idObj : idReferencedObjects ) { try { String id = getIdFromObject(idObj); reportError( new NotIdentifiableEventImpl( ValidationEvent.ERROR, Messages.DANGLING_IDREF.format(id), new ValidationEventLocatorImpl(idObj) ) ); } catch (JAXBException e) { // this error should have been reported already. just ignore here. } } // clear the garbage idReferencedObjects.clear(); objectsWithId.clear(); }
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(); } }
/** * Called when a referenced object doesn't have an ID. */ public void errorMissingId(Object obj) throws SAXException { reportError( new ValidationEventImpl( ValidationEvent.ERROR, Messages.MISSING_ID.format(obj), new ValidationEventLocatorImpl(obj)) ); }
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 } } }
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; } }
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); } } } }