Refine search
/** * 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; }
/** * Create a new {@code IUnmarshallingContext}. * @return the created unmarshalling context * @throws JiBXException in case of errors */ protected IUnmarshallingContext createUnmarshallingContext() throws JiBXException { Assert.state(this.bindingFactory != null, "JibxMarshaller not initialized"); return this.bindingFactory.createUnmarshallingContext(); }
@Override public boolean supports(Class<?> clazz) { Assert.notNull(clazz, "Class must not be null"); if (this.targetClass != null) { return (this.targetClass == clazz); } Assert.state(this.bindingFactory != null, "JibxMarshaller not initialized"); String[] mappedClasses = this.bindingFactory.getMappedClasses(); String className = clazz.getName(); for (String mappedClass : mappedClasses) { if (className.equals(mappedClass)) { return true; } } return false; }
protected Object decode0(ChannelHandlerContext arg0, ByteBuf body) throws Exception { factory = BindingDirectory.getFactory(clazz); String content = body.toString(UTF_8); if (isPrint) System.out.println("The body is : " + content); reader = new StringReader(content); IUnmarshallingContext uctx = factory.createUnmarshallingContext(); Object result = uctx.unmarshalDocument(reader); reader.close(); reader = null; return result; }
public SchemaMarshaller() throws JiBXException { IBindingFactory ifact = BindingDirectory.getFactory(SchemaUtils.XS_PREFIX_BINDING, SchemaElement.class); m_schemaContext = (MarshallingContext)ifact.createMarshallingContext(); }
bfact = BindingDirectory.getFactory(mclas); } else { bfact = BindingDirectory.getFactory(bname, mclas); IUnmarshallingContext uctx = bfact.createUnmarshallingContext(); Object obj = uctx.unmarshalDocument(new FileInputStream(fin), null); String encoding = ((UnmarshallingContext)uctx).getInputEncoding(); IMarshallingContext mctx = bfact.createMarshallingContext(); mctx.setIndent(2); ByteArrayOutputStream bos = new ByteArrayOutputStream();
/** * 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); }
/** * 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, ' '); }
public void write(Object obj, XMLStreamWriter output) { try { IBindingFactory factory = BindingDirectory.getFactory(obj.getClass()); IMarshallingContext ctx = getMarshallingContext(obj); StAXWriter writer = new StAXWriter(factory.getNamespaces(), output); ctx.setXmlWriter(writer); ((IMarshallable)obj).marshal(ctx); } catch (Exception e) { throw new RuntimeException(e); } }
String[] nss = bindingFactory.getNamespaces(); if (marshallerName != null) { String prefix = xmlWriter.getPrefix(elementNamespace); IMarshallingContext ctx = bindingFactory.createMarshallingContext(); ctx.setXmlWriter(writer); marshal(full, ctx);
public String getPrefix() { if (marshallerName == null) { String[] namespaces = bindingFactory.getNamespaces(); String uri = bindingFactory.getElementNamespaces()[elementNamespaceIndex]; for (int i=0; i<namespaces.length; i++) { if (namespaces[i].equals(uri)) { String prefix = bindingFactory.getPrefixes()[i]; return prefix == null ? "" : prefix; } } return null; } else { return elementNamespacePrefix; } }
bindingFactory = factory; boolean found = false; String[] nss = factory.getNamespaces(); int nsidx = -1; for (int i = 0; i < nsindexes.length; i++) {
public static <T> T fromXML(byte[] bytes, Class<T> clazz) throws Exception { ByteArrayInputStream baos = new ByteArrayInputStream(bytes); IBindingFactory bfact = BindingDirectory.getFactory(clazz); UnmarshallingContext uctx = (UnmarshallingContext) bfact.createUnmarshallingContext(); Object obj = uctx.unmarshalDocument(baos, "UTF-8"); return clazz.cast(obj); }
private IMarshallingContext getMarshallingContext(Object object) throws JiBXException { IBindingFactory factory = BindingDirectory.getFactory(object.getClass()); return factory.createMarshallingContext(); } }
IBindingFactory factory = BindingDirectory.getFactory(SchemaUtils.XS_PREFIX_BINDING, SchemaElement.class); IUnmarshallingContext ictx = factory.createUnmarshallingContext(); int count = list.size(); SchemaElement[] schemas = new SchemaElement[count]; IMarshallingContext mctx = factory.createMarshallingContext(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); mctx.setIndent(2);
/** * Marshal this message to DOM. * @param message * @return DOM tree */ public static Element marshalObjectToDOM(Object message) { try { IBindingFactory jc = BindingDirectory.getFactory(message.getClass()); IMarshallingContext marshaller = jc.createMarshallingContext(); String[] namespaces = jc.getNamespaces(); JDOMWriter jdomWriter = new JDOMWriter(namespaces); marshaller.setXmlWriter(jdomWriter); marshaller.marshalDocument(message); marshaller.endDocument(); org.jdom.Document jdoc = jdomWriter.getDocument(); DOMOutputter dout = new DOMOutputter(); Document doc = dout.output(jdoc); Element node = doc.getDocumentElement(); return node; } catch (JiBXException e) { e.printStackTrace(); } catch (JDOMException e) { e.printStackTrace(); } return null; } /**
public void write(Object obj, XMLStreamWriter output) { try { IBindingFactory factory = BindingDirectory.getFactory(obj.getClass()); IMarshallingContext ctx = getMarshallingContext(obj); StAXWriter writer = new StAXWriter(factory.getNamespaces(), output); ctx.setXmlWriter(writer); ((IMarshallable)obj).marshal(ctx); } catch (Exception e) { throw new RuntimeException(e); } }
/** * Read the template into the model. * @return */ public Object getBindingFromStream(Class<?> bindingClass, InputStream inStream) { try { IBindingFactory jc = BindingDirectory.getFactory(bindingClass); IUnmarshallingContext unmarshaller = jc.createUnmarshallingContext(); Model message = (Model)unmarshaller.unmarshalDocument( inStream, URL_ENCODING); return message; } catch (JiBXException e) { e.printStackTrace(); } return null; } /**
private IMarshallingContext getMarshallingContext(Object object) throws JiBXException { IBindingFactory factory = BindingDirectory.getFactory(object.getClass()); return factory.createMarshallingContext(); } }
/** * Marshal this message to DOM. * @param message * @return DOM tree */ public static Element marshalObjectToDOM(Object message) { try { IBindingFactory jc = BindingDirectory.getFactory(message.getClass()); IMarshallingContext marshaller = jc.createMarshallingContext(); String[] namespaces = jc.getNamespaces(); JDOMWriter jdomWriter = new JDOMWriter(namespaces); marshaller.setXmlWriter(jdomWriter); marshaller.marshalDocument(message); marshaller.endDocument(); org.jdom.Document jdoc = jdomWriter.getDocument(); DOMOutputter dout = new DOMOutputter(); Document doc = dout.output(jdoc); Element node = doc.getDocumentElement(); return node; } catch (JiBXException e) { e.printStackTrace(); } catch (JDOMException e) { e.printStackTrace(); } return null; } /**