Search in sources :

Example 1 with Constructor

use of org.yaml.snakeyaml.constructor.Constructor in project sharding-jdbc by dangdangdotcom.

the class BestEffortsDeliveryJobMain method main.

/**
     * 启动入口.
     * 
     * @param args 启动参数
     */
// CHECKSTYLE:OFF
public static void main(final String[] args) throws Exception {
    // CHECKSTYLE:ON
    try (InputStreamReader inputStreamReader = new InputStreamReader(BestEffortsDeliveryJobMain.class.getResourceAsStream("/conf/config.yaml"), "UTF-8")) {
        BestEffortsDeliveryConfiguration config = new Yaml(new Constructor(BestEffortsDeliveryConfiguration.class)).loadAs(inputStreamReader, BestEffortsDeliveryConfiguration.class);
        new BestEffortsDeliveryJobFactory(config).init();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) Constructor(org.yaml.snakeyaml.constructor.Constructor) Yaml(org.yaml.snakeyaml.Yaml)

Example 2 with Constructor

use of org.yaml.snakeyaml.constructor.Constructor in project jstorm by alibaba.

the class FluxParser method yaml.

private static Yaml yaml() {
    Constructor constructor = new Constructor(TopologyDef.class);
    TypeDescription topologyDescription = new TypeDescription(TopologyDef.class);
    topologyDescription.putListPropertyType("spouts", SpoutDef.class);
    topologyDescription.putListPropertyType("bolts", BoltDef.class);
    topologyDescription.putListPropertyType("includes", IncludeDef.class);
    constructor.addTypeDescription(topologyDescription);
    Yaml yaml = new Yaml(constructor);
    return yaml;
}
Also used : Constructor(org.yaml.snakeyaml.constructor.Constructor) TypeDescription(org.yaml.snakeyaml.TypeDescription) Yaml(org.yaml.snakeyaml.Yaml)

Example 3 with Constructor

use of org.yaml.snakeyaml.constructor.Constructor in project es6draft by anba.

the class Test262Info method readYaml.

private void readYaml(String descriptor, boolean lenient) throws MalformedDataException {
    assert descriptor != null && !descriptor.isEmpty();
    Yaml yaml = null;
    if (lenient) {
        yaml = yamlQueue.poll();
    }
    if (yaml == null) {
        Constructor constructor = new Constructor(TestDescriptor.class);
        if (lenient) {
            PropertyUtils utils = new PropertyUtils();
            utils.setSkipMissingProperties(true);
            constructor.setPropertyUtils(utils);
        }
        yaml = new Yaml(constructor);
    }
    TestDescriptor desc;
    try {
        desc = yaml.loadAs(descriptor, TestDescriptor.class);
    } catch (YAMLException e) {
        throw new MalformedDataException(e.getMessage(), e);
    }
    if (lenient) {
        yamlQueue.offer(yaml);
    }
    this.description = desc.getDescription();
    this.includes = desc.getIncludes();
    this.features = desc.getFeatures();
    this.errorType = desc.getNegative();
    this.negative = desc.getNegative() != null;
    if (!desc.getFlags().isEmpty()) {
        if (!lenient) {
            for (String flag : desc.getFlags()) {
                if (!allowedFlags.contains(flag)) {
                    throw new MalformedDataException(String.format("Unknown flag '%s'", flag));
                }
            }
        }
        this.negative |= desc.getFlags().contains("negative");
        this.noStrict = desc.getFlags().contains("noStrict");
        this.onlyStrict = desc.getFlags().contains("onlyStrict");
        this.module = desc.getFlags().contains("module");
        this.raw = desc.getFlags().contains("raw");
    }
}
Also used : PropertyUtils(org.yaml.snakeyaml.introspector.PropertyUtils) Constructor(org.yaml.snakeyaml.constructor.Constructor) YAMLException(org.yaml.snakeyaml.error.YAMLException) Yaml(org.yaml.snakeyaml.Yaml)

Example 4 with Constructor

use of org.yaml.snakeyaml.constructor.Constructor in project camel by apache.

the class SnakeYAMLDataFormat method defaultConstructor.

// ***************************
// Defaults
// ***************************
private BaseConstructor defaultConstructor(CamelContext context) {
    ClassLoader yamlClassLoader = this.classLoader;
    Collection<TypeFilter> yamlTypeFilters = this.typeFilters;
    if (yamlClassLoader == null && useApplicationContextClassLoader) {
        yamlClassLoader = context.getApplicationContextClassLoader();
    }
    if (allowAnyType) {
        yamlTypeFilters = Collections.singletonList(TypeFilters.allowAll());
    }
    BaseConstructor yamlConstructor;
    if (yamlTypeFilters != null) {
        yamlConstructor = yamlClassLoader != null ? typeFilterConstructor(yamlClassLoader, yamlTypeFilters) : typeFilterConstructor(yamlTypeFilters);
    } else {
        yamlConstructor = new SafeConstructor();
    }
    if (typeDescriptions != null && yamlConstructor instanceof Constructor) {
        for (TypeDescription typeDescription : typeDescriptions) {
            ((Constructor) yamlConstructor).addTypeDescription(typeDescription);
        }
    }
    return yamlConstructor;
}
Also used : BaseConstructor(org.yaml.snakeyaml.constructor.BaseConstructor) BaseConstructor(org.yaml.snakeyaml.constructor.BaseConstructor) SafeConstructor(org.yaml.snakeyaml.constructor.SafeConstructor) CustomClassLoaderConstructor(org.yaml.snakeyaml.constructor.CustomClassLoaderConstructor) Constructor(org.yaml.snakeyaml.constructor.Constructor) SafeConstructor(org.yaml.snakeyaml.constructor.SafeConstructor) TypeDescription(org.yaml.snakeyaml.TypeDescription)

Example 5 with Constructor

use of org.yaml.snakeyaml.constructor.Constructor in project cassandra by apache.

the class StressProfile method load.

public static StressProfile load(URI file) throws IOError {
    try {
        Constructor constructor = new Constructor(StressYaml.class);
        Yaml yaml = new Yaml(constructor);
        InputStream yamlStream = file.toURL().openStream();
        if (yamlStream.available() == 0)
            throw new IOException("Unable to load yaml file from: " + file);
        StressYaml profileYaml = yaml.loadAs(yamlStream, StressYaml.class);
        StressProfile profile = new StressProfile();
        profile.init(profileYaml);
        return profile;
    } catch (YAMLException | IOException | RequestValidationException e) {
        throw new IOError(e);
    }
}
Also used : IOError(java.io.IOError) Constructor(org.yaml.snakeyaml.constructor.Constructor) InputStream(java.io.InputStream) YAMLException(org.yaml.snakeyaml.error.YAMLException) IOException(java.io.IOException) RequestValidationException(org.apache.cassandra.exceptions.RequestValidationException) Yaml(org.yaml.snakeyaml.Yaml)

Aggregations

Constructor (org.yaml.snakeyaml.constructor.Constructor)10 Yaml (org.yaml.snakeyaml.Yaml)8 TypeDescription (org.yaml.snakeyaml.TypeDescription)4 InputStream (java.io.InputStream)3 YAMLException (org.yaml.snakeyaml.error.YAMLException)3 IOException (java.io.IOException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOError (java.io.IOError)1 InputStreamReader (java.io.InputStreamReader)1 ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)1 RequestValidationException (org.apache.cassandra.exceptions.RequestValidationException)1 Loader (org.yaml.snakeyaml.Loader)1 BaseConstructor (org.yaml.snakeyaml.constructor.BaseConstructor)1 CustomClassLoaderConstructor (org.yaml.snakeyaml.constructor.CustomClassLoaderConstructor)1 SafeConstructor (org.yaml.snakeyaml.constructor.SafeConstructor)1 PropertyUtils (org.yaml.snakeyaml.introspector.PropertyUtils)1