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


Java BeanAccess类代码示例

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


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

示例1: createPropertySet

import org.yaml.snakeyaml.introspector.BeanAccess; //导入依赖的package包/类
@Override protected Set<Property> createPropertySet(Class<?> type, BeanAccess bAccess) {
  try {
    Set<Property> properties = super.createPropertySet(type, bAccess);
    if (Tape.class.isAssignableFrom(type)) {
      return sort(properties, "name", "interactions");
    } else if (YamlRecordedInteraction.class.isAssignableFrom(type)) {
      return sort(properties, "recorded", "request", "response");
    } else if (YamlRecordedRequest.class.isAssignableFrom(type)) {
      return sort(properties, "method", "uri", "headers", "body");
    } else if (YamlRecordedResponse.class.isAssignableFrom(type)) {
      return sort(properties, "status", "headers", "body");
    } else {
      return properties;
    }
  } catch (IntrospectionException e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:airbnb,项目名称:okreplay,代码行数:19,代码来源:TapeRepresenter.java

示例2: testArrayAsMapValue

import org.yaml.snakeyaml.introspector.BeanAccess; //导入依赖的package包/类
public void testArrayAsMapValue() {
    Yaml yaml2dump = new Yaml();
    yaml2dump.setBeanAccess(BeanAccess.FIELD);
    A data = createA();
    String dump = yaml2dump.dump(data);
    // System.out.println(dump);

    Yaml yaml2load = new Yaml();
    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,代码行数:19,代码来源:ArrayInGenericCollectionTest.java

示例3: testArrayAsMapValueWithTypeDespriptor

import org.yaml.snakeyaml.introspector.BeanAccess; //导入依赖的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

示例4: testArrayAsListValueWithTypeDespriptor

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

示例5: testErrorMessage

import org.yaml.snakeyaml.introspector.BeanAccess; //导入依赖的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

示例6: readConfigFile

import org.yaml.snakeyaml.introspector.BeanAccess; //导入依赖的package包/类
/**
 * Read a.yaml file according to a class type.
 *
 * @param file      File path of the configuration file
 * @param classType Class type of the.yaml bean
 * @param <T>       Class T
 * @return Config file bean
 * @throws CarbonIdentityMgtConfigException Error in reading configuration file
 */
public static <T> T readConfigFile(Path file, Class<T> classType)
        throws CarbonIdentityMgtConfigException {

    if (Files.exists(file)) {
        try {
            Reader in = new InputStreamReader(Files.newInputStream(file), StandardCharsets.UTF_8);
            CustomClassLoaderConstructor constructor =
                    new CustomClassLoaderConstructor(classType.getClassLoader());
            Yaml yaml = new Yaml(constructor);
            yaml.setBeanAccess(BeanAccess.FIELD);
            return yaml.loadAs(in, classType);
        } catch (IOException e) {
            throw new CarbonIdentityMgtConfigException(String.format("Error in reading file %s", file.toString())
                    , e);
        }
    } else {
        throw new CarbonIdentityMgtConfigException(String
                .format("Configuration file %s is not available.", file.toString()));
    }
}
 
开发者ID:wso2,项目名称:carbon-identity-mgt,代码行数:30,代码来源:FileUtil.java

示例7: readConfigFiles

import org.yaml.snakeyaml.introspector.BeanAccess; //导入依赖的package包/类
/**
 * Read a.yaml file according to a class type.
 *
 * @param path          folder which contain the config files
 * @param classType     Class type of the.yaml bean
 * @param fileNameRegex file name regex
 * @param <T>           Class T
 * @return Config file bean
 * @throws CarbonIdentityMgtConfigException Error in reading configuration file
 */
public static <T> List<T> readConfigFiles(Path path, Class<T> classType, String fileNameRegex)
        throws CarbonIdentityMgtConfigException {

    List<T> configEntries = new ArrayList<>();
    if (Files.exists(path)) {
        try (DirectoryStream<Path> stream = Files.newDirectoryStream(path, fileNameRegex)) {
            for (Path file : stream) {
                Reader in = new InputStreamReader(Files.newInputStream(file), StandardCharsets.UTF_8);
                CustomClassLoaderConstructor constructor =
                        new CustomClassLoaderConstructor(classType.getClassLoader());
                Yaml yaml = new Yaml(constructor);
                yaml.setBeanAccess(BeanAccess.FIELD);
                configEntries.add(yaml.loadAs(in, classType));
            }
        } catch (DirectoryIteratorException | IOException e) {
            throw new CarbonIdentityMgtConfigException(String.format("Failed to read identity connector files " +
                    "from path: %s", path.toString()), e);
        }
    }
    return configEntries;
}
 
开发者ID:wso2,项目名称:carbon-identity-mgt,代码行数:32,代码来源:FileUtil.java

示例8: writeConfigFiles

import org.yaml.snakeyaml.introspector.BeanAccess; //导入依赖的package包/类
public static <T> void writeConfigFiles(Path file, Object data)
        throws IdentityRecoveryException {

    if (Files.exists(file, new LinkOption[0])) {
        try {
            CustomClassLoaderConstructor constructor =
                    new CustomClassLoaderConstructor(FileUtil.class.getClassLoader());
            Yaml yaml = new Yaml(constructor);
            yaml.setBeanAccess(BeanAccess.FIELD);
            try (Writer writer = new OutputStreamWriter(new FileOutputStream(file.toFile()),
                                                        StandardCharsets.UTF_8)) {
                yaml.dump(data, writer);
            }
        } catch (IOException e) {
            throw new IdentityRecoveryException(
                    String.format("Error in reading file %s", new Object[] { file.toString() }), e);
        }
    } else {
        throw new IdentityRecoveryException(
                String.format("Configuration file %s is not available.", new Object[] { file.toString() }));
    }
}
 
开发者ID:wso2,项目名称:carbon-identity-mgt,代码行数:23,代码来源:FileUtil.java

示例9: readProperties

import org.yaml.snakeyaml.introspector.BeanAccess; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static Map<String, Object> readProperties(final InputStream in) throws IOException
{
    String inputStreamString = IOUtils.toString(new InputStreamReader(in, "UTF-8"));
    Yaml yaml = new Yaml();
    yaml.setBeanAccess(BeanAccess.FIELD);
    final Iterable<Object> iter = yaml.loadAll(substituteVariables(inputStreamString));

    final Map<String, Object> newProperties = new LinkedHashMap<>();

    iter.forEach(item -> {
        final Map<String, Object> section = (Map<String, Object>) item;
        newProperties.putAll(section);
    });

    return newProperties;
}
 
开发者ID:orbit,项目名称:orbit-hk2,代码行数:18,代码来源:YAMLConfigReader.java

示例10: readMailReceiver

import org.yaml.snakeyaml.introspector.BeanAccess; //导入依赖的package包/类
@Override
public List<MailReceiver> readMailReceiver() {
	File dir = git.getRepo().directory();
	File file = new File(dir, "/mailinglists.yml");
	if (!file.exists()) {
		return null;
	}
	try {
		Yaml yaml = new Yaml();
		yaml.setBeanAccess(BeanAccess.FIELD);
		return (List<MailReceiver>) yaml.load(FileUtils.readFileToString(file));
	} catch (IOException e) {
		log.error(e.getMessage(), e);
	}
	return null;
}
 
开发者ID:SchweizerischeBundesbahnen,项目名称:releasetrain,代码行数:17,代码来源:ConfigAccessorImpl.java

示例11: ChronixSparkLoader

import org.yaml.snakeyaml.introspector.BeanAccess; //导入依赖的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: build

import org.yaml.snakeyaml.introspector.BeanAccess; //导入依赖的package包/类
public static TransportsConfiguration build(String nettyTransportsConfigFile) {
    TransportsConfiguration transportsConfiguration;
    File file = new File(nettyTransportsConfigFile);
    if (file.exists()) {
        try (Reader in = new InputStreamReader(new FileInputStream(file), StandardCharsets.ISO_8859_1)) {
            Yaml yaml = new Yaml();
            yaml.setBeanAccess(BeanAccess.FIELD);
            transportsConfiguration = yaml.loadAs(in, TransportsConfiguration.class);
        } catch (IOException e) {
            String msg = "Error while loading " + nettyTransportsConfigFile + " configuration file";
            throw new RuntimeException(msg, e);
        }
    } else { // return a default config
        log.warn("Netty transport configuration file not found in: " + nettyTransportsConfigFile);
        transportsConfiguration = TransportsConfiguration.getDefault();
    }

    return transportsConfiguration;
}
 
开发者ID:wso2,项目名称:carbon-transports,代码行数:20,代码来源:YAMLTransportConfigurationBuilder.java

示例13: getConfiguration

import org.yaml.snakeyaml.introspector.BeanAccess; //导入依赖的package包/类
/**
 * Get the {@code TransportsConfiguration} represented by a particular configuration file
 *
 * @param configFileLocation configuration file location
 * @return TransportsConfiguration represented by a particular configuration file
 */
public TransportsConfiguration getConfiguration(String configFileLocation) {
    TransportsConfiguration transportsConfiguration;

    File file = new File(configFileLocation);
    if (file.exists()) {
        try (Reader in = new InputStreamReader(new FileInputStream(file), StandardCharsets.ISO_8859_1)) {
            Yaml yaml = new Yaml(new CustomClassLoaderConstructor
                    (TransportsConfiguration.class, TransportsConfiguration.class.getClassLoader()));
            yaml.setBeanAccess(BeanAccess.FIELD);
            transportsConfiguration = yaml.loadAs(in, TransportsConfiguration.class);
        } catch (IOException e) {
            throw new RuntimeException(
                    "Error while loading " + configFileLocation + " configuration file", e);
        }
    } else { // return a default config
        log.warn("Netty transport configuration file not found in: " + configFileLocation +
                 " ,hence using default configuration");
        transportsConfiguration = TransportsConfiguration.getDefault();
    }

    return transportsConfiguration;
}
 
开发者ID:wso2,项目名称:carbon-transports,代码行数:29,代码来源:ConfigurationBuilder.java

示例14: getConfiguration

import org.yaml.snakeyaml.introspector.BeanAccess; //导入依赖的package包/类
public static TransportsConfiguration getConfiguration(String configFileLocation) {
    TransportsConfiguration transportsConfiguration;

    File file = new File(TestUtil.class.getResource(configFileLocation).getFile());
    if (file.exists()) {
        try (Reader in = new InputStreamReader(new FileInputStream(file), StandardCharsets.ISO_8859_1)) {
            Yaml yaml = new Yaml(new CustomClassLoaderConstructor
                                         (TransportsConfiguration.class,
                                          TransportsConfiguration.class.getClassLoader()));
            yaml.setBeanAccess(BeanAccess.FIELD);
            transportsConfiguration = yaml.loadAs(in, TransportsConfiguration.class);
        } catch (IOException e) {
            throw new RuntimeException(
                    "Error while loading " + configFileLocation + " configuration file", e);
        }
    } else { // return a default config
        log.warn("Netty transport configuration file not found in: " + configFileLocation +
                         " ,hence using default configuration");
        transportsConfiguration = TransportsConfiguration.getDefault();
    }

    return transportsConfiguration;
}
 
开发者ID:wso2,项目名称:carbon-transports,代码行数:24,代码来源:TestUtil.java

示例15: getPropertiesMap

import org.yaml.snakeyaml.introspector.BeanAccess; //导入依赖的package包/类
@Override
protected Map<String, Property> getPropertiesMap(Class<?> type, BeanAccess bAccess) throws IntrospectionException {
    Map<String, Property> newPropertyMap = new LinkedHashMap<>();
    Map<String, Property> propertiesMap = super.getPropertiesMap(type, bAccess);
    for (Iterator<Map.Entry<String, Property>> iterator = propertiesMap.entrySet().iterator(); iterator.hasNext(); ) {
        Map.Entry<String, Property> entry = iterator.next();
        boolean updated = false;
        if (entry.getValue() instanceof FieldProperty) {
            try {
                Field field = type.getDeclaredField(entry.getValue().getName());
                Path path = field.getAnnotation(Path.class);
                if (path != null) {
                    newPropertyMap.put(path.value(), new CustomNameFieldProperty(field, path.value()));
                    updated = true;
                }
            } catch (NoSuchFieldException ignored) {
            }
        }
        if (!updated) {
            newPropertyMap.put(entry.getKey(), entry.getValue());
        }
    }

    return newPropertyMap;
}
 
开发者ID:CodeCrafter47,项目名称:BungeeTabListPlus,代码行数:26,代码来源:YamlConfig.java


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