Search in sources :

Example 11 with IBindingFactory

use of org.jibx.runtime.IBindingFactory in project kernel by exoplatform.

the class TestConfigurationXML method testTrimValue.

@SuppressWarnings("unchecked")
public void testTrimValue() throws Exception {
    InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("test-trim-value.xml");
    assertNotNull(is);
    try {
        IBindingFactory bfact = BindingDirectory.getFactory(XMLObject.class);
        IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
        Configuration conf = (Configuration) uctx.unmarshalDocument(is, null);
        assertNotNull(conf);
        Iterator it = conf.getContainerLifecyclePluginIterator();
        assertNotNull(it);
        assertTrue(it.hasNext());
        ContainerLifecyclePlugin conlp = (ContainerLifecyclePlugin) it.next();
        assertEquals("container-lifecycle-plugin-type", conlp.getType());
        assertNotNull(conlp.getInitParams());
        assertEquals("container-lifecycle-plugin-value-param-value", (conlp.getInitParams().getValueParam("container-lifecycle-plugin-value-param-name")).getValue());
        it = conf.getComponentLifecyclePluginIterator();
        assertNotNull(it);
        assertTrue(it.hasNext());
        ComponentLifecyclePlugin comlp = (ComponentLifecyclePlugin) it.next();
        assertEquals("component-lifecycle-plugin", comlp.getType());
        ManageableComponents mc = comlp.getManageableComponents();
        assertNotNull(mc);
        assertEquals("manageable-components-component-type", mc.getComponentsType().get(0));
        ValuesParam valuesParam = comlp.getInitParams().getValuesParam("component-lifecycle-plugin-values-param-name");
        assertNotNull(valuesParam);
        assertNotNull(valuesParam.getValues());
        assertTrue(valuesParam.getValues().contains("component-lifecycle-plugin-values-param-value1"));
        assertTrue(valuesParam.getValues().contains("component-lifecycle-plugin-values-param-value2"));
        Component c = conf.getComponent("component-key1");
        assertNotNull(c);
        assertEquals("component-type1", c.getType());
        PropertiesParam propertiesParam = c.getInitParams().getPropertiesParam("component-key1-properties-param-name");
        assertNotNull(propertiesParam);
        assertEquals("component-key1-properties-param-prop-value", propertiesParam.getProperty("component-key1-properties-param-prop-name"));
        c = conf.getComponent("component-type2");
        assertNotNull(c);
        ObjectParameter objectParameter = c.getInitParams().getObjectParam("component-key2-object-param-name");
        assertNotNull(objectParameter);
        MyObject o = (MyObject) objectParameter.getObject();
        assertNotNull(o);
        assertEquals("string-value", o.field1);
        assertEquals(1, o.field2);
        assertEquals(1l, o.field3);
        assertEquals(1d, o.field4);
        assertEquals(true, o.field5);
        assertNotNull(o.field6);
        assertEquals("entry-value", o.field6.get("entry-name"));
        assertNotNull(o.field7);
        assertTrue(o.field7.contains("string-value"));
        assertNotNull(o.field8);
        assertEquals(1, o.field8[0]);
        List list = c.getComponentPlugins();
        assertNotNull(list);
        assertFalse(list.isEmpty());
        ComponentPlugin cp = (ComponentPlugin) list.get(0);
        assertEquals("component-plugins-name", cp.getName());
        assertEquals("set-method-name", cp.getSetMethod());
        assertEquals("component-plugins-type", cp.getType());
        assertEquals(1, cp.getPriority());
        it = conf.getExternalComponentPluginsIterator();
        assertNotNull(it);
        assertTrue(it.hasNext());
        ExternalComponentPlugins ecps = (ExternalComponentPlugins) it.next();
        assertEquals("target-component-name", ecps.getTargetComponent());
        list = ecps.getComponentPlugins();
        assertNotNull(list);
        assertFalse(list.isEmpty());
        cp = (ComponentPlugin) list.get(0);
        assertEquals("component-plugins-name", cp.getName());
        assertEquals("set-method-name", cp.getSetMethod());
        assertEquals("component-plugins-type", cp.getType());
        assertEquals(1, cp.getPriority());
        list = conf.getImports();
        assertNotNull(list);
        assertFalse(list.isEmpty());
        assertEquals("import-value", list.get(0));
        list = conf.getRemoveConfiguration();
        assertNotNull(list);
        assertFalse(list.isEmpty());
        assertEquals("remove-configuration-value", list.get(0));
    } finally {
        try {
            is.close();
        } catch (Exception e) {
        // ignore me
        }
    }
}
Also used : ComponentPlugin(org.exoplatform.container.xml.ComponentPlugin) Configuration(org.exoplatform.container.xml.Configuration) IBindingFactory(org.jibx.runtime.IBindingFactory) InputStream(java.io.InputStream) PropertiesParam(org.exoplatform.container.xml.PropertiesParam) ContainerLifecyclePlugin(org.exoplatform.container.xml.ContainerLifecyclePlugin) IUnmarshallingContext(org.jibx.runtime.IUnmarshallingContext) ComponentLifecyclePlugin(org.exoplatform.container.xml.ComponentLifecyclePlugin) ValuesParam(org.exoplatform.container.xml.ValuesParam) ExternalComponentPlugins(org.exoplatform.container.xml.ExternalComponentPlugins) ObjectParameter(org.exoplatform.container.xml.ObjectParameter) Iterator(java.util.Iterator) List(java.util.List) ManageableComponents(org.exoplatform.container.xml.ManageableComponents) Component(org.exoplatform.container.xml.Component)

Example 12 with IBindingFactory

use of org.jibx.runtime.IBindingFactory in project RESTdoclet by IG-Group.

the class JiBXUtils method marshallServices.

/**
    * Static method for marshalling services (list).
    * 
    * @param services the services to be marshalled.
    * @param file the file the services have to be marshalled to.
    * @throws JiBXException if JiBX fails.
    * @throws IOException if an input- or output-exception occurs.
    */
public static void marshallServices(final Services services, final File file) throws JiBXException, IOException {
    final Writer writer = new FileWriter(file);
    final IBindingFactory factory = BindingDirectory.getFactory(Services.class);
    final IMarshallingContext context = factory.createMarshallingContext();
    context.setIndent(INDENT);
    context.setOutput(writer);
    context.marshalDocument(services, ENCODING, null);
}
Also used : IMarshallingContext(org.jibx.runtime.IMarshallingContext) IBindingFactory(org.jibx.runtime.IBindingFactory) FileWriter(java.io.FileWriter) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 13 with IBindingFactory

use of org.jibx.runtime.IBindingFactory in project camel by apache.

the class JibxDataFormat method unmarshal.

public Object unmarshal(Exchange exchange, InputStream stream) throws Exception {
    Class<?> unmarshallType = exchange.getIn().getHeader(UNMARSHALL_CLASS, Class.class);
    if (unmarshallType == null) {
        unmarshallType = getUnmarshallClass();
    }
    ObjectHelper.notNull(unmarshallType, "unmarshallClass or CamelJibxUnmarshallClass header");
    IBindingFactory bindingFactory = createBindingFactory(unmarshallType, bindingName);
    IUnmarshallingContext unmarshallingContext = bindingFactory.createUnmarshallingContext();
    return unmarshallingContext.unmarshalDocument(stream, null);
}
Also used : IUnmarshallingContext(org.jibx.runtime.IUnmarshallingContext) IBindingFactory(org.jibx.runtime.IBindingFactory)

Example 14 with IBindingFactory

use of org.jibx.runtime.IBindingFactory in project kernel by exoplatform.

the class Configuration method toXML.

/**
 * Dumps the configuration in XML format into the given {@link Writer}
 */
public void toXML(Writer w) {
    try {
        CURRENT_CONFIG_TO_SERIALIZE.set(this);
        IBindingFactory bfact = BindingDirectory.getFactory(Configuration.class);
        IMarshallingContext mctx = bfact.createMarshallingContext();
        mctx.setIndent(2);
        mctx.marshalDocument(this, "UTF-8", null, w);
    } catch (Exception e) {
        LOG.warn("Couldn't dump the runtime configuration in XML Format", e);
    } finally {
        CURRENT_CONFIG_TO_SERIALIZE.remove();
    }
}
Also used : IMarshallingContext(org.jibx.runtime.IMarshallingContext) IBindingFactory(org.jibx.runtime.IBindingFactory) IOException(java.io.IOException)

Example 15 with IBindingFactory

use of org.jibx.runtime.IBindingFactory in project kernel by exoplatform.

the class XMLCollection method getXMLCollection.

public static XMLCollection getXMLCollection(InputStream is) throws Exception {
    IBindingFactory bfact = XMLObject.getBindingFactoryInPriviledgedMode(XMLObject.class);
    IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
    return (XMLCollection) uctx.unmarshalDocument(is, null);
}
Also used : IUnmarshallingContext(org.jibx.runtime.IUnmarshallingContext) IBindingFactory(org.jibx.runtime.IBindingFactory)

Aggregations

IBindingFactory (org.jibx.runtime.IBindingFactory)18 IUnmarshallingContext (org.jibx.runtime.IUnmarshallingContext)10 IMarshallingContext (org.jibx.runtime.IMarshallingContext)9 FileWriter (java.io.FileWriter)3 Writer (java.io.Writer)3 URL (java.net.URL)3 Configuration (org.exoplatform.container.xml.Configuration)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Component (org.exoplatform.container.xml.Component)2 ObjectParameter (org.exoplatform.container.xml.ObjectParameter)2 Controller (com.iggroup.oss.restdoclet.doclet.type.Controller)1 Service (com.iggroup.oss.restdoclet.doclet.type.Service)1 Services (com.iggroup.oss.restdoclet.doclet.type.Services)1 FileInputStream (java.io.FileInputStream)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1