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


Java Constructor.addTypeDescription方法代码示例

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


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

示例1: 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

示例2: 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

示例3: testLoadEnumBean2

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

示例4: load

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

示例5: 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

示例6: 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

示例7: testDirectives2

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

示例8: 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

示例9: testDirectives

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

示例10: registerTypes

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

示例11: ChronixSparkLoader

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

示例12: testCreatingVNFDInstance

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

示例13: testNSDIperfTemplate

import org.yaml.snakeyaml.constructor.Constructor; //导入方法依赖的package包/类
@Test
public void testNSDIperfTemplate() throws FileNotFoundException, NotFoundException {

  InputStream nsdFile =
      new FileInputStream(new File("src/main/resources/Testing/testNSDIperf.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));
}
 
开发者ID:openbaton,项目名称:NFVO,代码行数:21,代码来源:ToscaTest.java

示例14: testMultipleVLs

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

示例15: init

import org.yaml.snakeyaml.constructor.Constructor; //导入方法依赖的package包/类
@PostConstruct
public void init() {

	try {

		Constructor constructor = new Constructor(VariableConfig.class);

		TypeDescription variableConfigTypeDescription = new TypeDescription(VariableConfig.class);
		variableConfigTypeDescription.putListPropertyType(PROPERTY_VARIABLE_GROUPS, VariableGroup.class);
		constructor.addTypeDescription(variableConfigTypeDescription);

		TypeDescription variableGroupTypeDescription = new TypeDescription(VariableGroup.class);
		variableGroupTypeDescription.putListPropertyType(PROPERTY_VARIABLES, Variable.class);
		constructor.addTypeDescription(variableGroupTypeDescription);

		Yaml yaml = new Yaml(constructor);

		File terraformFolder = resourceService.getClasspathResource(Constants.FOLDER_TERRAFORM);
		if (!terraformFolder.isFile()) {
			File[] providerFolderArray = terraformFolder.listFiles();
			for (File providerFolder : providerFolderArray) {
				File variableFile = new File(new URI(providerFolder.toURI() + File.separator + FILE_VARIABLES_YML));
				if (variableFile.exists()) {
					VariableConfig variableConfig = yaml.loadAs(new FileInputStream(variableFile), VariableConfig.class);
					List<VariableGroup> variableGroupList = variableConfig.getVariableGroups();
					providerDefaults.put(providerFolder.getName(), variableGroupList);
				}

			}
		}
	}
	catch (Exception e) {
		LOG.error(e.getMessage(), e);
	}
}
 
开发者ID:chrisipa,项目名称:cloud-portal,代码行数:36,代码来源:TerraformService.java


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