Java 类org.yaml.snakeyaml.constructor.Constructor 实例源码

项目:marathonv5    文件:ObjectMapItem.java   
private Object loadYaml(File omapfile) throws IOException {
    FileReader reader = new FileReader(omapfile);
    try {
        Constructor constructor = new Constructor();
        PropertyUtils putils = new PropertyUtils();
        putils.setSkipMissingProperties(true);
        constructor.setPropertyUtils(putils);
        Yaml yaml = new Yaml(constructor);
        return yaml.load(reader);
    } catch (Throwable t) {
        throw new RuntimeException("Error loading yaml from: " + omapfile.getAbsolutePath() + "\n" + t.getMessage(), t);
    } finally {
        try {
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
项目:spring-cloud-skipper    文件:DefaultPackageReader.java   
private PackageMetadata loadPackageMetadata(File file) {
    // The Representer will not try to set the value in the YAML on the
    // Java object if it isn't present on the object
    Representer representer = new Representer();
    representer.getPropertyUtils().setSkipMissingProperties(true);
    Yaml yaml = new Yaml(new Constructor(PackageMetadata.class), representer);
    String fileContents = null;
    try {
        fileContents = FileUtils.readFileToString(file);
    }
    catch (IOException e) {
        e.printStackTrace();
    }
    PackageMetadata pkgMetadata = (PackageMetadata) yaml.load(fileContents);
    return pkgMetadata;
}
项目:cdep    文件:V3Reader.java   
@NotNull
public static io.cdep.cdep.yml.cdepmanifest.CDepManifestYml convertStringToManifest(@NotNull String content) {
  Yaml yaml = new Yaml(new Constructor(io.cdep.cdep.yml.cdepmanifest.v3.CDepManifestYml.class));
  io.cdep.cdep.yml.cdepmanifest.CDepManifestYml manifest;
  try {
    CDepManifestYml prior = (CDepManifestYml) yaml.load(
        new ByteArrayInputStream(content.getBytes(StandardCharsets
            .UTF_8)));
    prior.sourceVersion = CDepManifestYmlVersion.v3;
    manifest = convert(prior);
    require(manifest.sourceVersion == CDepManifestYmlVersion.v3);
  } catch (YAMLException e) {
    manifest = convert(V2Reader.convertStringToManifest(content));
  }
  return manifest;
}
项目:CloudNet    文件:YamlConfiguration.java   
@Override
protected Yaml initialValue()
{
    Representer representer = new Representer() {
        {
            representers.put(Configuration.class, new Represent() {
                @Override
                public Node representData(Object data)
                {
                    return represent(((Configuration) data).self);
                }
            });
        }
    };

    DumperOptions options = new DumperOptions();
    options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);

    return new Yaml(new Constructor(), representer, options);
}
项目:marathonv5    文件:OMapContainer.java   
private Object loadYaml(File file) throws FileNotFoundException {
    FileReader reader = new FileReader(file);
    try {
        Constructor constructor = new Constructor();
        PropertyUtils putils = new PropertyUtils();
        putils.setSkipMissingProperties(true);
        constructor.setPropertyUtils(putils);
        Yaml yaml = new Yaml(constructor);
        return yaml.load(reader);
    } catch (Throwable t) {
        throw new RuntimeException("Error loading yaml from: " + file.getAbsolutePath() + "\n" + t.getMessage(), t);
    } finally {
        try {
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
项目:Biliomi    文件:UserSettingsProducer.java   
@PostConstruct
private void initUserSettingsProducer() {
  try {
    File coreYml = new File(BiliomiContainer.getParameters().getConfigurationDir(), "core.yml");
    Yaml yamlInstance = new Yaml(new Constructor(YamlCoreSettings.class));
    yamlCoreSettings = yamlInstance.loadAs(new FileInputStream(coreYml), YamlCoreSettings.class);

    String updateMode = yamlCoreSettings.getBiliomi().getCore().getUpdateMode();
    // Somehow Yaml thinks "off" means "false"
    if (StringUtils.isEmpty(updateMode)) {
      this.updateMode = UpdateModeType.OFF;
    } else {
      this.updateMode = EnumUtils.toEnum(updateMode, UpdateModeType.class);
    }
  } catch (FileNotFoundException e) {
    this.yamlCoreSettings = new YamlCoreSettings();
    ObjectGraphs.initializeObjectGraph(this.yamlCoreSettings);
    this.updateMode = UpdateModeType.INSTALL;
    this.yamlCoreSettings.getBiliomi().getCore().setUpdateMode(this.updateMode.toString());
  }
}
项目:waggle-dance    文件:YamlFactory.java   
public static Yaml newYaml() {
  PropertyUtils propertyUtils = new AdvancedPropertyUtils();
  propertyUtils.setSkipMissingProperties(true);

  Constructor constructor = new Constructor(Federations.class);
  TypeDescription federationDescription = new TypeDescription(Federations.class);
  federationDescription.putListPropertyType("federatedMetaStores", FederatedMetaStore.class);
  constructor.addTypeDescription(federationDescription);
  constructor.setPropertyUtils(propertyUtils);

  Representer representer = new AdvancedRepresenter();
  representer.setPropertyUtils(new FieldOrderPropertyUtils());
  representer.addClassTag(Federations.class, Tag.MAP);
  representer.addClassTag(AbstractMetaStore.class, Tag.MAP);
  representer.addClassTag(WaggleDanceConfiguration.class, Tag.MAP);
  representer.addClassTag(YamlStorageConfiguration.class, Tag.MAP);
  representer.addClassTag(GraphiteConfiguration.class, Tag.MAP);

  DumperOptions dumperOptions = new DumperOptions();
  dumperOptions.setIndent(2);
  dumperOptions.setDefaultFlowStyle(FlowStyle.BLOCK);

  return new Yaml(constructor, representer, dumperOptions);
}
项目:snake-yaml    文件:StaticFieldsWrapperTest.java   
/**
 * use wrapper with local tag
 */
public void testLocalTag() {
    JavaBeanWithStaticState bean = new JavaBeanWithStaticState();
    bean.setName("Bahrack");
    bean.setAge(-47);
    JavaBeanWithStaticState.setType("Type3");
    JavaBeanWithStaticState.color = "Violet";
    Representer repr = new Representer();
    repr.addClassTag(Wrapper.class, new Tag("!mybean"));
    Yaml yaml = new Yaml(repr);
    String output = yaml.dump(new Wrapper(bean));
    // System.out.println(output);
    assertEquals("!mybean {age: -47, color: Violet, name: Bahrack, type: Type3}\n", output);
    // parse back to instance
    Constructor constr = new Constructor();
    TypeDescription description = new TypeDescription(Wrapper.class, new Tag("!mybean"));
    constr.addTypeDescription(description);
    yaml = new Yaml(constr);
    Wrapper wrapper = (Wrapper) yaml.load(output);
    JavaBeanWithStaticState bean2 = wrapper.createBean();
    assertEquals(-47, bean2.getAge());
    assertEquals("Bahrack", bean2.getName());
}
项目:snake-yaml    文件:TypeSafePriorityTest.java   
/**
 * explicit TypeDescription is more important then runtime class (which may
 * be an interface)
 */
public void testLoadList2() {
    String output = Util.getLocalResource("examples/list-bean-3.yaml");
    // System.out.println(output);
    TypeDescription descr = new TypeDescription(ListBean.class);
    descr.putListPropertyType("developers", Developer.class);
    Yaml beanLoader = new Yaml(new Constructor(descr));
    ListBean parsed = beanLoader.loadAs(output, ListBean.class);
    assertNotNull(parsed);
    List<Human> developers = parsed.getDevelopers();
    assertEquals(2, developers.size());
    assertEquals("Committer must be recognised.", Developer.class, developers.get(0).getClass());
    Developer fred = (Developer) developers.get(0);
    assertEquals("Fred", fred.getName());
    assertEquals("creator", fred.getRole());
    Developer john = (Developer) developers.get(1);
    assertEquals("John", john.getName());
    assertEquals("committer", john.getRole());
}
项目:snake-yaml    文件:Human_WithArrayOfChildrenTest.java   
public void testChildrenArray() {
    Constructor constructor = new Constructor(Human_WithArrayOfChildren.class);
    TypeDescription HumanWithChildrenArrayDescription = new TypeDescription(
            Human_WithArrayOfChildren.class);
    HumanWithChildrenArrayDescription.putListPropertyType("children",
            Human_WithArrayOfChildren.class);
    constructor.addTypeDescription(HumanWithChildrenArrayDescription);
    Human_WithArrayOfChildren son = createSon();
    Yaml yaml = new Yaml(constructor);
    String output = yaml.dump(son);
    // System.out.println(output);
    String etalon = Util.getLocalResource("recursive/with-childrenArray.yaml");
    assertEquals(etalon, output);
    //
    Human_WithArrayOfChildren son2 = (Human_WithArrayOfChildren) yaml.load(output);
    checkSon(son2);
}
项目:snake-yaml    文件:MergeJavaBeanTest.java   
/**
 * Merge map to JavaBean
 */
@SuppressWarnings("unchecked")
public void testMergeMapToJavaBean() {
    String input = "- &id001 { age: 11, id: id123 }\n- !!org.yaml.snakeyaml.issues.issue100.Data\n  <<: *id001\n  id: id456";
    // System.out.println(input);
    Yaml yaml = new Yaml(new Constructor());
    List<Object> objects = (List<Object>) yaml.load(input);
    assertEquals(2, objects.size());
    // Check first type
    Object first = objects.get(0);
    Map<Object, Object> firstMap = (Map<Object, Object>) first;
    // Check first contents
    assertEquals(11, firstMap.get("age"));
    assertEquals("id123", firstMap.get("id"));
    // Check second contents
    Data secondData = (Data) objects.get(1);
    assertEquals(11, secondData.getAge());
    assertEquals("id456", secondData.getId());
}
项目:snake-yaml    文件:PerlTest.java   
@SuppressWarnings("unchecked")
public void testJavaBeanWithTypeDescription() {
    Constructor c = new CustomBeanConstructor();
    TypeDescription descr = new TypeDescription(CodeBean.class, new Tag(
            "!de.oddb.org,2007/ODDB::Util::Code"));
    c.addTypeDescription(descr);
    Yaml yaml = new Yaml(c);
    String input = Util.getLocalResource("issues/issue56-1.yaml");
    int counter = 0;
    for (Object obj : yaml.loadAll(input)) {
        // System.out.println(obj);
        Map<String, Object> map = (Map<String, Object>) obj;
        Integer oid = (Integer) map.get("oid");
        assertTrue(oid > 10000);
        counter++;
    }
    assertEquals(4, counter);
    assertEquals(55, CodeBean.counter);
}
项目:snake-yaml    文件:PerlTest.java   
@SuppressWarnings("unchecked")
public void testJavaBean() {
    Constructor c = new CustomBeanConstructor();
    Yaml yaml = new Yaml(c);
    String input = Util.getLocalResource("issues/issue56-1.yaml");
    int counter = 0;
    for (Object obj : yaml.loadAll(input)) {
        // System.out.println(obj);
        Map<String, Object> map = (Map<String, Object>) obj;
        Integer oid = (Integer) map.get("oid");
        assertTrue(oid > 10000);
        counter++;
    }
    assertEquals(4, counter);
    assertEquals(55, CodeBean.counter);
}
项目:snake-yaml    文件:PropOrderInfluenceWhenAliasedInGenericCollectionTest.java   
public void testABProperty() {
    SuperSaverAccount supersaver = new SuperSaverAccount();
    GeneralAccount generalAccount = new GeneralAccount();

    CustomerAB_Property customerAB_property = new CustomerAB_Property();
    ArrayList<Account> all = new ArrayList<Account>();
    all.add(supersaver);
    all.add(generalAccount);
    ArrayList<GeneralAccount> general = new ArrayList<GeneralAccount>();
    general.add(generalAccount);
    general.add(supersaver);

    customerAB_property.acc = generalAccount;
    customerAB_property.bGeneral = general;

    Constructor constructor = new Constructor();
    Representer representer = new Representer();

    Yaml yaml = new Yaml(constructor, representer);
    String dump = yaml.dump(customerAB_property);
    // System.out.println(dump);
    CustomerAB_Property parsed = (CustomerAB_Property) yaml.load(dump);
    assertNotNull(parsed);
}
项目:snake-yaml    文件:ArrayInGenericCollectionTest.java   
public void testArrayAsMapValueWithTypeDespriptor() {
    Yaml yaml2dump = new Yaml();
    yaml2dump.setBeanAccess(BeanAccess.FIELD);
    A data = createA();
    String dump = yaml2dump.dump(data);
    // System.out.println(dump);

    TypeDescription aTypeDescr = new TypeDescription(A.class);
    aTypeDescr.putMapPropertyType("meta", String.class, String[].class);

    Constructor c = new Constructor();
    c.addTypeDescription(aTypeDescr);
    Yaml yaml2load = new Yaml(c);
    yaml2load.setBeanAccess(BeanAccess.FIELD);

    A loaded = (A) yaml2load.load(dump);

    assertEquals(data.meta.size(), loaded.meta.size());
    Set<Entry<String, String[]>> loadedMeta = loaded.meta.entrySet();
    for (Entry<String, String[]> entry : loadedMeta) {
        assertTrue(data.meta.containsKey(entry.getKey()));
        Assert.assertArrayEquals(data.meta.get(entry.getKey()), entry.getValue());
    }
}
项目:snake-yaml    文件:ArrayInGenericCollectionTest.java   
public void testArrayAsListValueWithTypeDespriptor() {
    Yaml yaml2dump = new Yaml();
    yaml2dump.setBeanAccess(BeanAccess.FIELD);
    B data = createB();
    String dump = yaml2dump.dump(data);
    // System.out.println(dump);

    TypeDescription aTypeDescr = new TypeDescription(B.class);
    aTypeDescr.putListPropertyType("meta", String[].class);

    Constructor c = new Constructor();
    c.addTypeDescription(aTypeDescr);
    Yaml yaml2load = new Yaml(c);
    yaml2load.setBeanAccess(BeanAccess.FIELD);

    B loaded = (B) yaml2load.load(dump);

    Assert.assertArrayEquals(data.meta.toArray(), loaded.meta.toArray());
}
项目:snake-yaml    文件:GlobalDirectivesTest.java   
public void testDirectives() {
    String input = Util.getLocalResource("issues/issue149-losing-directives.yaml");
    // System.out.println(input);
    Constructor constr = new Constructor();
    TypeDescription description = new TypeDescription(ComponentBean.class, new Tag(
            "tag:ualberta.ca,2012:" + 29));
    constr.addTypeDescription(description);
    Yaml yaml = new Yaml(constr);
    Iterator<Object> parsed = yaml.loadAll(input).iterator();
    ComponentBean bean1 = (ComponentBean) parsed.next();
    assertEquals(0, bean1.getProperty1());
    assertEquals("aaa", bean1.getProperty2());
    ComponentBean bean2 = (ComponentBean) parsed.next();
    assertEquals(3, bean2.getProperty1());
    assertEquals("bbb", bean2.getProperty2());
    assertFalse(parsed.hasNext());
}
项目:snake-yaml    文件:GlobalDirectivesTest.java   
public void testDirectives2() {
    String input = Util.getLocalResource("issues/issue149-losing-directives-2.yaml");
    // System.out.println(input);
    Constructor constr = new Constructor();
    TypeDescription description = new TypeDescription(ComponentBean.class, new Tag(
            "tag:ualberta.ca,2012:" + 29));
    constr.addTypeDescription(description);
    Yaml yaml = new Yaml(constr);
    Iterator<Object> parsed = yaml.loadAll(input).iterator();
    ComponentBean bean1 = (ComponentBean) parsed.next();
    assertEquals(0, bean1.getProperty1());
    assertEquals("aaa", bean1.getProperty2());
    ComponentBean bean2 = (ComponentBean) parsed.next();
    assertEquals(3, bean2.getProperty1());
    assertEquals("bbb", bean2.getProperty2());
    assertFalse(parsed.hasNext());
}
项目:snake-yaml    文件:AbstractBeanTest.java   
public void testErrorMessage() throws Exception {

        BeanA1 b = new BeanA1();
        b.setId(2l);
        b.setName("name1");

        Constructor c = new Constructor();
        Representer r = new Representer();

        PropertyUtils pu = new PropertyUtils();
        c.setPropertyUtils(pu);
        r.setPropertyUtils(pu);

        pu.getProperties(BeanA1.class, BeanAccess.FIELD);

        Yaml yaml = new Yaml(c, r);
        // yaml.setBeanAccess(BeanAccess.FIELD);
        String dump = yaml.dump(b);
        BeanA1 b2 = (BeanA1) yaml.load(dump);
        assertEquals(b.getId(), b2.getId());
        assertEquals(b.getName(), b2.getName());
    }
项目:snake-yaml    文件:EnumTest.java   
public void testLoadEnumBean2() {
    Constructor c = new Constructor();
    TypeDescription td = new TypeDescription(EnumBean.class);
    td.putMapPropertyType("map", Suit.class, Object.class);
    c.addTypeDescription(td);
    Yaml yaml = new Yaml(c);
    EnumBean bean = (EnumBean) yaml
            .load("!!org.yaml.snakeyaml.EnumBean\nid: 174\nmap:\n  CLUBS: 1\n  DIAMONDS: 2\nsuit: CLUBS");

    LinkedHashMap<Suit, Integer> map = new LinkedHashMap<Suit, Integer>();
    map.put(Suit.CLUBS, 1);
    map.put(Suit.DIAMONDS, 2);

    assertEquals(Suit.CLUBS, bean.getSuit());
    assertEquals(174, bean.getId());
    assertEquals(map, bean.getMap());
}
项目:snake-yaml    文件:CompactConstructorExampleTest.java   
public void test11withoutPackageNames() {
    Constructor compact = new PackageCompactConstructor(
            "org.yaml.snakeyaml.extensions.compactnotation");
    Yaml yaml = new Yaml(compact);
    String doc = Util.getLocalResource("compactnotation/example11.yaml");
    Box box = (Box) yaml.load(doc);
    assertNotNull(box);
    assertEquals("id11", box.getId());
    assertEquals("Main box", box.getName());
    Item top = box.getTop();
    assertEquals("id003", top.getId());
    assertEquals("25.0", top.getPrice());
    assertEquals("parrot", top.getName());
    Item bottom = box.getBottom();
    assertEquals("id004", bottom.getId());
    assertEquals("3.5", bottom.getPrice());
    assertEquals("sweet", bottom.getName());
}
项目:MapleStory    文件:YamlConfiguration.java   
@Override
protected Yaml initialValue()
{
    Representer representer = new Representer()
    {
        {
            representers.put( Configuration.class, new Represent()
            {
                @Override
                public Node representData(Object data)
                {
                    return represent( ( (Configuration) data ).self );
                }
            } );
        }
    };

    DumperOptions options = new DumperOptions();
    options.setDefaultFlowStyle( DumperOptions.FlowStyle.BLOCK );

    return new Yaml( new Constructor(), representer, options );
}
项目:jpa-unit    文件:YamlDataSetProducer.java   
public Yaml createYamlReader() {
    return new Yaml(new Constructor(), new Representer(), new DumperOptions(), new Resolver() {
        @Override
        protected void addImplicitResolvers() {
            // Intentionally left TIMESTAMP as string to let DBUnit deal with the conversion
            addImplicitResolver(Tag.BOOL, BOOL, "yYnNtTfFoO");
            addImplicitResolver(Tag.INT, INT, "-+0123456789");
            addImplicitResolver(Tag.FLOAT, FLOAT, "-+0123456789.");
            addImplicitResolver(Tag.MERGE, MERGE, "<");
            addImplicitResolver(Tag.NULL, NULL, "~nN\0");
            addImplicitResolver(Tag.NULL, EMPTY, null);
            addImplicitResolver(Tag.VALUE, VALUE, "=");
            addImplicitResolver(Tag.YAML, YAML, "!&*");
        }
    });
}
项目:icetone    文件:ThemeLoader.java   
@Override
public Object load(AssetInfo assetInfo) throws IOException {
    Constructor constructor = new Constructor();
    InputStream file = assetInfo.openStream();
    Yaml yaml = new Yaml(constructor);
    constructor.addTypeDescription(new TypeDescription(Theme.class, "!theme"));
    try {
        Theme theme = (Theme) yaml.load(file);
        String path = theme.getPath();
        if (path == null || path.equals("")) {
            theme.setPath(folderName(assetInfo.getKey().getName()) + "/" + theme.getName() + ".css");
        } else if (!path.startsWith("/")) {
            theme.setPath(folderName(assetInfo.getKey().getName()) + "/" + path);
        }
        return theme;
    } finally {
        file.close();
    }
}
项目:icetone    文件:LayoutLoader.java   
private void registerTypes(Constructor constructor) {
    // Standard controls
    constructor.addTypeDescription(new TypeDescription(PanelLayoutPart.class, "!panel"));
    constructor.addTypeDescription(new TypeDescription(LabelLayoutPart.class, "!label"));
    constructor.addTypeDescription(new TypeDescription(CheckBoxLayoutPart.class, "!checkBox"));
    constructor.addTypeDescription(new TypeDescription(DefaultButtonLayoutPart.class, "!button"));
    constructor.addTypeDescription(new TypeDescription(SplitPaneLayoutPart.class, "!splitPanel"));
    constructor.addTypeDescription(new TypeDescription(ScrollPanelLayoutPart.class, "!scrollPanel"));
    constructor.addTypeDescription(new TypeDescription(ContainerLayoutPart.class, "!container"));
    constructor.addTypeDescription(new TypeDescription(FrameLayoutPart.class, "!frame"));
    constructor.addTypeDescription(new TypeDescription(TextFieldLayoutPart.class, "!textField"));
    constructor.addTypeDescription(new TypeDescription(PasswordLayoutPart.class, "!password"));
    constructor.addTypeDescription(new TypeDescription(XHTMLLabelLayoutPart.class, "!xhtmlLabel"));

    // Layouts
    constructor.addTypeDescription(new TypeDescription(FillLayoutLayoutPart.class, "!fillLayout"));
    constructor.addTypeDescription(new TypeDescription(BorderLayoutLayoutPart.class, "!borderLayout"));
    constructor.addTypeDescription(new TypeDescription(MigLayoutLayoutPart.class, "!migLayout"));

    // Custom
    ServiceLoader<LayoutPartRegisterable> parts = ServiceLoader.load(LayoutPartRegisterable.class);
    for (LayoutPartRegisterable part : parts) {
        part.register(constructor);
    }
}
项目:wildfly-swarm    文件:ConfigViewFactory.java   
private static Yaml newYaml() {
    return new Yaml(new Constructor(),
                    new Representer(),
                    new DumperOptions(),
                    new Resolver() {
                        @Override
                        public Tag resolve(NodeId kind, String value, boolean implicit) {
                            if (value != null) {
                                if (value.equalsIgnoreCase("on") ||
                                        value.equalsIgnoreCase("off") ||
                                        value.equalsIgnoreCase("yes") ||
                                        value.equalsIgnoreCase("no")) {
                                    return Tag.STR;
                                }
                            }
                            return super.resolve(kind, value, implicit);
                        }
                    });
}
项目:dice-heroes    文件:ThesaurusLoader.java   
@Override public void loadAsync(AssetManager manager, String fileName, FileHandle file, ThesaurusLoader.ThesaurusParameter parameter) {
    Constructor constructor = new Constructor(ThesaurusData.class);
    Yaml yaml = new Yaml(constructor);
    ObjectMap<String, ThesaurusData> data = new ObjectMap<String, ThesaurusData>();
    for (Object o : yaml.loadAll(resolve(fileName).read())) {
        ThesaurusData description = (ThesaurusData) o;
        data.put(description.key, description);
    }
    if (parameter != null && parameter.other.length > 0) {
        for (String depName : parameter.other) {
            Thesaurus dep = manager.get(depName);
            data.putAll(dep.data);
        }
    }
    thesaurus = new Thesaurus(data);
}
项目:cassandra-kmean    文件:StressProfile.java   
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);
    }
}
项目:chronix.spark    文件:ChronixSparkLoader.java   
public ChronixSparkLoader() {
    Representer representer = new Representer();
    representer.getPropertyUtils().setSkipMissingProperties(true);

    Constructor constructor = new Constructor(YamlConfiguration.class);

    TypeDescription typeDescription = new TypeDescription(ChronixYAMLConfiguration.class);
    typeDescription.putMapPropertyType("configurations", Object.class, ChronixYAMLConfiguration.IndividualConfiguration.class);
    constructor.addTypeDescription(typeDescription);

    Yaml yaml = new Yaml(constructor, representer);
    yaml.setBeanAccess(BeanAccess.FIELD);

    InputStream in = this.getClass().getClassLoader().getResourceAsStream("test_config.yml");
    chronixYAMLConfiguration = yaml.loadAs(in, ChronixYAMLConfiguration.class);
}
项目:NFVO    文件:Utils.java   
public static NSDTemplate bytesToNSDTemplate(ByteArrayOutputStream b) throws BadFormatException {

    Constructor constructor = new Constructor(NSDTemplate.class);
    TypeDescription projectDesc = new TypeDescription(NSDTemplate.class);

    constructor.addTypeDescription(projectDesc);

    Yaml yaml = new Yaml(constructor);
    try {
      return yaml.loadAs(new ByteArrayInputStream(b.toByteArray()), NSDTemplate.class);
    } catch (Exception e) {
      log.error(e.getLocalizedMessage());
      throw new BadFormatException(
          "Problem parsing the descriptor. Check if yaml is formatted correctly.");
    }
  }
项目:NFVO    文件:ToscaTest.java   
@Test
public void testGetNodesFromVNFDTemplate() throws FileNotFoundException, NotFoundException {

  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.getTopology_template().getVDUNodes());
  System.out.println(vnfdInput.getTopology_template().getCPNodes());
  System.out.println(vnfdInput.getTopology_template().getVNFNodes());
}
项目:scylla-tools-java    文件:StressProfile.java   
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);
    }
}
项目:NFVO    文件:ToscaTest.java   
@Test
public void testGettingVLNodes() throws FileNotFoundException {

  InputStream cpFile =
      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 cpInput = yaml.loadAs(cpFile, VNFDTemplate.class);

  List<VLNodeTemplate> vlNodes = cpInput.getTopology_template().getVLNodes();

  for (VLNodeTemplate n : vlNodes) {
    System.out.println(n.toString());
  }
}
项目:NFVO    文件:ToscaTest.java   
@Test
public void testGettingCPNodes() throws FileNotFoundException {

  InputStream cpFile =
      new FileInputStream(new File("src/main/resources/Testing/testTopologyTemplate.yaml"));

  Constructor constructor = new Constructor(TopologyTemplate.class);
  TypeDescription typeDescription = new TypeDescription(TopologyTemplate.class);
  constructor.addTypeDescription(typeDescription);

  Yaml yaml = new Yaml(constructor);
  TopologyTemplate cpInput = yaml.loadAs(cpFile, TopologyTemplate.class);

  List<CPNodeTemplate> cpNodes = cpInput.getCPNodes();

  for (CPNodeTemplate n : cpNodes) {
    System.out.println(n.toString());
  }
}
项目:NFVO    文件:ToscaTest.java   
@Test
public void testCreatingVNFDInstance() throws FileNotFoundException, NotFoundException {

  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);

  TOSCAParser parser = new TOSCAParser();

  VirtualNetworkFunctionDescriptor vnfd = parser.parseVNFDTemplate(vnfdInput);

  Gson gson = new Gson();
  System.out.println(gson.toJson(vnfd));
}
项目:NFVO    文件:ToscaTest.java   
@Test
public void testVNFDServerIperf() throws NotFoundException, FileNotFoundException {

  InputStream vnfdFile =
      new FileInputStream(new File("src/main/resources/Testing/vnfd_server_iperf.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);

  TOSCAParser parser = new TOSCAParser();

  VirtualNetworkFunctionDescriptor vnfd = parser.parseVNFDTemplate(vnfdInput);
  Gson gson = new Gson();
  System.out.println(gson.toJson(vnfd));
}
项目:NFVO    文件:ToscaTest.java   
@Test
public void testMultipleVLs() throws FileNotFoundException, NotFoundException {

  InputStream nsdFile =
      new FileInputStream(new File("src/main/resources/Testing/tosca-ns-example.yaml"));

  Constructor constructor = new Constructor(NSDTemplate.class);
  TypeDescription typeDescription = new TypeDescription(NSDTemplate.class);
  constructor.addTypeDescription(typeDescription);

  Yaml yaml = new Yaml(constructor);
  NSDTemplate nsdInput = yaml.loadAs(nsdFile, NSDTemplate.class);

  TOSCAParser parser = new TOSCAParser();

  NetworkServiceDescriptor nsd = parser.parseNSDTemplate(nsdInput);

  Gson gson = new Gson();
  System.out.println(gson.toJson(nsd));
}
项目:NFVO    文件:ToscaTest.java   
@Test
public void testNSDIperfASTemplate() throws FileNotFoundException, NotFoundException {

  InputStream nsdFile =
      new FileInputStream(new File("src/main/resources/Testing/testNSDIperfAutoscaling.yaml"));

  Constructor constructor = new Constructor(NSDTemplate.class);
  TypeDescription typeDescription = new TypeDescription(NSDTemplate.class);
  constructor.addTypeDescription(typeDescription);

  Yaml yaml = new Yaml(constructor);
  NSDTemplate nsdInput = yaml.loadAs(nsdFile, NSDTemplate.class);

  TOSCAParser parser = new TOSCAParser();

  NetworkServiceDescriptor nsd = parser.parseNSDTemplate(nsdInput);

  Gson gson = new Gson();
  System.out.println(gson.toJson(nsd));
}
项目:owltools    文件:ConfigManager.java   
/**
     * Work with a flexible document definition from a configuration file.
     *
     * @param location
     * @throws FileNotFoundException 
     */
    public void add(String location) throws FileNotFoundException {

        // Find the file in question on the filesystem.
        InputStream input = new FileInputStream(new File(location));

        LOG.info("Found flex config: " + location);
        Yaml yaml = new Yaml(new Constructor(GOlrConfig.class));
        GOlrConfig config = (GOlrConfig) yaml.load(input);
        LOG.info("Dumping flex loader YAML: \n" + yaml.dump(config));

        //searchable_extension = config.searchable_extension;

        // Plonk them all in to our bookkeeping.
        for( GOlrField field : config.fields ){
            addFieldToBook(config.id, field);
            fields.add(field);
        }
//      for( GOlrDynamicField field : config.dynamic ){
//          addFieldToBook(field);
//          dynamic_fields.add(field);
//      }
    }
项目:snakeyaml    文件:TypeSafePriorityTest.java   
/**
 * explicit TypeDescription is more important then runtime class (which may
 * be an interface)
 */
public void testLoadList2() {
    String output = Util.getLocalResource("examples/list-bean-3.yaml");
    // System.out.println(output);
    TypeDescription descr = new TypeDescription(ListBean.class);
    descr.putListPropertyType("developers", Developer.class);
    Yaml beanLoader = new Yaml(new Constructor(descr));
    ListBean parsed = beanLoader.loadAs(output, ListBean.class);
    assertNotNull(parsed);
    List<Human> developers = parsed.getDevelopers();
    assertEquals(2, developers.size());
    assertEquals("Committer must be recognised.", Developer.class, developers.get(0).getClass());
    Developer fred = (Developer) developers.get(0);
    assertEquals("Fred", fred.getName());
    assertEquals("creator", fred.getRole());
    Developer john = (Developer) developers.get(1);
    assertEquals("John", john.getName());
    assertEquals("committer", john.getRole());
}