Package org.milyn

Examples of org.milyn.GenericReaderConfigurator


* @author
*/
public class GenericReaderConfiguratorTest extends TestCase {

    public void test_resource_only() {
        GenericReaderConfigurator configurator = new GenericReaderConfigurator(JavaXMLReader.class);

        SmooksResourceConfiguration config = configurator.toConfig().get(0);
        assertConfigOK(config, JavaXMLReader.class.getName(), 0, 0, 0);
    }
View Full Code Here


        SmooksResourceConfiguration config = configurator.toConfig().get(0);
        assertConfigOK(config, JavaXMLReader.class.getName(), 0, 0, 0);
    }

    public void test_resource_and_features_and_params() throws SAXException {
        GenericReaderConfigurator configurator = new GenericReaderConfigurator(JavaXMLReader.class);

        configurator.getParameters().setProperty("a", "1");
        configurator.getParameters().setProperty("b", "2");
        configurator.setFeature("http://a", true);
        configurator.setFeature("http://b", true);
        configurator.setFeature("http://c", false);
        configurator.setFeature("http://d", true);
        configurator.setFeature("http://e", false);
        configurator.setFeature("http://f", false);

        SmooksResourceConfiguration config = configurator.toConfig().get(0);
        assertConfigOK(config, JavaXMLReader.class.getName(), 8, 3, 3);

        assertEquals("1", config.getStringParameter("a"));
        assertEquals("2", config.getStringParameter("b"));
View Full Code Here

        assertTrue(AbstractParser.isFeatureOff("http://e", config));
        assertTrue(AbstractParser.isFeatureOff("http://f", config));
    }

    public void test_features_and_params_only() throws SAXException {
        GenericReaderConfigurator configurator = new GenericReaderConfigurator();

        configurator.getParameters().setProperty("a", "1");
        configurator.setFeature("http://a", true);

        SmooksResourceConfiguration config = configurator.toConfig().get(0);
        assertConfigOK(config, null, 2, 1, 0);

        assertEquals("1", config.getStringParameter("a"));

        assertTrue(AbstractParser.isFeatureOn("http://a", config));
View Full Code Here

    }
   
    public void test_readerPool_Pooled() {
      Smooks smooks = new Smooks();
     
      smooks.setReaderConfig(new GenericReaderConfigurator(PooledSAXParser.class));
      smooks.setFilterSettings(FilterSettings.newSAXSettings().setReaderPoolSize(1));
     
      PooledSAXParser.numSetHandlerCalls = 0;
      smooks.filterSource(new StringSource("<x/>"));
      smooks.filterSource(new StringSource("<x/>"));
View Full Code Here

    }
   
    public void test_readerPool_Unpooled() {
      Smooks smooks = new Smooks();
     
      smooks.setReaderConfig(new GenericReaderConfigurator(UnpooledSAXParser.class));
      smooks.setFilterSettings(FilterSettings.newSAXSettings().setReaderPoolSize(0));
     
      UnpooledSAXParser.numSetHandlerCalls = 0;
      smooks.filterSource(new StringSource("<x/>"));
      smooks.filterSource(new StringSource("<x/>"));
View Full Code Here

        this.targetProfile = targetProfile;
        return this;
    }

    public List<SmooksResourceConfiguration> toConfig() {
        GenericReaderConfigurator configurator = new GenericReaderConfigurator(FixedLengthReader.class);

        configurator.getParameters().setProperty("fields", fields);
        configurator.getParameters().setProperty("lineNumber", Boolean.toString(lineNumber));
        configurator.getParameters().setProperty("skipLines", Integer.toString(skipLines));
        configurator.getParameters().setProperty("encoding", encoding.name());
        configurator.getParameters().setProperty("rootElementName", rootElementName);
        configurator.getParameters().setProperty("recordElementName", recordElementName);
        configurator.getParameters().setProperty("lineNumberAttributeName", lineNumberAttributeName);
        configurator.getParameters().setProperty("truncatedAttributeName", truncatedAttributeName);
        configurator.getParameters().setProperty("indent", Boolean.toString(indent));
        configurator.getParameters().setProperty("strict", Boolean.toString(strict));

        if(binding != null) {
            configurator.getParameters().setProperty("bindBeanId", binding.getBeanId());
            configurator.getParameters().setProperty("bindBeanClass", binding.getBeanClass().getName());
            configurator.getParameters().setProperty("bindingType", binding.getBindingType().toString());
            if(binding.getBindingType() == FixedLengthBindingType.MAP) {
                if(binding.getKeyField() == null) {
                    throw new SmooksConfigurationException("Fixed length 'MAP' Binding must specify a 'keyField' property on the binding configuration.");
                }
                configurator.getParameters().setProperty("bindMapKeyField", binding.getKeyField());
            }
        }

        configurator.setTargetProfile(targetProfile);

        return configurator.toConfig();
    }
View Full Code Here

        this.targetProfile = targetProfile;
        return this;
    }

    public List<SmooksResourceConfiguration> toConfig() {
        GenericReaderConfigurator configurator = new GenericReaderConfigurator(FlatFileReader.class);

        configurator.getParameters().setProperty("parserFactory", CSVRecordParserFactory.class.getName());
        configurator.getParameters().setProperty("fields", csvFields);
        configurator.getParameters().setProperty("separator", Character.toString(separatorChar));
        configurator.getParameters().setProperty("quote-char", Character.toString(quoteChar));
        configurator.getParameters().setProperty("escape-char", Character.toString(escapeChar));
        configurator.getParameters().setProperty("skip-line-count", Integer.toString(skipLineCount));
        configurator.getParameters().setProperty("encoding", encoding.name());
        configurator.getParameters().setProperty("rootElementName", rootElementName);
        configurator.getParameters().setProperty("recordElementName", recordElementName);
        configurator.getParameters().setProperty("indent", Boolean.toString(indent));
        configurator.getParameters().setProperty("strict", Boolean.toString(strict));

        if (binding != null) {
            configurator.getParameters().setProperty("bindBeanId", binding.getBeanId());
            configurator.getParameters().setProperty("bindBeanClass", binding.getBeanClass().getName());
            configurator.getParameters().setProperty("bindingType", binding.getBindingType().toString());
            if (binding.getBindingType() == CSVBindingType.MAP) {
                if (binding.getKeyField() == null) {
                    throw new SmooksConfigurationException(
                            "CSV 'MAP' Binding must specify a 'keyField' property on the binding configuration.");
                }
                configurator.getParameters().setProperty("bindMapKeyField", binding.getKeyField());
            }
        }

        configurator.setTargetProfile(targetProfile);

        return configurator.toConfig();
    }
View Full Code Here

   * Creates the SmooksResourceConfiguration from the defined settings.
   *
   * @return The SmooksResourceConfiguration
   */
  public List<SmooksResourceConfiguration> toConfig() {
        GenericReaderConfigurator configurator = new GenericReaderConfigurator(YamlReader.class);

        configurator.getParameters().setProperty("aliasStrategy", aliasStrategy.toString());
        configurator.getParameters().setProperty("anchorAttributeName", anchorAttributeName);
        configurator.getParameters().setProperty("aliasAttributeName", aliasAttributeName);
        configurator.getParameters().setProperty("indent", Boolean.toString(indent));
        configurator.getParameters().setProperty("rootName", rootName);
        configurator.getParameters().setProperty("documentName", documentName);
        configurator.getParameters().setProperty("arrayElementName", arrayElementName);
        if(keyWhitspaceReplacement != null) {
            configurator.getParameters().setProperty("keyWhitspaceReplacement", keyWhitspaceReplacement);
        }
        if(keyPrefixOnNumeric != null) {
            configurator.getParameters().setProperty("keyPrefixOnNumeric", keyPrefixOnNumeric);
        }
        if(illegalElementNameCharReplacement != null) {
            configurator.getParameters().setProperty("illegalElementNameCharReplacement", illegalElementNameCharReplacement);
        }
        configurator.setTargetProfile(targetProfile);

        List<SmooksResourceConfiguration> configList = configurator.toConfig();
        SmooksResourceConfiguration config = configList.get(0);

        if(keyMap != null) {
            Parameter keyMapParam = new Parameter(YamlReader.CONFIG_PARAM_KEY_MAP, keyMap);
            config.setParameter(keyMapParam);
View Full Code Here

        this.targetProfile = targetProfile;
        return this;
    }

    public List<SmooksResourceConfiguration> toConfig() {
        GenericReaderConfigurator configurator = new GenericReaderConfigurator(EDIReader.class);

        configurator.getParameters().setProperty(EDIReader.MODEL_CONFIG_KEY, mappingModel);
        configurator.setTargetProfile(targetProfile);

        return configurator.toConfig();
    }
View Full Code Here

        this.targetProfile = targetProfile;
        return this;
    }

    public List<SmooksResourceConfiguration> toConfig() {
        GenericReaderConfigurator configurator = new GenericReaderConfigurator(JSONReader.class);

        configurator.getParameters().setProperty("rootName", rootName);
        configurator.getParameters().setProperty("arrayElementName", arrayElementName);
        if(keyWhitspaceReplacement != null) {
            configurator.getParameters().setProperty("keyWhitspaceReplacement", keyWhitspaceReplacement);
        }
        if(keyPrefixOnNumeric != null) {
            configurator.getParameters().setProperty("keyPrefixOnNumeric", keyPrefixOnNumeric);
        }
        if(illegalElementNameCharReplacement != null) {
            configurator.getParameters().setProperty("illegalElementNameCharReplacement", illegalElementNameCharReplacement);
        }
        configurator.getParameters().setProperty("nullValueReplacement", nullValueReplacement);
        configurator.getParameters().setProperty("encoding", encoding.name());

        List<SmooksResourceConfiguration> configList = configurator.toConfig();
        SmooksResourceConfiguration config = configList.get(0);

        if(keyMap != null) {
            Parameter keyMapParam = new Parameter(JSONReader.CONFIG_PARAM_KEY_MAP, keyMap);
            config.setParameter(keyMapParam);
View Full Code Here

TOP

Related Classes of org.milyn.GenericReaderConfigurator

Copyright © 2018 www.massapicom. 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.