當前位置: 首頁>>代碼示例>>Java>>正文


Java Representer類代碼示例

本文整理匯總了Java中org.yaml.snakeyaml.representer.Representer的典型用法代碼示例。如果您正苦於以下問題:Java Representer類的具體用法?Java Representer怎麽用?Java Representer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Representer類屬於org.yaml.snakeyaml.representer包,在下文中一共展示了Representer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: loadPackageMetadata

import org.yaml.snakeyaml.representer.Representer; //導入依賴的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

示例2: initialValue

import org.yaml.snakeyaml.representer.Representer; //導入依賴的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

示例3: Yaml

import org.yaml.snakeyaml.representer.Representer; //導入依賴的package包/類
/**
 * Create Yaml instance. It is safe to create a few instances and use them
 * in different Threads.
 * 
 * @param constructor
 *            BaseConstructor to construct incoming documents
 * @param representer
 *            Representer to emit outgoing objects
 * @param dumperOptions
 *            DumperOptions to configure outgoing objects
 * @param resolver
 *            Resolver to detect implicit type
 */
public Yaml(BaseConstructor constructor, Representer representer, DumperOptions dumperOptions,
        Resolver resolver) {
    if (!constructor.isExplicitPropertyUtils()) {
        constructor.setPropertyUtils(representer.getPropertyUtils());
    } else if (!representer.isExplicitPropertyUtils()) {
        representer.setPropertyUtils(constructor.getPropertyUtils());
    }
    this.constructor = constructor;
    representer.setDefaultFlowStyle(dumperOptions.getDefaultFlowStyle());
    representer.setDefaultScalarStyle(dumperOptions.getDefaultScalarStyle());
    representer.getPropertyUtils().setAllowReadOnlyProperties(
            dumperOptions.isAllowReadOnlyProperties());
    representer.setTimeZone(dumperOptions.getTimeZone());
    this.representer = representer;
    this.dumperOptions = dumperOptions;
    this.resolver = resolver;
    this.name = "Yaml:" + System.identityHashCode(this);
}
 
開發者ID:imkiva,項目名稱:AndroidApktool,代碼行數:32,代碼來源:Yaml.java

示例4: Yaml

import org.yaml.snakeyaml.representer.Representer; //導入依賴的package包/類
/**
 * Create Yaml instance. It is safe to create a few instances and use them
 * in different Threads.
 *
 * @param constructor
 *            BaseConstructor to construct incoming documents
 * @param representer
 *            Representer to emit outgoing objects
 * @param dumperOptions
 *            DumperOptions to configure outgoing objects
 * @param loadingConfig
 *            LoadingConfig to control load behavior
 * @param resolver
 *            Resolver to detect implicit type
 */
public Yaml(BaseConstructor constructor, Representer representer, DumperOptions dumperOptions,
        LoaderOptions loadingConfig, Resolver resolver) {
    if (!constructor.isExplicitPropertyUtils()) {
        constructor.setPropertyUtils(representer.getPropertyUtils());
    } else if (!representer.isExplicitPropertyUtils()) {
        representer.setPropertyUtils(constructor.getPropertyUtils());
    }
    this.constructor = constructor;
    this.constructor.setAllowDuplicateKeys(loadingConfig.isAllowDuplicateKeys());
    if (dumperOptions.getIndent() <= dumperOptions.getIndicatorIndent()) {
        throw new YAMLException("Indicator indent must be smaller then indent.");
    }
    representer.setDefaultFlowStyle(dumperOptions.getDefaultFlowStyle());
    representer.setDefaultScalarStyle(dumperOptions.getDefaultScalarStyle());
    representer.getPropertyUtils()
            .setAllowReadOnlyProperties(dumperOptions.isAllowReadOnlyProperties());
    representer.setTimeZone(dumperOptions.getTimeZone());
    this.representer = representer;
    this.dumperOptions = dumperOptions;
    this.loadingConfig = loadingConfig;
    this.resolver = resolver;
    this.name = "Yaml:" + System.identityHashCode(this);
}
 
開發者ID:RoccoDev,項目名稱:5zig-TIMV-Plugin,代碼行數:39,代碼來源:Yaml.java

示例5: newYaml

import org.yaml.snakeyaml.representer.Representer; //導入依賴的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

示例6: testLocalTag

import org.yaml.snakeyaml.representer.Representer; //導入依賴的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

示例7: testEmitWithTags

import org.yaml.snakeyaml.representer.Representer; //導入依賴的package包/類
public void testEmitWithTags() {
    TestObject result = parseObject(Util.getLocalResource("ruby/ruby1.yaml"));
    DumperOptions options = new DumperOptions();
    options.setExplicitStart(true);
    Representer repr = new Representer();
    repr.addClassTag(TestObject.class, new Tag("!ruby/object:Test::Module::Object"));
    repr.addClassTag(Sub1.class, new Tag("!ruby/object:Test::Module::Sub1"));
    repr.addClassTag(Sub2.class, new Tag("!ruby/object:Test::Module::Sub2"));
    Yaml yaml2 = new Yaml(repr, options);
    String output = yaml2.dump(result);
    // System.out.println(output);
    assertTrue("Tags must be present.",
            output.startsWith("--- !ruby/object:Test::Module::Object"));
    assertTrue("Tags must be present: " + output,
            output.contains("!ruby/object:Test::Module::Sub1"));
    assertTrue("Tags must be present.", output.contains("!ruby/object:Test::Module::Sub2"));
    // parse back.
    TestObject result2 = parseObject(output);
    assertEquals(0, result2.getSub1().getAtt2());
    assertEquals("MyString", result2.getSub2().getAtt1());
    assertEquals(1, result2.getSub2().getAtt2().size());
    assertEquals(12345, result2.getSub2().getAtt3());
}
 
開發者ID:bmoliveira,項目名稱:snake-yaml,代碼行數:24,代碼來源:RubyTest.java

示例8: testEmitWithTags2WithoutTagForParentJavabean

import org.yaml.snakeyaml.representer.Representer; //導入依賴的package包/類
public void testEmitWithTags2WithoutTagForParentJavabean() {
    TestObject result = parseObject(Util.getLocalResource("ruby/ruby1.yaml"));
    DumperOptions options = new DumperOptions();
    options.setExplicitStart(true);
    Representer repr = new Representer();
    repr.addClassTag(Sub1.class, new Tag("!ruby/object:Test::Module::Sub1"));
    repr.addClassTag(Sub2.class, new Tag("!ruby/object:Test::Module::Sub2"));
    Yaml yaml2 = new Yaml(repr, options);
    String output = yaml2.dump(result);
    // System.out.println(output);
    assertTrue("Tags must be present.",
            output.startsWith("--- !!org.yaml.snakeyaml.ruby.TestObject"));
    assertTrue("Tags must be present: " + output,
            output.contains("!ruby/object:Test::Module::Sub1"));
    assertTrue("Tags must be present.", output.contains("!ruby/object:Test::Module::Sub2"));
    // parse back.
    TestObject result2 = parseObject(output);
    assertEquals(0, result2.getSub1().getAtt2());
    assertEquals("MyString", result2.getSub2().getAtt1());
    assertEquals(1, result2.getSub2().getAtt2().size());
    assertEquals(12345, result2.getSub2().getAtt3());
}
 
開發者ID:bmoliveira,項目名稱:snake-yaml,代碼行數:23,代碼來源:RubyTest.java

示例9: testABProperty

import org.yaml.snakeyaml.representer.Representer; //導入依賴的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

示例10: checkQuotes

import org.yaml.snakeyaml.representer.Representer; //導入依賴的package包/類
private void checkQuotes(boolean isBlock, String expectation) {
    DumperOptions options = new DumperOptions();
    options.setIndent(4);
    if (isBlock) {
        options.setDefaultFlowStyle(FlowStyle.BLOCK);
    }
    Representer representer = new Representer();

    Yaml yaml = new Yaml(new SafeConstructor(), representer, options);

    LinkedHashMap<String, Object> lvl1 = new LinkedHashMap<String, Object>();
    lvl1.put("steak:cow", "11");
    LinkedHashMap<String, Object> root = new LinkedHashMap<String, Object>();
    root.put("cows", lvl1);
    String output = yaml.dump(root);
    assertEquals(expectation + "\n", output);

    // parse the value back
    @SuppressWarnings("unchecked")
    Map<String, Object> cows = (Map<String, Object>) yaml.load(output);
    @SuppressWarnings("unchecked")
    Map<String, String> cow = (Map<String, String>) cows.get("cows");
    assertEquals("11", cow.get("steak:cow"));
}
 
開發者ID:bmoliveira,項目名稱:snake-yaml,代碼行數:25,代碼來源:SingleQuoteTest.java

示例11: testErrorMessage

import org.yaml.snakeyaml.representer.Representer; //導入依賴的package包/類
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());
    }
 
開發者ID:bmoliveira,項目名稱:snake-yaml,代碼行數:23,代碼來源:AbstractBeanTest.java

示例12: testDumpClassTag

import org.yaml.snakeyaml.representer.Representer; //導入依賴的package包/類
public void testDumpClassTag() {
    Car car = new Car();
    car.setPlate("12-XP-F4");
    List<Wheel> wheels = new ArrayList<Wheel>();
    for (int i = 1; i < 6; i++) {
        Wheel wheel = new Wheel();
        wheel.setId(i);
        wheels.add(wheel);
    }
    car.setWheels(wheels);
    Representer representer = new Representer();
    representer.addClassTag(Car.class, new Tag("!car"));
    representer.addClassTag(Wheel.class, Tag.MAP);
    Yaml yaml = new Yaml(representer);
    String output = yaml.dump(car);
    assertEquals(Util.getLocalResource("constructor/car-without-tags.yaml"), output);
}
 
開發者ID:bmoliveira,項目名稱:snake-yaml,代碼行數:18,代碼來源:ClassTagsTest.java

示例13: testLoadClassTag

import org.yaml.snakeyaml.representer.Representer; //導入依賴的package包/類
public void testLoadClassTag() {
    Constructor constructor = new Constructor();
    constructor.addTypeDescription(new TypeDescription(Car.class, "!car"));
    Yaml yaml = new Yaml(constructor);
    Car car = (Car) yaml.load(Util.getLocalResource("constructor/car-without-tags.yaml"));
    assertEquals("12-XP-F4", car.getPlate());
    List<Wheel> wheels = car.getWheels();
    assertNotNull(wheels);
    assertEquals(5, wheels.size());
    Wheel w1 = wheels.get(0);
    assertEquals(1, w1.getId());
    //
    String carYaml1 = new Yaml().dump(car);
    assertTrue(carYaml1.startsWith("!!org.yaml.snakeyaml.constructor.Car"));
    //
    Representer representer = new Representer();
    representer.addClassTag(Car.class, new Tag("!car"));
    yaml = new Yaml(representer);
    String carYaml2 = yaml.dump(car);
    assertEquals(Util.getLocalResource("constructor/car-without-tags.yaml"), carYaml2);
}
 
開發者ID:bmoliveira,項目名稱:snake-yaml,代碼行數:22,代碼來源:ImplicitTagsTest.java

示例14: configYamlFormat

import org.yaml.snakeyaml.representer.Representer; //導入依賴的package包/類
private static void configYamlFormat(final ToolBelt belt, final AppConfig config) {
    DumperOptions dumperOptions = new DumperOptions();
    dumperOptions.setDefaultFlowStyle(
            "BLOCK".equalsIgnoreCase(config.getString("RD_YAML_FLOW", "BLOCK")) ?
            DumperOptions.FlowStyle.BLOCK :
            DumperOptions.FlowStyle.FLOW
    );
    dumperOptions.setPrettyFlow(config.getBool("RD_YAML_PRETTY", true));
    Representer representer = new Representer();
    representer.addClassTag(JobItem.class, Tag.MAP);
    representer.addClassTag(ScheduledJobItem.class, Tag.MAP);
    representer.addClassTag(DateInfo.class, Tag.MAP);
    representer.addClassTag(Execution.class, Tag.MAP);
    belt.formatter(new YamlFormatter(representer, dumperOptions));
    belt.channels().infoEnabled(false);
    belt.channels().warningEnabled(false);
    belt.channels().errorEnabled(false);
}
 
開發者ID:rundeck,項目名稱:rundeck-cli,代碼行數:19,代碼來源:Main.java

示例15: initialValue

import org.yaml.snakeyaml.representer.Representer; //導入依賴的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:tylerhasman,項目名稱:MapleStory,代碼行數:23,代碼來源:YamlConfiguration.java


注:本文中的org.yaml.snakeyaml.representer.Representer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。