Example usage for com.fasterxml.jackson.dataformat.xml XmlFactory XmlFactory

List of usage examples for com.fasterxml.jackson.dataformat.xml XmlFactory XmlFactory

Introduction

In this page you can find the example usage for com.fasterxml.jackson.dataformat.xml XmlFactory XmlFactory.

Prototype

public XmlFactory() 

Source Link

Document

Default constructor used to create factory instances.

Usage

From source file:org.jberet.support.io.XmlFactoryObjectFactory.java

/**
 * Gets an instance of {@code com.fasterxml.jackson.dataformat.xml.XmlFactory} based on the resource configuration in the
 * application server. The parameter {@code environment} contains XmlFactory configuration properties, and accepts
 * the following properties:/*from  ww w .  j av  a2s.  c o m*/
 * <ul>
 * <li>inputDecorator: fully-qualified name of a class that extends {@code com.fasterxml.jackson.core.io.InputDecorator}
 * <li>outputDecorator: fully-qualified name of a class that extends {@code com.fasterxml.jackson.core.io.OutputDecorator}
 * <li>xmlTextElementName: 
 * <li>defaultUseWrapper:
 * </ul>
 *
 * @param obj         the JNDI name of {@code com.fasterxml.jackson.dataformat.xml.XmlFactory} resource
 * @param name        always null
 * @param nameCtx     always null
 * @param environment a {@code Hashtable} of configuration properties
 * @return an instance of {@code com.fasterxml.jackson.dataformat.xml.XmlFactory}
 * @throws Exception any exception occurred
 */
@Override
public Object getObjectInstance(final Object obj, final Name name, final Context nameCtx,
        final Hashtable<?, ?> environment) throws Exception {
    XmlFactory xmlFactory = xmlFactoryCached;
    if (xmlFactory == null) {
        synchronized (this) {
            xmlFactory = xmlFactoryCached;
            if (xmlFactory == null) {
                xmlFactoryCached = xmlFactory = new XmlFactory();
            }

            JacksonXmlModule xmlModule = null;
            NoMappingJsonFactoryObjectFactory.configureInputDecoratorAndOutputDecorator(xmlFactory,
                    environment);

            final Object xmlTextElementName = environment.get("xmlTextElementName");
            if (xmlTextElementName != null) {
                xmlModule = new JacksonXmlModule();
                xmlModule.setXMLTextElementName((String) xmlTextElementName);
            }

            final Object defaultUseWrapper = environment.get("defaultUseWrapper");
            if (defaultUseWrapper != null) {
                if (defaultUseWrapper.equals("false")) {
                    if (xmlModule == null) {
                        xmlModule = new JacksonXmlModule();
                    }
                    xmlModule.setDefaultUseWrapper(false);
                } else if (defaultUseWrapper.equals("true")) {
                    //default value is already true, so nothing to do
                } else {
                    throw SupportMessages.MESSAGES.invalidReaderWriterProperty(null, (String) defaultUseWrapper,
                            "defaultUseWrapper");
                }
            }

            final XmlMapper xmlMapper = xmlModule == null ? new XmlMapper(xmlFactory)
                    : new XmlMapper(xmlFactory, xmlModule);
            xmlFactory.setCodec(xmlMapper);
        }
    }
    return xmlFactory;
}

From source file:org.jberet.support.io.XmlItemReaderWriterBase.java

/**
 * Initializes {@link #xmlFactory} field, which may be instantiated or obtained from other part of the application.
 *///from  w ww .  jav  a  2 s  .c om
protected void initXmlFactory() throws Exception {
    if (xmlFactoryLookup != null) {
        xmlFactory = InitialContext.doLookup(xmlFactoryLookup);
        xmlMapper = (XmlMapper) xmlFactory.getCodec();
    } else {
        initXmlModule();
        xmlFactory = new XmlFactory();
        xmlMapper = xmlModule == null ? new XmlMapper(xmlFactory) : new XmlMapper(xmlFactory, xmlModule);
        xmlFactory.setCodec(xmlMapper);
    }
    MappingJsonFactoryObjectFactory.configureCustomSerializersAndDeserializers(xmlMapper, null, null,
            customDataTypeModules, getClass().getClassLoader());
}

From source file:org.opencb.opencga.analysis.execution.plugins.OpenCGAAnalysis.java

public static Manifest loadManifest(String identifier) throws IOException {
    final String file;
    JsonFactory factory;/*from  ww  w.j a  va 2  s  . com*/
    if (OpenCGAAnalysis.class.getResource("/" + identifier + "/manifest.yml") != null) {
        file = "/" + identifier + "/manifest.yml";
        factory = new YAMLFactory();
    } else if (OpenCGAAnalysis.class.getResource("/" + identifier + "/manifest.json") != null) {
        file = "/" + identifier + "/manifest.json";
        factory = new JsonFactory();
    } else if (OpenCGAAnalysis.class.getResource("/" + identifier + "/manifest.xml") != null) {
        file = "/" + identifier + "/manifest.xml";
        factory = new XmlFactory();
    } else {
        return null;
    }
    try (InputStream stream = OpenCGAAnalysis.class.getResourceAsStream(file)) {
        return new ObjectMapper(factory).readValue(stream, Manifest.class);
    }
}