Java Code Examples for org.yaml.snakeyaml.TypeDescription#putListPropertyType()

The following examples show how to use org.yaml.snakeyaml.TypeDescription#putListPropertyType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: YamlFactory.java    From waggle-dance with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 2
Source File: TypeSafePriorityTest.java    From snake-yaml with Apache License 2.0 6 votes vote down vote up
/**
 * 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());
}
 
Example 3
Source File: Human_WithArrayOfChildrenTest.java    From snake-yaml with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 4
Source File: ArrayInGenericCollectionTest.java    From snake-yaml with Apache License 2.0 6 votes vote down vote up
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());
}
 
Example 5
Source File: Human_WithArrayOfChildrenTest.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
public void testParseChildrenArrayWithoutRootTag() {
    Constructor constructor = new Constructor(Human_WithArrayOfChildren.class);
    TypeDescription HumanWithChildrenArrayDescription = new TypeDescription(
            Human_WithArrayOfChildren.class);
    HumanWithChildrenArrayDescription.putListPropertyType("children",
            Human_WithArrayOfChildren.class);
    constructor.addTypeDescription(HumanWithChildrenArrayDescription);
    Yaml yaml = new Yaml(constructor);
    String doc = Util.getLocalResource("recursive/with-childrenArray-no-root-tag.yaml");
    Human_WithArrayOfChildren son2 = (Human_WithArrayOfChildren) yaml.load(doc);
    checkSon(son2);
}
 
Example 6
Source File: BundleCacher.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public BundleElementsConstructor(File bundleDirectory)
{
	this.bundleDirectory = bundleDirectory;
	this.yamlConstructors.put(new Tag(SCOPE_SELECTOR_TAG), new ConstructScopeSelector());
	this.yamlConstructors.put(new Tag("!ruby/regexp"), new ConstructRubyRegexp()); //$NON-NLS-1$
	this.yamlConstructors.put(new Tag(REGEXP_TAG), new ConstructRubyRegexp());
	this.yamlConstructors.put(new Tag(COMMAND_TAG), new ConstructCommandElement());
	this.yamlConstructors.put(new Tag(ENVIRONMENT_TAG), new ConstructEnvironmentElement());
	this.yamlConstructors.put(new Tag(CONTENT_ASSIST_TAG), new ConstructContentAssistElement());
	this.yamlConstructors.put(new Tag(TEMPLATE_TAG), new ConstructTemplateElement());
	this.yamlConstructors.put(new Tag(BundleElement.class), new ConstructBundleElement());
	this.yamlConstructors.put(new Tag(MenuElement.class), new ConstructMenuElement());
	this.yamlConstructors.put(new Tag(SnippetElement.class), new ConstructSnippetElement());
	this.yamlConstructors.put(new Tag(SnippetCategoryElement.class), new ConstructSnippetCategoryElement());
	this.yamlConstructors.put(new Tag(ContentAssistElement.class), new ConstructContentAssistElement());
	this.yamlConstructors.put(new Tag(CommandElement.class), new ConstructCommandElement());
	this.yamlConstructors.put(new Tag(TemplateElement.class), new ConstructTemplateElement());
	this.yamlConstructors.put(new Tag(SmartTypingPairsElement.class), new ConstructSmartTypingPairsElement());
	this.yamlConstructors.put(new Tag(ProjectTemplateElement.class), new ConstructProjectTemplateElement());
	this.yamlConstructors.put(new Tag(ProjectSampleElement.class), new ConstructProjectSampleElement());
	this.yamlConstructors.put(new Tag(EnvironmentElement.class), new ConstructEnvironmentElement());
	this.yamlConstructors.put(new Tag(BuildPathElement.class), new ConstructBuildPathElement());

	// Tell it that "children" field for MenuElement is a list of MenuElements
	TypeDescription menuDescription = new TypeDescription(MenuElement.class);
	menuDescription.putListPropertyType("children", MenuElement.class); //$NON-NLS-1$
	addTypeDescription(menuDescription);
}
 
Example 7
Source File: Settings.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 8
Source File: Config.java    From arbiter with Apache License 2.0 5 votes vote down vote up
/**
 * Defines how to construct a Config objects when reading from YAML
 *
 * @return A snakeyaml Constructor instance that will be used to create Config objects
 */
public static Constructor getYamlConstructor() {
    Constructor configConstructor = new Constructor(Config.class);
    TypeDescription configDescription = new TypeDescription(Config.class);
    configDescription.putListPropertyType("actionTypes", ActionType.class);
    configConstructor.addTypeDescription(configDescription);

    return configConstructor;
}
 
Example 9
Source File: Workflow.java    From arbiter with Apache License 2.0 5 votes vote down vote up
/**
 * Defines how to construct a Workflow objects when reading from YAML
 *
 * @return A snakeyaml Constructor instance that will be used to create Workflow objects
 */
public static Constructor getYamlConstructor() {
    Constructor workflowConstructor = new Constructor(Workflow.class);
    TypeDescription workflowDescription = new TypeDescription(Workflow.class);
    workflowDescription.putListPropertyType("actions", Action.class);
    workflowConstructor.addTypeDescription(workflowDescription);

    return workflowConstructor;
}
 
Example 10
Source File: EcoParser.java    From incubator-heron with Apache License 2.0 5 votes vote down vote up
private static Yaml topologyYaml() {
  Constructor topologyConstructor = new Constructor(EcoTopologyDefinition.class);

  TypeDescription topologyDescription = new TypeDescription(EcoTopologyDefinition.class);

  topologyDescription.putListPropertyType("spouts", SpoutDefinition.class);
  topologyDescription.putListPropertyType("bolts", BoltDefinition.class);
  topologyConstructor.addTypeDescription(topologyDescription);

  return new Yaml(topologyConstructor);
}
 
Example 11
Source File: TypeSafeCollectionsTest.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
public void testTypeSafeList() {
    Constructor constructor = new Constructor(Car.class);
    TypeDescription carDescription = new TypeDescription(Car.class);
    carDescription.putListPropertyType("wheels", Wheel.class);
    constructor.addTypeDescription(carDescription);
    Yaml yaml = new Yaml(constructor);
    Car car = (Car) yaml.load(Util.getLocalResource("constructor/car-no-root-class.yaml"));
    assertEquals("12-XP-F4", car.getPlate());
    List<Wheel> wheels = car.getWheels();
    assertNotNull(wheels);
    assertEquals(5, wheels.size());
    for (Wheel wheel : wheels) {
        assertTrue(wheel.getId() > 0);
    }
}
 
Example 12
Source File: EntityFactory.java    From xibalba with MIT License 4 votes vote down vote up
/**
 * Create an item.
 *
 * @param key      Key of item to create
 * @param position Vector2 of their position
 * @return The item
 */
public Entity createItem(String key, Vector2 position) {
  Constructor constructor = new Constructor(ItemData.class);
  constructor.addTypeDescription(new TypeDescription(Bleed.class, "!Bleed"));
  constructor.addTypeDescription(new TypeDescription(Charm.class, "!Charm"));
  constructor.addTypeDescription(new TypeDescription(DealDamage.class, "!DealDamage"));
  constructor.addTypeDescription(new TypeDescription(Poison.class, "!Poison"));
  constructor.addTypeDescription(new TypeDescription(RaiseHealth.class, "!RaiseHealth"));
  constructor.addTypeDescription(new TypeDescription(StartFire.class, "!StartFire"));
  TypeDescription itemDescription = new TypeDescription(ItemData.class);
  itemDescription.putListPropertyType("requiredComponent", ItemRequiredComponentData.class);
  constructor.addTypeDescription(itemDescription);
  Yaml yaml = new Yaml(constructor);
  ItemData data = (ItemData) yaml.load(Main.itemsData.get(key));
  Entity entity = new Entity();

  entity.add(new PositionComponent(position));

  entity.add(
      new ItemComponent(
          key,
          i18n.get("entities.items." + key + ".name"),
          i18n.get("entities.items." + key + ".description"),
          data
      )
  );

  switch (data.type) {
    case "armor":
      entity.add(new ArmorComponent());
      break;
    case "weapon":
      entity.add(new WeaponComponent(data.weaponType, data.ammunition));
      break;
    case "light":
      ArrayList<Color> colors = new ArrayList<>();
      for (String hex : data.lightColors) {
        colors.add(Main.parseColor(hex));
      }
      entity.add(new LightComponent(data.lightRadius, data.lightFlickers, colors));
      break;
    default:
  }

  if (data.ammunitionType != null) {
    entity.add(new AmmunitionComponent(data.ammunitionType));
  }

  if (data.effects != null) {
    entity.add(new EffectsComponent(data));
  }

  entity.add(new VisualComponent(
      Main.asciiAtlas.createSprite(data.visual.get("character")),
      position, Main.parseColor(data.visual.get("color"))
  ));

  return entity;
}
 
Example 13
Source File: HouseTest.java    From snake-yaml with Apache License 2.0 4 votes vote down vote up
/**
 * with global root class tag (global tag should be avoided)
 */
public void testDump3() {
    House house = new House();
    FrontDoor frontDoor = new FrontDoor("qaz1", 5);
    frontDoor.setKeytype("qwerty123");
    house.setFrontDoor(frontDoor);
    List<Room> rooms = new ArrayList<Room>();
    rooms.add(new Room("Hall"));
    rooms.add(new Room("Kitchen"));
    house.setRooms(rooms);
    Map<String, String> reminders = new TreeMap<String, String>();
    reminders.put("today", "do nothig");
    reminders.put("tomorrow", "go shoping");
    house.setReminders(reminders);
    house.setNumber(1);
    house.setStreet("Wall Street");
    Yaml beanDumper = new Yaml();
    String yaml = beanDumper.dumpAsMap(house);
    String etalon = Util.getLocalResource("javabeans/house-dump3.yaml");
    assertEquals(etalon, yaml);
    // load
    TypeDescription description = new TypeDescription(House.class);
    description.putListPropertyType("rooms", Room.class);
    Yaml beanLoader = new Yaml(new Constructor(description));
    House loadedHouse = (House) beanLoader.load(yaml);
    House loadedHouse2 = (House) beanLoader.loadAs(yaml, House.class);
    assertNotNull(loadedHouse);
    assertFalse(loadedHouse == loadedHouse2);
    assertEquals("Wall Street", loadedHouse.getStreet());
    assertEquals(1, loadedHouse.getNumber());
    assertEquals(1, loadedHouse2.getNumber());
    FrontDoor fdoor = loadedHouse.getFrontDoor();
    assertEquals(frontDoor.getId(), fdoor.getId());
    assertEquals(frontDoor.getHeight(), fdoor.getHeight());
    assertEquals(frontDoor.getKeytype(), fdoor.getKeytype());
    assertEquals(frontDoor, fdoor);
    assertEquals(reminders, loadedHouse.getReminders());
    List<Room> loadedRooms = loadedHouse.getRooms();
    assertEquals(rooms, loadedRooms);
    // dump again
    String yaml3 = beanDumper.dumpAsMap(loadedHouse);
    assertEquals(yaml, yaml3);
}
 
Example 14
Source File: HumanTest.java    From snake-yaml with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public void testChildrenListRoot() {
    Human3 father = new Human3();
    father.setName("Father");
    father.setBirthday(new Date(1000000000));
    father.setBirthPlace("Leningrad");
    father.setBankAccountOwner(father);
    //
    Human3 mother = new Human3();
    mother.setName("Mother");
    mother.setBirthday(new Date(100000000000L));
    mother.setBirthPlace("Saint-Petersburg");
    father.setPartner(mother);
    mother.setPartner(father);
    mother.setBankAccountOwner(father);
    //
    Human3 son = new Human3();
    son.setName("Son");
    son.setBirthday(new Date(310000000000L));
    son.setBirthPlace("Munich");
    son.setBankAccountOwner(father);
    son.setFather(father);
    son.setMother(mother);
    //
    Human3 daughter = new Human3();
    daughter.setName("Daughter");
    daughter.setBirthday(new Date(420000000000L));
    daughter.setBirthPlace("New York");
    daughter.setBankAccountOwner(father);
    daughter.setFather(father);
    daughter.setMother(mother);
    //
    ArrayList<Human3> children = new ArrayList<Human3>();
    children.add(son);
    children.add(daughter);
    father.setChildren(children);
    mother.setChildren(children);
    //

    Constructor constructor = new Constructor();
    TypeDescription Human3Description = new TypeDescription(Human3.class);
    Human3Description.putListPropertyType("children", Human3.class);
    constructor.addTypeDescription(Human3Description);

    Yaml yaml = new Yaml(constructor);
    String output = yaml.dump(father.getChildren());
    // System.out.println(output);
    String etalon = Util.getLocalResource("recursive/with-children-as-list.yaml");
    assertEquals(etalon, output);
    //
    List<Human3> children2 = (List<Human3>) yaml.load(output);
    assertNotNull(children2);
    Human3 son2 = children2.iterator().next();
    assertEquals(2, children2.size());

    Human3 father2 = son2.getFather();
    assertEquals("Father", father2.getName());
    assertEquals("Mother", son2.getMother().getName());
    assertSame(father2, father2.getBankAccountOwner());
    assertSame(father2.getPartner(), son2.getMother());
    assertSame(father2, son2.getMother().getPartner());

    assertSame(father2.getPartner().getChildren(), children2);

    for (Object child : children2) {
        // check if type descriptor was correct
        assertSame(Human3.class, child.getClass());
    }
}
 
Example 15
Source File: HumanTest.java    From snake-yaml with Apache License 2.0 4 votes vote down vote up
public void testChildren3() {
    Human3 father = new Human3();
    father.setName("Father");
    father.setBirthday(new Date(1000000000));
    father.setBirthPlace("Leningrad");
    father.setBankAccountOwner(father);
    //
    Human3 mother = new Human3();
    mother.setName("Mother");
    mother.setBirthday(new Date(100000000000L));
    mother.setBirthPlace("Saint-Petersburg");
    father.setPartner(mother);
    mother.setPartner(father);
    mother.setBankAccountOwner(father);
    //
    Human3 son = new Human3();
    son.setName("Son");
    son.setBirthday(new Date(310000000000L));
    son.setBirthPlace("Munich");
    son.setBankAccountOwner(father);
    son.setFather(father);
    son.setMother(mother);
    //
    Human3 daughter = new Human3();
    daughter.setName("Daughter");
    daughter.setBirthday(new Date(420000000000L));
    daughter.setBirthPlace("New York");
    daughter.setBankAccountOwner(father);
    daughter.setFather(father);
    daughter.setMother(mother);
    //
    ArrayList<Human3> children = new ArrayList<Human3>();
    children.add(son);
    children.add(daughter);
    father.setChildren(children);
    mother.setChildren(children);
    //

    Constructor constructor = new Constructor(Human3.class);
    TypeDescription Human3Description = new TypeDescription(Human3.class);
    Human3Description.putListPropertyType("children", Human3.class);
    constructor.addTypeDescription(Human3Description);

    Yaml yaml = new Yaml(constructor);
    String output = yaml.dump(son);
    // System.out.println(output);
    String etalon = Util.getLocalResource("recursive/with-children-3.yaml");
    assertEquals(etalon, output);
    //
    Human3 son2 = (Human3) yaml.load(output);
    assertNotNull(son2);
    assertEquals("Son", son.getName());

    Human3 father2 = son2.getFather();
    assertEquals("Father", father2.getName());
    assertEquals("Mother", son2.getMother().getName());
    assertSame(father2, father2.getBankAccountOwner());
    assertSame(father2.getPartner(), son2.getMother());
    assertSame(father2, son2.getMother().getPartner());

    List<Human3> children2 = father2.getChildren();
    assertEquals(2, children2.size());
    assertSame(father2.getPartner().getChildren(), children2);

    for (Object child : children2) {
        // check if type descriptor was correct
        assertSame(Human3.class, child.getClass());
    }
}
 
Example 16
Source File: HumanGenericsTest.java    From snake-yaml with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public void testChildrenListRoot() throws IOException, IntrospectionException {
    if (!GenericsBugDetector.isProperIntrospection()) {
        return;
    }
    HumanGen3 father = new HumanGen3();
    father.setName("Father");
    father.setBirthday(new Date(1000000000));
    father.setBirthPlace("Leningrad");
    father.setBankAccountOwner(father);
    //
    HumanGen3 mother = new HumanGen3();
    mother.setName("Mother");
    mother.setBirthday(new Date(100000000000L));
    mother.setBirthPlace("Saint-Petersburg");
    father.setPartner(mother);
    mother.setPartner(father);
    mother.setBankAccountOwner(father);
    //
    HumanGen3 son = new HumanGen3();
    son.setName("Son");
    son.setBirthday(new Date(310000000000L));
    son.setBirthPlace("Munich");
    son.setBankAccountOwner(father);
    son.setFather(father);
    son.setMother(mother);
    //
    HumanGen3 daughter = new HumanGen3();
    daughter.setName("Daughter");
    daughter.setBirthday(new Date(420000000000L));
    daughter.setBirthPlace("New York");
    daughter.setBankAccountOwner(father);
    daughter.setFather(father);
    daughter.setMother(mother);
    //
    ArrayList<HumanGen3> children = new ArrayList<HumanGen3>();
    children.add(son);
    children.add(daughter);
    father.setChildren(children);
    mother.setChildren(children);
    //

    Constructor constructor = new Constructor();
    TypeDescription Human3Description = new TypeDescription(HumanGen3.class);
    Human3Description.putListPropertyType("children", HumanGen3.class);
    constructor.addTypeDescription(Human3Description);

    Yaml yaml = new Yaml(constructor);
    String output = yaml.dump(father.getChildren());
    // System.out.println(output);
    String etalon = Util.getLocalResource("recursive/generics/with-children-as-list.yaml");
    assertEquals(etalon, output);
    //
    List<HumanGen3> children2 = (List<HumanGen3>) yaml.load(output);
    assertNotNull(children2);
    HumanGen3 son2 = children2.iterator().next();
    assertEquals(2, children2.size());

    HumanGen3 father2 = son2.getFather();
    assertEquals("Father", father2.getName());
    assertEquals("Mother", son2.getMother().getName());
    assertSame(father2, father2.getBankAccountOwner());
    assertSame(father2.getPartner(), son2.getMother());
    assertSame(father2, son2.getMother().getPartner());

    assertSame(father2.getPartner().getChildren(), children2);

    for (Object child : children2) {
        assertSame(HumanGen3.class, child.getClass()); // check if type
        // descriptor was
        // correct
    }
}
 
Example 17
Source File: HumanGenericsTest.java    From snake-yaml with Apache License 2.0 4 votes vote down vote up
public void testChildren3() throws IOException, IntrospectionException {
    if (!GenericsBugDetector.isProperIntrospection()) {
        return;
    }
    HumanGen3 father = new HumanGen3();
    father.setName("Father");
    father.setBirthday(new Date(1000000000));
    father.setBirthPlace("Leningrad");
    father.setBankAccountOwner(father);
    //
    HumanGen3 mother = new HumanGen3();
    mother.setName("Mother");
    mother.setBirthday(new Date(100000000000L));
    mother.setBirthPlace("Saint-Petersburg");
    father.setPartner(mother);
    mother.setPartner(father);
    mother.setBankAccountOwner(father);
    //
    HumanGen3 son = new HumanGen3();
    son.setName("Son");
    son.setBirthday(new Date(310000000000L));
    son.setBirthPlace("Munich");
    son.setBankAccountOwner(father);
    son.setFather(father);
    son.setMother(mother);
    //
    HumanGen3 daughter = new HumanGen3();
    daughter.setName("Daughter");
    daughter.setBirthday(new Date(420000000000L));
    daughter.setBirthPlace("New York");
    daughter.setBankAccountOwner(father);
    daughter.setFather(father);
    daughter.setMother(mother);
    //
    ArrayList<HumanGen3> children = new ArrayList<HumanGen3>();
    children.add(son);
    children.add(daughter);
    father.setChildren(children);
    mother.setChildren(children);
    //

    Constructor constructor = new Constructor();
    TypeDescription Human3Description = new TypeDescription(HumanGen3.class);
    Human3Description.putListPropertyType("children", HumanGen3.class);
    constructor.addTypeDescription(Human3Description);

    Yaml yaml = new Yaml(constructor);
    String output = yaml.dump(son);
    // System.out.println(output);
    String etalon = Util.getLocalResource("recursive/generics/with-children-3.yaml");
    assertEquals(etalon, output);
    //
    HumanGen3 son2 = (HumanGen3) yaml.load(output);
    assertNotNull(son2);
    assertEquals("Son", son.getName());

    HumanGen3 father2 = son2.getFather();
    assertEquals("Father", father2.getName());
    assertEquals("Mother", son2.getMother().getName());
    assertSame(father2, father2.getBankAccountOwner());
    assertSame(father2.getPartner(), son2.getMother());
    assertSame(father2, son2.getMother().getPartner());

    List<HumanGen3> children2 = father2.getChildren();
    assertEquals(2, children2.size());
    assertSame(father2.getPartner().getChildren(), children2);

    for (Object child : children2) {
        assertSame(HumanGen3.class, child.getClass()); // check if type
        // descriptor was
        // correct
    }
}
 
Example 18
Source File: UseCaseService.java    From cloud-portal with MIT License 4 votes vote down vote up
private void getUseCasesFromFileSystem() {

		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 useCaseRootFolder = resourceService.getClasspathResource(Constants.FOLDER_USE_CASE);
			
			for (File useCaseFolder : useCaseRootFolder.listFiles()) {
				for (File providerFolder : useCaseFolder.listFiles()) {
					for (File provisionerFolder : providerFolder.listFiles()) {
						
						String useCaseName = useCaseFolder.getName();
						
						StringBuilder useCaseIdBuilder = new StringBuilder();
						useCaseIdBuilder.append(useCaseName);
						useCaseIdBuilder.append(Constants.CHAR_DASH);
						useCaseIdBuilder.append(providerFolder.getName());
						useCaseIdBuilder.append(Constants.CHAR_DASH);
						useCaseIdBuilder.append(provisionerFolder.getName());
						
						String id = useCaseIdBuilder.toString();
						String provider = providerFolder.getName();
						String provisioner = provisionerFolder.getName();

						List<VariableGroup> variableGroups = new ArrayList<>();
						File variableFile = new File(new URI(provisionerFolder.toURI() + File.separator + FILE_VARIABLES_YML));
						if (variableFile.exists()) {
							VariableConfig variableConfig = yaml.loadAs(new FileInputStream(variableFile), VariableConfig.class);
							variableGroups = variableConfig.getVariableGroups();
						}
						
						StringBuilder resourcePathBuilder = new StringBuilder();
						resourcePathBuilder.append(useCaseRootFolder.getName());
						resourcePathBuilder.append(File.separator);
						resourcePathBuilder.append(useCaseName);
						resourcePathBuilder.append(File.separator);
						resourcePathBuilder.append(providerFolder.getName());
						resourcePathBuilder.append(File.separator);
						resourcePathBuilder.append(provisionerFolder.getName());
						
						UseCase useCase = new UseCase();
						useCase.setId(id);
						useCase.setName(useCaseName);
						useCase.setProvider(provider);
						useCase.setProvisioner(provisioner);
						useCase.setVariableGroups(variableGroups);
						useCase.setResourceFolderPath(resourcePathBuilder.toString());
						useCaseMap.put(id, useCase);
						
						providers.add(provider);
					}
				}
			}
		}
		catch (Exception e) {
			LOG.error(e.getMessage(), e);
		}
	}
 
Example 19
Source File: Settings.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
/**
 * Read configuration from a file into a new {@link Settings} object.
 *
 * @param stream an input stream containing a Gremlin Server YAML configuration
 * @return a new {@link Optional} object wrapping the created {@link Settings}
 */
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.putMapPropertyType("graphs", String.class, String.class);
    settingsDescription.putMapPropertyType("scriptEngines", String.class, ScriptEngineSettings.class);
    settingsDescription.putListPropertyType("serializers", SerializerSettings.class);
    settingsDescription.putListPropertyType("plugins", String.class);
    settingsDescription.putListPropertyType("processors", ProcessorSettings.class);
    constructor.addTypeDescription(settingsDescription);

    final TypeDescription serializerSettingsDescription = new TypeDescription(SerializerSettings.class);
    serializerSettingsDescription.putMapPropertyType("config", String.class, Object.class);
    constructor.addTypeDescription(serializerSettingsDescription);

    final TypeDescription scriptEngineSettingsDescription = new TypeDescription(ScriptEngineSettings.class);
    scriptEngineSettingsDescription.putListPropertyType("imports", String.class);
    scriptEngineSettingsDescription.putListPropertyType("staticImports", String.class);
    scriptEngineSettingsDescription.putListPropertyType("scripts", String.class);
    scriptEngineSettingsDescription.putMapPropertyType("config", String.class, Object.class);
    scriptEngineSettingsDescription.putMapPropertyType("plugins", String.class, Object.class);
    constructor.addTypeDescription(scriptEngineSettingsDescription);

    final TypeDescription sslSettings = new TypeDescription(SslSettings.class);
    constructor.addTypeDescription(sslSettings);

    final TypeDescription authenticationSettings = new TypeDescription(AuthenticationSettings.class);
    constructor.addTypeDescription(authenticationSettings);

    final TypeDescription serverMetricsDescription = new TypeDescription(ServerMetrics.class);
    constructor.addTypeDescription(serverMetricsDescription);

    final TypeDescription consoleReporterDescription = new TypeDescription(ConsoleReporterMetrics.class);
    constructor.addTypeDescription(consoleReporterDescription);

    final TypeDescription csvReporterDescription = new TypeDescription(CsvReporterMetrics.class);
    constructor.addTypeDescription(csvReporterDescription);

    final TypeDescription jmxReporterDescription = new TypeDescription(JmxReporterMetrics.class);
    constructor.addTypeDescription(jmxReporterDescription);

    final TypeDescription slf4jReporterDescription = new TypeDescription(Slf4jReporterMetrics.class);
    constructor.addTypeDescription(slf4jReporterDescription);

    final TypeDescription gangliaReporterDescription = new TypeDescription(GangliaReporterMetrics.class);
    constructor.addTypeDescription(gangliaReporterDescription);

    final TypeDescription graphiteReporterDescription = new TypeDescription(GraphiteReporterMetrics.class);
    constructor.addTypeDescription(graphiteReporterDescription);

    final Yaml yaml = new Yaml(constructor);
    return yaml.loadAs(stream, Settings.class);
}
 
Example 20
Source File: CraftScreen.java    From xibalba with MIT License 4 votes vote down vote up
/**
 * Craft screen.
 *
 * @param main Instance of Main
 */
public CraftScreen(Main main) {
  stage = new Stage(new FitViewport(960, 540));

  Constructor constructor = new Constructor(ItemData.class);
  constructor.addTypeDescription(new TypeDescription(Bleed.class, "!Bleed"));
  constructor.addTypeDescription(new TypeDescription(Charm.class, "!Charm"));
  constructor.addTypeDescription(new TypeDescription(DealDamage.class, "!DealDamage"));
  constructor.addTypeDescription(new TypeDescription(Poison.class, "!Poison"));
  constructor.addTypeDescription(new TypeDescription(RaiseHealth.class, "!RaiseHealth"));
  constructor.addTypeDescription(new TypeDescription(StartFire.class, "!StartFire"));
  TypeDescription itemDescription = new TypeDescription(ItemData.class);
  itemDescription.putListPropertyType("requiredComponent", ItemRequiredComponentData.class);
  constructor.addTypeDescription(itemDescription);
  Yaml yaml = new Yaml(constructor);
  recipes = new HashMap<>();

  for (Map.Entry<String, String> entry : Main.itemsData.entrySet()) {
    ItemData data = (ItemData) yaml.load(entry.getValue());

    if (data.requiredComponents != null) {
      recipes.put(entry.getKey(), data);
    }
  }

  table = new Table();
  table.setFillParent(true);
  table.left().top();
  stage.addActor(table);

  Table titleTable = new Table();

  HorizontalGroup titleGroup = new HorizontalGroup();
  titleGroup.space(10);
  titleTable.add(titleGroup).pad(10).width(Gdx.graphics.getWidth() - 20);

  ActionButton closeButton = new ActionButton("Q", null);
  closeButton.setKeys(Input.Keys.Q);
  closeButton.setAction(table, () -> main.setScreen(Main.playScreen));
  titleGroup.addActor(closeButton);

  Label title = new Label("Craft", Main.skin);
  titleGroup.addActor(title);

  recipeGroup = new VerticalGroup().top().left().columnLeft();

  Table craftTable = new Table();
  craftTable.add(recipeGroup).pad(10).top().left().width(Gdx.graphics.getWidth() / 2);

  table.add(titleTable);
  table.row();
  table.add(craftTable).left();

  setupRecipes();

  Gdx.input.setInputProcessor(stage);
  stage.setKeyboardFocus(table);
}