当前位置: 首页>>代码示例>>Java>>正文


Java Constructor类代码示例

本文整理汇总了Java中org.yaml.snakeyaml.constructor.Constructor的典型用法代码示例。如果您正苦于以下问题:Java Constructor类的具体用法?Java Constructor怎么用?Java Constructor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Constructor类属于org.yaml.snakeyaml.constructor包,在下文中一共展示了Constructor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadYaml

import org.yaml.snakeyaml.constructor.Constructor; //导入依赖的package包/类
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();
        }
    }
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:20,代码来源:ObjectMapItem.java

示例2: initUserSettingsProducer

import org.yaml.snakeyaml.constructor.Constructor; //导入依赖的package包/类
@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());
  }
}
 
开发者ID:Juraji,项目名称:Biliomi,代码行数:22,代码来源:UserSettingsProducer.java

示例3: loadPackageMetadata

import org.yaml.snakeyaml.constructor.Constructor; //导入依赖的package包/类
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;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-skipper,代码行数:17,代码来源:DefaultPackageReader.java

示例4: convertStringToManifest

import org.yaml.snakeyaml.constructor.Constructor; //导入依赖的package包/类
@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;
}
 
开发者ID:jomof,项目名称:cdep,代码行数:17,代码来源:V3Reader.java

示例5: initialValue

import org.yaml.snakeyaml.constructor.Constructor; //导入依赖的package包/类
@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);
}
 
开发者ID:Dytanic,项目名称:CloudNet,代码行数:21,代码来源:YamlConfiguration.java

示例6: loadYaml

import org.yaml.snakeyaml.constructor.Constructor; //导入依赖的package包/类
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();
        }
    }
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:20,代码来源:OMapContainer.java

示例7: newYaml

import org.yaml.snakeyaml.constructor.Constructor; //导入依赖的package包/类
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);
}
 
开发者ID:HotelsDotCom,项目名称:waggle-dance,代码行数:25,代码来源:YamlFactory.java

示例8: testLocalTag

import org.yaml.snakeyaml.constructor.Constructor; //导入依赖的package包/类
/**
 * 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());
}
 
开发者ID:bmoliveira,项目名称:snake-yaml,代码行数:26,代码来源:StaticFieldsWrapperTest.java

示例9: testLoadList2

import org.yaml.snakeyaml.constructor.Constructor; //导入依赖的package包/类
/**
 * 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());
}
 
开发者ID:bmoliveira,项目名称:snake-yaml,代码行数:23,代码来源:TypeSafePriorityTest.java

示例10: testChildrenArray

import org.yaml.snakeyaml.constructor.Constructor; //导入依赖的package包/类
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);
}
 
开发者ID:bmoliveira,项目名称:snake-yaml,代码行数:18,代码来源:Human_WithArrayOfChildrenTest.java

示例11: testMergeMapToJavaBean

import org.yaml.snakeyaml.constructor.Constructor; //导入依赖的package包/类
/**
 * 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());
}
 
开发者ID:bmoliveira,项目名称:snake-yaml,代码行数:22,代码来源:MergeJavaBeanTest.java

示例12: testJavaBeanWithTypeDescription

import org.yaml.snakeyaml.constructor.Constructor; //导入依赖的package包/类
@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);
}
 
开发者ID:bmoliveira,项目名称:snake-yaml,代码行数:20,代码来源:PerlTest.java

示例13: testJavaBean

import org.yaml.snakeyaml.constructor.Constructor; //导入依赖的package包/类
@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);
}
 
开发者ID:bmoliveira,项目名称:snake-yaml,代码行数:17,代码来源:PerlTest.java

示例14: testABProperty

import org.yaml.snakeyaml.constructor.Constructor; //导入依赖的package包/类
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);
}
 
开发者ID:bmoliveira,项目名称:snake-yaml,代码行数:25,代码来源:PropOrderInfluenceWhenAliasedInGenericCollectionTest.java

示例15: testArrayAsMapValueWithTypeDespriptor

import org.yaml.snakeyaml.constructor.Constructor; //导入依赖的package包/类
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());
    }
}
 
开发者ID:bmoliveira,项目名称:snake-yaml,代码行数:25,代码来源:ArrayInGenericCollectionTest.java


注:本文中的org.yaml.snakeyaml.constructor.Constructor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。