Search in sources :

Example 1 with TypeDescription

use of org.yaml.snakeyaml.TypeDescription 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 2 with TypeDescription

use of org.yaml.snakeyaml.TypeDescription 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 3 with TypeDescription

use of org.yaml.snakeyaml.TypeDescription in project eiger by wlloyd.

the class CliClient method loadHelp.

private CliUserHelp loadHelp() {
    final InputStream is = CliClient.class.getClassLoader().getResourceAsStream("org/apache/cassandra/cli/CliHelp.yaml");
    assert is != null;
    try {
        final Constructor constructor = new Constructor(CliUserHelp.class);
        TypeDescription desc = new TypeDescription(CliUserHelp.class);
        desc.putListPropertyType("commands", CliCommandHelp.class);
        final Yaml yaml = new Yaml(new Loader(constructor));
        return (CliUserHelp) yaml.load(is);
    } finally {
        FileUtils.closeQuietly(is);
    }
}
Also used : InputStream(java.io.InputStream) Constructor(org.yaml.snakeyaml.constructor.Constructor) TypeDescription(org.yaml.snakeyaml.TypeDescription) Loader(org.yaml.snakeyaml.Loader) Yaml(org.yaml.snakeyaml.Yaml)

Example 4 with TypeDescription

use of org.yaml.snakeyaml.TypeDescription in project storm by apache.

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 5 with TypeDescription

use of org.yaml.snakeyaml.TypeDescription in project Essentials by drtshock.

the class YamlStorageReader method prepareConstructor.

private void prepareConstructor(final Constructor constructor, final Set<Class> classes, final Class clazz) {
    classes.add(clazz);
    final TypeDescription description = new TypeDescription(clazz);
    for (Field field : clazz.getDeclaredFields()) {
        prepareList(field, description, classes, constructor);
        prepareMap(field, description, classes, constructor);
        if (StorageObject.class.isAssignableFrom(field.getType()) && !classes.contains(field.getType())) {
            prepareConstructor(constructor, classes, field.getType());
        }
    }
    constructor.addTypeDescription(description);
}
Also used : Field(java.lang.reflect.Field) TypeDescription(org.yaml.snakeyaml.TypeDescription)

Aggregations

TypeDescription (org.yaml.snakeyaml.TypeDescription)5 Constructor (org.yaml.snakeyaml.constructor.Constructor)4 Yaml (org.yaml.snakeyaml.Yaml)3 InputStream (java.io.InputStream)1 Field (java.lang.reflect.Field)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