當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。