Examples of IXMLWriter


Examples of org.jibx.runtime.IXMLWriter

    protected void writeNamespaces(IMarshallingContext ictx) throws JiBXException {
        if (m_namespaces != null) {
            try {
               
                // set up information for namespace indexes and prefixes
                IXMLWriter writer = ictx.getXmlWriter();
                String[] uris = new String[m_namespaces.size() / 2];
                int[] indexes = new int[uris.length];
                String[] prefs = new String[uris.length];
                int base = writer.getNamespaceCount();
                for (int i = 0; i < uris.length; i++) {
                    indexes[i] = base + i;
                    prefs[i] = (String)m_namespaces.get(i * 2);
                    uris[i] = (String)m_namespaces.get(i * 2 + 1);
                }
               
                // add the namespace declarations to current element
                writer.pushExtensionNamespaces(uris);
                writer.openNamespaces(indexes, prefs);
                for (int i = 0; i < uris.length; i++) {
                    String prefix = prefs[i];
                    String name = prefix.length() > 0 ? "xmlns:" + prefix : "xmlns";
                    writer.addAttribute(0, name, uris[i]);
                }
               
            } catch (IOException e) {
                throw new JiBXException("Error writing output document", e);
            }
View Full Code Here

Examples of org.jibx.runtime.IXMLWriter

            m_context.setOutput(strwriter);
           
            // define namespaces as extension to those used in binding
            int count = uritoprefix.size();
            String[] uris = (String[])uritoprefix.keySet().toArray(new String[count]);
            IXMLWriter xmlwriter = m_context.getXmlWriter();
            int base = xmlwriter.getNamespaceCount();
            xmlwriter.pushExtensionNamespaces(uris);
           
            // build the arrays of namespace indexes and prefixes for use on marshalled root elements
            int length = count;
            if (!uritoprefix.containsKey(null)) {
                length++;
View Full Code Here

Examples of org.jibx.runtime.IXMLWriter

                    } else {
                        text.append(" Reference to class ");
                        text.append(name);
                    }
                    text.append(' ');
                    IXMLWriter writer = m_context.getXmlWriter();
                    writer.indent();
                    writer.writeComment(text.toString());
                   
                } else {
                    expand = true;
                }
               
View Full Code Here

Examples of org.jibx.runtime.IXMLWriter

            ((IMarshallable)dataObject).marshal(ctx);
        } else {
            try {
               
                // open namespaces from wrapper element
                IXMLWriter wrtr = ctx.getXmlWriter();
                wrtr.openNamespaces(openNamespaceIndexes, openNamespacePrefixes);
                String name = elementName;
                if (!"".equals(elementNamespacePrefix)) {
                    name = elementNamespacePrefix + ':' + name;
                }
                wrtr.startTagOpen(0, name);
               
                // marshal object representation (may include attributes) into element
                IMarshaller mrsh = ctx.getMarshaller(marshallerIndex,
                    bindingFactory.getMappedClasses()[marshallerIndex]);
                mrsh.marshal(dataObject, ctx);
                wrtr.endTag(0, name);
               
            } catch (IOException e) {
                throw new JiBXException("Error marshalling XML representation", e);
            }
        }
View Full Code Here

Examples of org.jibx.runtime.IXMLWriter

    /* (non-Javadoc)
     * @see org.apache.axiom.om.OMDataSource#serialize(javax.xml.stream.XMLStreamWriter)
     */
    public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {
        try {
            IXMLWriter writer = new StAXWriter(bindingFactory.getNamespaces(),
                xmlWriter);
            IMarshallingContext ctx = bindingFactory.createMarshallingContext();
            ctx.setXmlWriter(writer);
            marshal(ctx);
        } catch (JiBXException e) {
View Full Code Here

Examples of org.jibx.runtime.IXMLWriter

                } else {
                    throw new IllegalStateException("Object of class " + dataObject.getClass().getName() +
                        " needs a JiBX <mapping> to be marshalled");
                }
            } else {
                IXMLWriter wrtr = ctx.getXmlWriter();
                String name = elementName;
                int nsidx = 0;
                if (full) {
                   
                    // declare all namespaces on start tag
                    nsidx = elementNamespaceIndex;
                    wrtr.startTagNamespaces(nsidx, name, openNamespaceIndexes, openNamespacePrefixes);
                   
                } else {
       
                    // configure writer with namespace declared in enclosing scope
                    wrtr.openNamespaces(openNamespaceIndexes, openNamespacePrefixes);
                    if (!"".equals(elementNamespacePrefix)) {
                        name = elementNamespacePrefix + ':' + name;
                    }
                    wrtr.startTagOpen(0, name);
                }
               
                // marshal object representation (may include attributes) into element
                IMarshaller mrsh = ctx.getMarshaller(marshallerIndex,
                                                     bindingFactory
                                                             .getMappedClasses()[marshallerIndex]);
                mrsh.marshal(dataObject, ctx);
                wrtr.endTag(nsidx, name);
            }
            ctx.getXmlWriter().flush();

        } catch (IOException e) {
            throw new JiBXException("Error marshalling XML representation: " + e.getMessage(), e);
View Full Code Here

Examples of org.jibx.runtime.IXMLWriter

                    }
                }
            }
           
            // marshal with all namespace declarations, since external state unknown
            IXMLWriter writer = new StAXWriter(nss, xmlWriter);
            IMarshallingContext ctx = bindingFactory.createMarshallingContext();
            ctx.setXmlWriter(writer);
            marshal(full, ctx);
           
        } catch (JiBXException e) {
View Full Code Here

Examples of org.jibx.runtime.IXMLWriter

  }

  private void marshalDocument(IMarshallingContext marshallingContext, Object graph) throws IOException,
      JiBXException {
    if (StringUtils.hasLength(docTypeRootElementName)) {
      IXMLWriter xmlWriter = marshallingContext.getXmlWriter();
      xmlWriter.writeDocType(docTypeRootElementName, docTypeSystemId, docTypePublicId, docTypeInternalSubset);
    }
    marshallingContext.marshalDocument(graph);
  }
View Full Code Here

Examples of org.jibx.runtime.IXMLWriter

  @Override
  protected void marshalXmlStreamWriter(Object graph, XMLStreamWriter streamWriter) throws XmlMappingException {
    try {
      MarshallingContext marshallingContext = (MarshallingContext) createMarshallingContext();
      IXMLWriter xmlWriter = new StAXWriter(marshallingContext.getNamespaces(), streamWriter);
      marshallingContext.setXmlWriter(xmlWriter);
      marshallingContext.marshalDocument(graph);
    }
    catch (JiBXException ex) {
      throw convertJibxException(ex, false);
View Full Code Here

Examples of org.jibx.runtime.IXMLWriter

                } else {
                    throw new IllegalStateException("Object of class " + dataObject.getClass().getName() +
                        " needs a JiBX <mapping> to be marshalled");
                }
            } else {
                IXMLWriter wrtr = ctx.getXmlWriter();
                String name = elementName;
                int nsidx = 0;
                if (full) {
                   
                    // declare all namespaces on start tag
                    nsidx = elementNamespaceIndex;
                    wrtr.startTagNamespaces(nsidx, name, openNamespaceIndexes, openNamespacePrefixes);
                   
                } else {
       
                    // configure writer with namespace declared in enclosing scope
                    wrtr.openNamespaces(openNamespaceIndexes, openNamespacePrefixes);
                    if (!"".equals(elementNamespacePrefix)) {
                        name = elementNamespacePrefix + ':' + name;
                    }
                    wrtr.startTagOpen(0, name);
                }
               
                // marshal object representation (may include attributes) into element
                IMarshaller mrsh = ctx.getMarshaller(marshallerIndex,
                                                     bindingFactory
                                                             .getMappedClasses()[marshallerIndex]);
                mrsh.marshal(dataObject, ctx);
                wrtr.endTag(nsidx, name);
            }
            ctx.getXmlWriter().flush();

        } catch (IOException e) {
            throw new JiBXException("Error marshalling XML representation: " + e.getMessage(), e);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.