/** * Ends marshalling of an element. * Pops the internal stack. */ public void endElement() throws SAXException { writePendingText(); String uri = getCurrentElementUri(); String local = getCurrentElementLocal(); String prefix = nsContext.getPrefix(uri); String qname = local; if(prefix!=null) qname = prefix+':'+qname; writer.endElement( uri, local, qname ); // pop namespace bindings and // fire endPrefixMapping events nsContext.iterateDeclaredPrefixes(endPrefixCallback); popElement(); // prepare to collect texts _assert(textBuf==null); textBuf = new StringBuffer(); nsContext.endElement(); }
public void childAsAttributes( XMLSerializable o ) throws SAXException { if(o==null) { missingObjectError(); return; } o.serializeAttributes(this); }
/** * Starts marshalling of an element. * Calling this method will push the internal state into the * internal stack. */ public void startElement( String uri, String local ) throws SAXException { writePendingText(); nsContext.startElement(); pushElement(uri,local); // memorize element name }
/** * Switches to the "marshal child texts/elements" mode. * This method has to be called after the 1st pass is completed. */ public void endAttributes() throws SAXException { // calculate QName of the element String uri = getCurrentElementUri(); String local = getCurrentElementLocal(); String prefix = nsContext.declareNamespace(uri,false); String qname = local; if(prefix!=null) qname = prefix+':'+qname; // fire startPrefixMapping events nsContext.iterateDeclaredPrefixes(startPrefixCallback); // fire the startElement event writer.startElement( uri, local, qname, attributes ); // reset attributes attributes.clear(); // prepare to collect texts _assert(textBuf==null); textBuf = new StringBuffer(); }
_assert(textBuf!=null); new NullPointerException() ); reportError(ev); return;
/** * Starts marshalling of an attribute. * * The marshalling of an attribute will be done by * <ol> * <li>call the startAttribute method * <li>call the text method (several times if necessary) * <li>call the endAttribute method * </ol> * * No two attributes can be marshalled at the same time. * Note that the whole attribute marshalling must be happened * after the startElement method and before the endAttributes method. */ public void startAttribute( String uri, String local ) { _assert(textBuf==null); // allocate a buffer to collect attribute value textBuf = new StringBuffer(); // remember the attribute name. We'll use this value later. this.attNamespaceUri = uri; this.attLocalName = local; }
private void missingObjectError() throws SAXException { ValidationEvent ev = new ValidationEventImpl( ValidationEvent.ERROR, Messages.format(Messages.ERR_MISSING_OBJECT), null ); reportError(ev); }
private void write( XMLSerializable obj, ContentHandler writer ) throws JAXBException { try { if( getSchemaLocation()!=null || getNoNSSchemaLocation()!=null ) { // if we need to add xsi:schemaLocation or its brother, // throw in the component to do that. writer = new SchemaLocationFilter( getSchemaLocation(), getNoNSSchemaLocation(), writer ); } SAXMarshaller serializer = new SAXMarshaller(writer,this); // set a DocumentLocator that doesn't provide any information writer.setDocumentLocator( new LocatorImpl() ); writer.startDocument(); obj.serializeElements(serializer); writer.endDocument(); } catch( SAXException e ) { throw new MarshalException(e); } }
public void childAsElements( XMLSerializable o ) throws SAXException { if(o==null) { // if null is passed, it usually means that the content tree object // doesn't have some of its required property. missingObjectError(); // as a marshaller, we should be generous, so we'll continue to marshal // this document by skipping this missing object. return; } o.serializeElements(this); }
public void childAsAttributeBodies( XMLSerializable o ) throws SAXException { if(o==null) { missingObjectError(); return; } o.serializeAttributeBodies(this); }