/** * Create a new {@code IMarshallingContext}, configured with the correct indentation. * @return the created marshalling context * @throws JiBXException in case of errors */ protected IMarshallingContext createMarshallingContext() throws JiBXException { Assert.state(this.bindingFactory != null, "JibxMarshaller not initialized"); IMarshallingContext marshallingContext = this.bindingFactory.createMarshallingContext(); marshallingContext.setIndent(this.indent); return marshallingContext; }
/** * Creates a new <code>IMarshallingContext</code>, set with the correct indentation. * * @return the created marshalling context * @throws JiBXException in case of errors */ protected IMarshallingContext createMarshallingContext() throws JiBXException { IMarshallingContext marshallingContext = bindingFactory.createMarshallingContext(); marshallingContext.setIndent(indent); return marshallingContext; }
private IMarshallingContext getMarshallingContext(Object object) throws JiBXException { IBindingFactory factory = BindingDirectory.getFactory(object.getClass()); return factory.createMarshallingContext(); } }
private IMarshallingContext getMarshallingContext(Object object) throws JiBXException { IBindingFactory factory = BindingDirectory.getFactory(object.getClass()); return factory.createMarshallingContext(); } }
public SchemaMarshaller() throws JiBXException { IBindingFactory ifact = BindingDirectory.getFactory(SchemaUtils.XS_PREFIX_BINDING, SchemaElement.class); m_schemaContext = (MarshallingContext)ifact.createMarshallingContext(); }
private String encode2Xml(Order order) throws JiBXException, IOException { factory = BindingDirectory.getFactory(Order.class); writer = new StringWriter(); IMarshallingContext mctx = factory.createMarshallingContext(); mctx.setIndent(2); mctx.marshalDocument(order, CHARSET_NAME, null, writer); String xmlStr = writer.toString(); writer.close(); System.out.println(xmlStr.toString()); return xmlStr; }
public void marshal(Exchange exchange, Object body, OutputStream stream) throws Exception { IBindingFactory bindingFactory = createBindingFactory(body.getClass(), bindingName); IMarshallingContext marshallingContext = bindingFactory.createMarshallingContext(); marshallingContext.marshalDocument(body, null, null, stream); if (contentTypeHeader) { if (exchange.hasOut()) { exchange.getOut().setHeader(Exchange.CONTENT_TYPE, "application/xml"); } else { exchange.getIn().setHeader(Exchange.CONTENT_TYPE, "application/xml"); } } }
protected ByteBuf encode0(ChannelHandlerContext ctx, Object body) throws Exception { factory = BindingDirectory.getFactory(body.getClass()); writer = new StringWriter(); IMarshallingContext mctx = factory.createMarshallingContext(); mctx.setIndent(2); mctx.marshalDocument(body, CHARSET_NAME, null, writer); String xmlStr = writer.toString(); writer.close(); writer = null; ByteBuf encodeBuf = Unpooled.copiedBuffer(xmlStr, UTF_8); return encodeBuf; }
protected static String SerializeObject( IBindingFactory lBindingFactory, Object request) { String message = null; try { IMarshallingContext lContext = lBindingFactory. createMarshallingContext(); ByteArrayOutputStream lOutputStream = new ByteArrayOutputStream(); lContext.marshalDocument(request, "UTF-8", null, lOutputStream); message = new String(lOutputStream.toByteArray(), "UTF-8"); } catch (JiBXException lEx) { throw new RuntimeException("Problems generating XML, " + "underlying problem is " + lEx.getMessage(), lEx); } catch (UnsupportedEncodingException lEx) { throw new RuntimeException("Problems generating XML in specified" + "encoding, underlying problem is " + lEx.getMessage(), lEx); } return message; }
public static byte[] toXML(Object obj) throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); IBindingFactory bfact = BindingDirectory.getFactory(obj.getClass()); IMarshallingContext mctx = bfact.createMarshallingContext(); mctx.setIndent(2); mctx.marshalDocument(obj, "UTF-8", null, out); return out.toByteArray(); }
/** * Marshal this message to xml . * @param message * @return XML String */ public static String marshalObjectToXML(Object message) { if (message == null) return null; try { IBindingFactory jc = BindingDirectory.getFactory(message.getClass()); IMarshallingContext marshaller = jc.createMarshallingContext(); ByteArrayOutputStream out = new ByteArrayOutputStream(); marshaller.setIndent(4); marshaller.marshalDocument(message, URL_ENCODING, null, out); String xml = out.toString(STRING_ENCODING); return xml; } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (JiBXException e) { e.printStackTrace(); } return null; } /**
/** * Marshal this message to xml . * @param message * @return XML String */ public static String marshalObjectToXML(Object message) { if (message == null) return null; try { IBindingFactory jc = BindingDirectory.getFactory(message.getClass()); IMarshallingContext marshaller = jc.createMarshallingContext(); ByteArrayOutputStream out = new ByteArrayOutputStream(); marshaller.setIndent(4); marshaller.marshalDocument(message, URL_ENCODING, null, out); String xml = out.toString(STRING_ENCODING); return xml; } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (JiBXException e) { e.printStackTrace(); } return null; } /**
/** * Write schema definitions to file system. * * @param destdir destination directory * @throws JiBXException on error in marshalling * @throws IOException on error writing */ private void writeSchemas(File destdir) throws JiBXException, IOException { for (Iterator iter = m_validationContext.iterateSchemas(); iter.hasNext();) { SchemaElement schema = (SchemaElement)iter.next(); File file = new File(destdir, schema.getResolver().getName()); OutputStream stream = new FileOutputStream(file); Writer writer = new OutputStreamWriter(stream, "utf-8"); IBindingFactory factory = BindingDirectory.getFactory(SchemaUtils.XS_PREFIX_BINDING, SchemaElement.class); IMarshallingContext ictx = factory.createMarshallingContext(); ictx.setOutput(writer); ictx.setIndent(2); ictx.marshalDocument(schema); writer.close(); } }
/** * Constructor. * * @throws JiBXException on error loading binding information */ public SchemaDocumentationGenerator() throws JiBXException { m_factory = BindingDirectory.getFactory("schema_extract_binding", "org.jibx.schema.codegen"); int index = 0; String[] uris = m_factory.getNamespaces(); m_namespaceSet = new HashSet(); for (int i = 1; i < uris.length; i++) { m_namespaceSet.add(uris[i]); if (SCHEMA_DEFINITIONS_NS.equals(uris[i])) { index = i; } } if (index < 0) { throw new JiBXException("Schema namespace definition not found"); } m_schemaIndex = index; m_schemaPrefix = m_factory.getPrefixes()[index]; m_context = (MarshallingContext)m_factory.createMarshallingContext(); m_context.setIndent(2, COMMENT_LEAD_TEXT, ' '); }
/** * Write a collection of schemas to a target directory. * * @param dir target directory * @param schemas list of {@link SchemaHolder} * @throws JiBXException * @throws IOException */ public static void writeSchemas(File dir, Collection schemas) throws JiBXException, IOException { IBindingFactory fact = BindingDirectory.getFactory(SchemaUtils.XS_PREFIX_BINDING, SchemaElement.class); for (Iterator iter = schemas.iterator(); iter.hasNext();) { SchemaHolder holder = (SchemaHolder)iter.next(); if (!holder.isExistingFile()) { IMarshallingContext ictx = fact.createMarshallingContext(); File file = new File(dir, holder.getFileName()); ictx.setOutput(new FileOutputStream(file), null); ictx.setIndent(2); ((IMarshallable)holder.getSchema()).marshal(ictx); ictx.getXmlWriter().flush(); } } }
/** * Create XML representation of System Info * * @param xml xml representation of system info */ public void toXML(OutputStream xml) { try { IBindingFactory factory = BindingDirectory.getFactory(SystemInfo.class); IMarshallingContext context = factory.createMarshallingContext(); context.setIndent(4); context.marshalDocument(this, "UTF-8", null, xml); } catch(JiBXException e) { throw new DictionaryException("Failed to create System Info", e); } } }
/** * Create XML representation of System Info * * @param xml xml representation of system info */ public void toXML(OutputStream xml) { try { IBindingFactory factory = BindingDirectory.getFactory(SystemInfo.class); IMarshallingContext context = factory.createMarshallingContext(); context.setIndent(4); context.marshalDocument(this, "UTF-8", null, xml); } catch(JiBXException e) { throw new DictionaryException("Failed to create System Info", e); } } }
/** * Write this model to this outstream. * @param message * @param out * @return */ public boolean writeThisModel(Model message, OutputStream out) { try { IBindingFactory jc = BindingDirectory.getFactory(Model.class); IMarshallingContext marshaller = jc.createMarshallingContext(); marshaller.setIndent(4); // ByteArrayOutputStream out = new ByteArrayOutputStream(); marshaller.marshalDocument(message, URL_ENCODING, null, out); // String xml = out.toString(STRING_ENCODING); return true; // Success // } catch (UnsupportedEncodingException e) { // e.printStackTrace(); } catch (JiBXException e) { e.printStackTrace(); } return false; }
/** * Constructor. * * @throws JiBXException on error creating marshaller */ public WsdlWriter() throws JiBXException { // set the marshalling contexts IBindingFactory ifact = BindingDirectory.getFactory(Definitions.class); m_marshalContext = (MarshallingContext)ifact.createMarshallingContext(); // initialize namespace URI to index map String[] nss = ifact.getNamespaces(); s_namespaceMap = new StringIntSizedMap(nss.length); for (int i = 0; i < nss.length; i++) { s_namespaceMap.add(nss[i], i); } // create other statics used in code s_wsdlNamespaceIndex = s_namespaceMap.get(WSDL_NAMESPACE_URI); s_soapNamespaceIndex = s_namespaceMap.get(SOAP_NAMESPACE_URI); }
private RawSld parseSldI(StyledLayerDescriptorInfo sld) throws JiBXException { RawSld res = new RawSld(); IBindingFactory bfact; bfact = BindingDirectory.getFactory(StyledLayerDescriptorInfo.class); IMarshallingContext mctx = bfact.createMarshallingContext(); StringWriter writer = new StringWriter(); mctx.setOutput(writer); mctx.getXmlWriter().setIndentSpaces(2, "\n", ' '); mctx.marshalDocument(sld); res.setXml(writer.toString()); res.setName(sld.getName()); res.setVersion(sld.getVersion()); res.setTitle(sld.getTitle() == null ? getTitle(sld, "?") : sld.getTitle()); return res; }