org.yaml.snakeyaml.constructor.CustomClassLoaderConstructor Java Examples
The following examples show how to use
org.yaml.snakeyaml.constructor.CustomClassLoaderConstructor.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Utils.java From msf4j with Apache License 2.0 | 6 votes |
public static TransportsConfiguration resolveTransportsNSConfiguration(Object transportsConfig) throws ConfigurationException { TransportsConfiguration transportsConfiguration; if (transportsConfig instanceof Map) { LinkedHashMap httpConfig = ((LinkedHashMap) ((Map) transportsConfig).get("http")); if (httpConfig != null) { String configYaml = new Yaml().dump(httpConfig); Yaml yaml = new Yaml(new CustomClassLoaderConstructor(TransportsConfiguration.class, TransportsConfiguration.class.getClassLoader())); yaml.setBeanAccess(BeanAccess.FIELD); transportsConfiguration = yaml.loadAs(configYaml, TransportsConfiguration.class); } else { transportsConfiguration = new TransportsConfiguration(); } } else { throw new ConfigurationException("The first level config under 'transports' namespace should be " + "a map."); } return transportsConfiguration; }
Example #2
Source File: YAMLConfigManager.java From siddhi with Apache License 2.0 | 6 votes |
/** * Initialises YAML Config Manager by parsing the YAML file * * @throws YAMLConfigManagerException Exception is thrown if there are issues in processing thr yaml file */ private void init(String yamlContent) throws YAMLConfigManagerException { try { CustomClassLoaderConstructor constructor = new CustomClassLoaderConstructor( RootConfiguration.class, RootConfiguration.class.getClassLoader()); PropertyUtils propertyUtils = new PropertyUtils(); propertyUtils.setSkipMissingProperties(true); constructor.setPropertyUtils(propertyUtils); Yaml yaml = new Yaml(constructor); yaml.setBeanAccess(BeanAccess.FIELD); this.rootConfiguration = yaml.load(yamlContent); } catch (Exception e) { throw new YAMLConfigManagerException("Unable to parse YAML string, '" + yamlContent + "'.", e); } }
Example #3
Source File: SaltReturnHandlerRegistry.java From salt-step with BSD 3-Clause "New" or "Revised" License | 6 votes |
@SuppressWarnings("unchecked") protected void configureFromInputStream(InputStream is) { Yaml yaml = new Yaml(new CustomClassLoaderConstructor(getClass().getClassLoader())); Map<String, Object> document = (Map<String, Object>) yaml.load(is); if (document == null || !document.containsKey(HANDLER_MAPPINGS_KEY)) { throw new IllegalArgumentException(String.format("Expected yaml document with key: %s", HANDLER_MAPPINGS_KEY)); } else { Map<String, SaltReturnHandler> handlers = (Map<String, SaltReturnHandler>) document .get(HANDLER_MAPPINGS_KEY); for (Map.Entry<String, SaltReturnHandler> entry : handlers.entrySet()) { if (handlerMap.containsKey(entry.getKey())) { throw new IllegalStateException(String.format( "Already received a salt return handler configuration entry for %s", entry.getKey())); } handlerMap.put(entry.getKey(), entry.getValue()); } } }
Example #4
Source File: YamlToPipeline.java From simple-pull-request-job-plugin with Apache License 2.0 | 5 votes |
public YamlPipeline loadYaml(InputStream yamlScriptInputStream, TaskListener listener) { CustomClassLoaderConstructor constructor = new CustomClassLoaderConstructor(this.getClass().getClassLoader()); Yaml yaml = new Yaml(constructor); YamlPipeline yamlPipeline = yaml.loadAs(yamlScriptInputStream, YamlPipeline.class); if (yamlPipeline.getStages() != null && yamlPipeline.getSteps() != null) { throw new IllegalStateException("Only one of 'steps' or 'stages' must be present in the YAML file."); } return yamlPipeline; }
Example #5
Source File: Info.java From gateplugin-LearningFramework with GNU Lesser General Public License v2.1 | 5 votes |
/** * Save to directory. * @param directory directory to save to. */ public void save(File directory) { CustomClassLoaderConstructor constr = new CustomClassLoaderConstructor(this.getClass().getClassLoader()); String dump = new Yaml(constr) .dumpAs(this,Tag.MAP,DumperOptions.FlowStyle.BLOCK); File infoFile = new File(directory,FILENAME_INFO); //System.err.println("Saving engine to "+infoFile); try (OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(infoFile),"UTF-8")) { out.append(dump); } catch (IOException ex) { throw new GateRuntimeException("Could not write info file "+infoFile,ex); } }
Example #6
Source File: Info.java From gateplugin-LearningFramework with GNU Lesser General Public License v2.1 | 5 votes |
/** * Load from directory. * @param directory directory to load from * @return Info instance */ public static Info load(URL directory) { CustomClassLoaderConstructor constr = new CustomClassLoaderConstructor(Info.class.getClassLoader()); Yaml yaml = new Yaml(constr); Object obj; URL infoFile = newURL(directory,FILENAME_INFO); try (InputStream is = infoFile.openStream()) { obj = yaml.loadAs(new InputStreamReader(is,"UTF-8"),Info.class); } catch (IOException ex) { throw new GateRuntimeException("Could not load info file "+infoFile,ex); } Info info = (Info)obj; return info; }
Example #7
Source File: Fixtures.java From restcommander with Apache License 2.0 | 3 votes |
/** * Load and parse a plain YAML file and returns the corresponding Java Map. * The YAML parser used is SnakeYAML (http://code.google.com/p/snakeyaml/) * @param name Name of a YAML file somewhere in the classpath (or conf/)me * @param clazz the expected class * @return Object representing the YAML data */ @SuppressWarnings("unchecked") public static <T> T loadYaml(String name, Class<T> clazz) { Yaml yaml = new Yaml(new CustomClassLoaderConstructor(clazz, Play.classloader)); yaml.setBeanAccess(BeanAccess.FIELD); return (T)loadYaml(name, yaml); }