private static <T> T parseObject(String rawConfig) { Constructor constructor = new Constructor(ConfiguratorConfig.class); TypeDescription itemDescription = new TypeDescription(ConfiguratorConfig.class); itemDescription.addPropertyParameters("items", ConfigItem.class); constructor.addTypeDescription(itemDescription); Yaml yaml = new Yaml(constructor); return yaml.load(rawConfig); }
private static <T> T parseObject(String rawConfig) { Constructor constructor = new Constructor(ConfiguratorConfig.class); TypeDescription itemDescription = new TypeDescription(ConfiguratorConfig.class); itemDescription.addPropertyParameters("items", ConfigItem.class); constructor.addTypeDescription(itemDescription); Yaml yaml = new Yaml(constructor); return yaml.load(rawConfig); }
public Constructor(TypeDescription theRoot, Collection<TypeDescription> moreTDs) { if (theRoot == null) { throw new NullPointerException("Root type must be provided."); } this.yamlConstructors.put(null, new ConstructYamlObject()); if (!Object.class.equals(theRoot.getType())) { rootTag = new Tag(theRoot.getType()); } yamlClassConstructors.put(NodeId.scalar, new ConstructScalar()); yamlClassConstructors.put(NodeId.mapping, new ConstructMapping()); yamlClassConstructors.put(NodeId.sequence, new ConstructSequence()); addTypeDescription(theRoot); if (moreTDs != null) { for (TypeDescription td : moreTDs) { addTypeDescription(td); } } }
protected void addTypeDescription(Constructor configConstructor) { TypeDescription mapPropertyTypeDesc = new TypeDescription(MapPropertyTypeDef.class); mapPropertyTypeDesc.putMapPropertyType("parameters", String.class, String.class); configConstructor.addTypeDescription(mapPropertyTypeDesc); }
public static TagRouterRule parse(String rawRule) { Constructor constructor = new Constructor(TagRouterRule.class); TypeDescription tagDescription = new TypeDescription(TagRouterRule.class); tagDescription.addPropertyParameters("tags", Tag.class); constructor.addTypeDescription(tagDescription); Yaml yaml = new Yaml(constructor); TagRouterRule rule = yaml.load(rawRule); rule.setRawRule(rawRule); if (CollectionUtils.isEmpty(rule.getTags())) { rule.setValid(false); } rule.init(); return rule; } }
public static TagRouterRule parse(String rawRule) { Constructor constructor = new Constructor(TagRouterRule.class); TypeDescription tagDescription = new TypeDescription(TagRouterRule.class); tagDescription.addPropertyParameters("tags", Tag.class); constructor.addTypeDescription(tagDescription); Yaml yaml = new Yaml(constructor); TagRouterRule rule = yaml.load(rawRule); rule.setRawRule(rawRule); if (CollectionUtils.isEmpty(rule.getTags())) { rule.setValid(false); } rule.init(); return rule; } }
private static Yaml yaml() { TypeDescription topologyDescription = new TypeDescription(TopologyDef.class); topologyDescription.putListPropertyType("spouts", SpoutDef.class); topologyDescription.putListPropertyType("bolts", BoltDef.class); topologyDescription.putListPropertyType("includes", IncludeDef.class); Constructor constructor = new Constructor(TopologyDef.class); constructor.addTypeDescription(topologyDescription); Yaml yaml = new Yaml(constructor); return yaml; }
suiteDescription.putListPropertyType("tests", XmlTest.class); suiteDescription.putListPropertyType("method-selectors", XmlMethodSelector.class); constructor.addTypeDescription(suiteDescription); testDescription.putMapPropertyType("metaGroups", String.class, List.class); testDescription.putListPropertyType("method-selectors", XmlMethodSelector.class); constructor.addTypeDescription(testDescription);
suiteDescription.addPropertyParameters("tests", XmlTest.class); suiteDescription.addPropertyParameters("method-selectors", XmlMethodSelector.class); constructor.addTypeDescription(suiteDescription); testDescription.addPropertyParameters("metaGroups", String.class, List.class); testDescription.addPropertyParameters("method-selectors", XmlMethodSelector.class); constructor.addTypeDescription(testDescription);
public RecipeConfigParser() { Constructor constructor = new Constructor(Recipe.class); TypeDescription carDescription = new TypeDescription(Recipe.class); constructor.addTypeDescription(carDescription); Yaml yaml = new Yaml(constructor); Recipe recipe = (Recipe) yaml.load("ecommerce_test.yml"); }
/** * Read configuration from a file into a new {@link Settings} object. * * @param stream an input stream containing a Gremlin Server YAML configuration */ public static Settings read(final InputStream stream) { Objects.requireNonNull(stream); final Constructor constructor = new Constructor(Settings.class); final TypeDescription settingsDescription = new TypeDescription(Settings.class); settingsDescription.putListPropertyType("hosts", String.class); settingsDescription.putListPropertyType("serializers", SerializerSettings.class); constructor.addTypeDescription(settingsDescription); final Yaml yaml = new Yaml(constructor); return yaml.loadAs(stream, Settings.class); }
settingsDescription.putListPropertyType("plugins", String.class); settingsDescription.putListPropertyType("processors", ProcessorSettings.class); constructor.addTypeDescription(settingsDescription); constructor.addTypeDescription(serializerSettingsDescription); scriptEngineSettingsDescription.putMapPropertyType("config", String.class, Object.class); scriptEngineSettingsDescription.putMapPropertyType("plugins", String.class, Object.class); constructor.addTypeDescription(scriptEngineSettingsDescription); constructor.addTypeDescription(sslSettings); constructor.addTypeDescription(authenticationSettings); constructor.addTypeDescription(serverMetricsDescription); constructor.addTypeDescription(consoleReporterDescription); constructor.addTypeDescription(csvReporterDescription); constructor.addTypeDescription(jmxReporterDescription); constructor.addTypeDescription(slf4jReporterDescription); constructor.addTypeDescription(gangliaReporterDescription); constructor.addTypeDescription(graphiteReporterDescription);
public static VNFDTemplate fileToVNFDTemplate(String fileName) throws FileNotFoundException { InputStream tosca = new FileInputStream(new File(fileName)); Constructor constructor = new Constructor(VNFDTemplate.class); TypeDescription projectDesc = new TypeDescription(VNFDTemplate.class); constructor.addTypeDescription(projectDesc); Yaml yaml = new Yaml(constructor); return yaml.loadAs(tosca, VNFDTemplate.class); }
public static VNFDTemplate bytesToVNFDTemplate(ByteArrayOutputStream b) { Constructor constructor = new VnfdTemplateConstructor(); TypeDescription projectDesc = new TypeDescription(VNFDTemplate.class); constructor.addTypeDescription(projectDesc); Yaml yaml = new Yaml(constructor); return yaml.loadAs(new ByteArrayInputStream(b.toByteArray()), VNFDTemplate.class); }
private Yaml constructYaml(Class<?> cls) { if (cls != null) { Constructor constructor = new Constructor(); constructor.addTypeDescription(new TypeDescription(cls, "!" + cls.getSimpleName())); return new Yaml(constructor); } return new Yaml(); }
/** * Overridden to capture what tags are defined specially. */ @Override public TypeDescription addTypeDescription(TypeDescription definition) { if(definition != null && definition.getTag() != null) { tagsDefined.add(definition.getTag()); } return super.addTypeDescription(definition); }
private Yaml getCustomYaml() { Constructor constructor = new Constructor(CSVStmtDoc.class); TypeDescription tds = new TypeDescription(CSVStmtDoc.class); tds.putListPropertyType("blocks", CSVStmtBlock.class); constructor.addTypeDescription(tds); return new Yaml(constructor); }
private static Yaml yaml() { TypeDescription topologyDescription = new TypeDescription(TopologyDef.class); topologyDescription.putListPropertyType("spouts", SpoutDef.class); topologyDescription.putListPropertyType("bolts", BoltDef.class); topologyDescription.putListPropertyType("includes", IncludeDef.class); Constructor constructor = new Constructor(TopologyDef.class); constructor.addTypeDescription(topologyDescription); Yaml yaml = new Yaml(constructor); return yaml; }
@Test @Ignore public void testVNFDTemplate() throws FileNotFoundException { InputStream vnfdFile = new FileInputStream(new File("src/main/resources/Testing/testVNFDTemplate.yaml")); Constructor constructor = new Constructor(VNFDTemplate.class); TypeDescription typeDescription = new TypeDescription(VNFDTemplate.class); constructor.addTypeDescription(typeDescription); Yaml yaml = new Yaml(constructor); VNFDTemplate vnfdInput = yaml.loadAs(vnfdFile, VNFDTemplate.class); System.out.println(vnfdInput.toString()); }
private static Yaml getYaml() { Representer representer = new TapeRepresenter(); representer.addClassTag(YamlTape.class, YamlTape.TAPE_TAG); Constructor constructor = new TapeConstructor(); constructor.addTypeDescription(new TypeDescription(YamlTape.class, YamlTape.TAPE_TAG)); DumperOptions dumperOptions = new DumperOptions(); dumperOptions.setDefaultFlowStyle(BLOCK); dumperOptions.setWidth(256); Yaml yaml = new Yaml(constructor, representer, dumperOptions); yaml.setBeanAccess(BeanAccess.FIELD); return yaml; } }