Java 类org.yaml.snakeyaml.introspector.Property 实例源码

项目:AndroidApktool    文件:CompactConstructor.java   
/**
 * Provide the name of the property which is used when the entries form a
 * sequence. The property must be a List.
 * 
 */
protected String getSequencePropertyName(Class<?> bean) {
    Set<Property> properties = getPropertyUtils().getProperties(bean);
    for (Iterator<Property> iterator = properties.iterator(); iterator.hasNext();) {
        Property property = iterator.next();
        if (!List.class.isAssignableFrom(property.getType())) {
            iterator.remove();
        }
    }
    if (properties.size() == 0) {
        throw new YAMLException("No list property found in " + bean);
    } else if (properties.size() > 1) {
        throw new YAMLException(
                "Many list properties found in "
                        + bean
                        + "; Please override getSequencePropertyName() to specify which property to use.");
    }
    return properties.iterator().next().getName();
}
项目:5zig-TIMV-Plugin    文件:CompactConstructor.java   
/**
 * Provide the name of the property which is used when the entries form a
 * sequence. The property must be a List.
 * @param bean the class to provide exactly one List property
 * @return name of the List property
 * @throws IntrospectionException if the bean cannot be introspected
 */
protected String getSequencePropertyName(Class<?> bean) throws IntrospectionException {
    Set<Property> properties = getPropertyUtils().getProperties(bean);
    for (Iterator<Property> iterator = properties.iterator(); iterator.hasNext();) {
        Property property = iterator.next();
        if (!List.class.isAssignableFrom(property.getType())) {
            iterator.remove();
        }
    }
    if (properties.size() == 0) {
        throw new YAMLException("No list property found in " + bean);
    } else if (properties.size() > 1) {
        throw new YAMLException(
                "Many list properties found in "
                        + bean
                        + "; Please override getSequencePropertyName() to specify which property to use.");
    }
    return properties.iterator().next().getName();
}
项目:smart-testing    文件:ProjectConfigurator.java   
private void dumpConfiguration(Path configFilePath) {
    try (FileWriter fileWriter = new FileWriter(configFilePath.toFile())) {
        DumperOptions options = new DumperOptions();
        options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);

        Representer representer = new Representer() {
            @Override
            protected NodeTuple representJavaBeanProperty(Object javaBean, Property property, Object propertyValue,Tag customTag) {
                // if value of property is null, ignore it.
                if (propertyValue == null) {
                    return null;
                }
                else {
                    return super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
                }
            }
        };

        representer.addClassTag(Configuration.class, Tag.MAP);

        Yaml yaml = new Yaml(representer, options);
        yaml.dump(configuration, fileWriter);
    } catch (IOException e) {
        throw new RuntimeException("Failed to dump configuration in file " + configFilePath, e);
    }
}
项目:waggle-dance    文件:AdvancedRepresenterTest.java   
@Test
public void notNullMapProperty() {
  bean.setMapProperty(ImmutableMap.<String, Long> builder().put("first", 1L).put("second", 2L).build());
  Property property = new MethodProperty(getPropertyDescriptor("mapProperty"));
  NodeTuple nodeTuple = representer.representJavaBeanProperty(bean, property, bean.getMapProperty(), null);
  assertThat(nodeTuple, is(notNullValue()));
  assertThat(nodeTuple.getKeyNode(), is(instanceOf(ScalarNode.class)));
  assertThat(((ScalarNode) nodeTuple.getKeyNode()).getValue(), is("map-property"));
  assertThat(nodeTuple.getValueNode(), is(instanceOf(MappingNode.class)));
  assertThat(((MappingNode) nodeTuple.getValueNode()).getValue().size(), is(2));
  assertThat(((MappingNode) nodeTuple.getValueNode()).getValue().get(0), is(instanceOf(NodeTuple.class)));
  assertThat(((ScalarNode) ((MappingNode) nodeTuple.getValueNode()).getValue().get(0).getKeyNode()).getValue(),
      is("first"));
  assertThat(((ScalarNode) ((MappingNode) nodeTuple.getValueNode()).getValue().get(0).getValueNode()).getValue(),
      is("1"));
  assertThat(((ScalarNode) ((MappingNode) nodeTuple.getValueNode()).getValue().get(1).getKeyNode()).getValue(),
      is("second"));
  assertThat(((ScalarNode) ((MappingNode) nodeTuple.getValueNode()).getValue().get(1).getValueNode()).getValue(),
      is("2"));
}
项目:okreplay    文件:TapeRepresenter.java   
@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);
  }
}
项目:snake-yaml    文件:CompactConstructor.java   
protected String getSequencePropertyName(Class<?> bean) {
    Set<Property> properties = getPropertyUtils().getProperties(bean);
    for (Iterator<Property> iterator = properties.iterator(); iterator.hasNext();) {
        Property property = iterator.next();
        if (!List.class.isAssignableFrom(property.getType())) {
            iterator.remove();
        }
    }
    if (properties.size() == 0) {
        throw new YAMLException("No list property found in " + bean);
    } else if (properties.size() > 1) {
        throw new YAMLException(
                "Many list properties found in "
                        + bean
                        + "; Please override getSequencePropertyName() to specify which property to use.");
    }
    return properties.iterator().next().getName();
}
项目:eva2    文件:BeanSerializer.java   
@Override
protected Set<Property> getProperties(Class<?> type)
        throws IntrospectionException {

    Set<Property> set = super.getProperties(type);
    Set<Property> filtered = new TreeSet<>();
    BeanInfo info = Introspector.getBeanInfo(type, Object.class);
    PropertyDescriptor[] properties = info.getPropertyDescriptors();
    ArrayList<String> hiddenProperties = new ArrayList<>();

    // We don't want to save Hidden properties
    for (PropertyDescriptor p : properties) {
        Method setter = p.getWriteMethod();
        if (setter != null && setter.isAnnotationPresent(Hidden.class) || p.isHidden()) {
            hiddenProperties.add(p.getName());
        }
    }

    for (Property prop : set) {
        String name = prop.getName();
        if (!hiddenProperties.contains(name)) {
            filtered.add(prop);
        }
    }
    return filtered;
}
项目:SubServers-2    文件:CompactConstructor.java   
/**
 * Provide the name of the property which is used when the entries form a
 * sequence. The property must be a List.
 * @param bean the class to provide exactly one List property
 * @return name of the List property
 * @throws IntrospectionException if the bean cannot be introspected
 */
protected String getSequencePropertyName(Class<?> bean) throws IntrospectionException {
    Set<Property> properties = getPropertyUtils().getProperties(bean);
    for (Iterator<Property> iterator = properties.iterator(); iterator.hasNext();) {
        Property property = iterator.next();
        if (!List.class.isAssignableFrom(property.getType())) {
            iterator.remove();
        }
    }
    if (properties.size() == 0) {
        throw new YAMLException("No list property found in " + bean);
    } else if (properties.size() > 1) {
        throw new YAMLException(
                "Many list properties found in "
                        + bean
                        + "; Please override getSequencePropertyName() to specify which property to use.");
    }
    return properties.iterator().next().getName();
}
项目:mdw    文件:YamlTranslator.java   
protected Representer getRepresenter() {
    return new Representer() {
        @Override
        protected Set<Property> getProperties(Class<? extends Object> type) throws IntrospectionException {
            Set<Property> props = super.getProperties(type);
            Property toRemove = null;
            for (Property prop : props) {
                if (prop.getName().equals("metaClass")) {
                    toRemove = prop;
                    break;
                }
            }
            if (toRemove != null)
                props.remove(toRemove);
            return props;
        }
    };
}
项目:contestparser    文件:YamlJavaBeanPropertyConstructor.java   
/**
 * Adds an alias for a Javabean property name on a particular type. The values of YAML
 * keys with the alias name will be mapped to the Javabean property.
 * @param alias the alias to map
 * @param type the type of property
 * @param name the property name
 */
protected final void addPropertyAlias(String alias, Class<?> type, String name) {
    Map<String, Property> typeMap = this.properties.get(type);

    if (typeMap == null) {
        typeMap = new HashMap<String, Property>();
        this.properties.put(type, typeMap);
    }

    try {
        typeMap.put(alias, this.propertyUtils.getProperty(type, name));
    }
    catch (IntrospectionException ex) {
        throw new RuntimeException(ex);
    }
}
项目:eva2    文件:BeanSerializer.java   
@Override
protected Set<Property> getProperties(Class<?> type)
        throws IntrospectionException {

    Set<Property> set = super.getProperties(type);
    Set<Property> filtered = new TreeSet<>();
    BeanInfo info = Introspector.getBeanInfo(type, Object.class);
    PropertyDescriptor[] properties = info.getPropertyDescriptors();
    ArrayList<String> hiddenProperties = new ArrayList<>();

    // We don't want to save Hidden properties
    for (PropertyDescriptor p : properties) {
        Method setter = p.getWriteMethod();
        if (setter != null && setter.isAnnotationPresent(Hidden.class) || p.isHidden()) {
            hiddenProperties.add(p.getName());
        }
    }

    for (Property prop : set) {
        String name = prop.getName();
        if (!hiddenProperties.contains(name)) {
            filtered.add(prop);
        }
    }
    return filtered;
}
项目:karamel    文件:YamlPropertyRepresenter.java   
@Override
protected Set<Property> getProperties(Class<? extends Object> type)
        throws IntrospectionException {
  List<String> order = null;
  if (type.isAssignableFrom(YamlCluster.class)) {
    order = CLUSTER_ORDER;
  } else if (type.isAssignableFrom(YamlGroup.class)) {
    order = GROUP_ORDER;
  }
  if (order != null) {
    Set<Property> standard = super.getProperties(type);
    Set<Property> sorted = new TreeSet<>(new PropertyComparator(order));
    sorted.addAll(standard);
    return sorted;
  } else {
    return super.getProperties(type);
  }
}
项目:snakeyaml    文件:CompactConstructor.java   
/**
 * Provide the name of the property which is used when the entries form a
 * sequence. The property must be a List.
 * 
 * @throws IntrospectionException
 */
protected String getSequencePropertyName(Class<?> bean) throws IntrospectionException {
    Set<Property> properties = getPropertyUtils().getProperties(bean);
    for (Iterator<Property> iterator = properties.iterator(); iterator.hasNext();) {
        Property property = iterator.next();
        if (!List.class.isAssignableFrom(property.getType())) {
            iterator.remove();
        }
    }
    if (properties.size() == 0) {
        throw new YAMLException("No list property found in " + bean);
    } else if (properties.size() > 1) {
        throw new YAMLException(
                "Many list properties found in "
                        + bean
                        + "; Please override getSequencePropertyName() to specify which property to use.");
    }
    return properties.iterator().next().getName();
}
项目:snakeyaml    文件:FilterPropertyToDumpTest.java   
@Override
protected Set<Property> getProperties(Class<? extends Object> type)
        throws IntrospectionException {
    Set<Property> set = super.getProperties(type);
    Set<Property> filtered = new TreeSet<Property>();
    if (type.equals(BeanToRemoveProperty.class)) {
        // filter properties
        for (Property prop : set) {
            String name = prop.getName();
            if (!name.equals("id")) {
                filtered.add(prop);
            }
        }
    }
    return filtered;
}
项目:TestTheTeacher    文件:CompactConstructor.java   
/**
 * Provide the name of the property which is used when the entries form a
 * sequence. The property must be a List.
 * 
 * @throws IntrospectionException
 */
protected String getSequencePropertyName(Class<?> bean) throws IntrospectionException {
    Set<Property> properties = getPropertyUtils().getProperties(bean);
    for (Iterator<Property> iterator = properties.iterator(); iterator.hasNext();) {
        Property property = iterator.next();
        if (!List.class.isAssignableFrom(property.getType())) {
            iterator.remove();
        }
    }
    if (properties.size() == 0) {
        throw new YAMLException("No list property found in " + bean);
    } else if (properties.size() > 1) {
        throw new YAMLException(
                "Many list properties found in "
                        + bean
                        + "; Please override getSequencePropertyName() to specify which property to use.");
    }
    return properties.iterator().next().getName();
}
项目:APICloud-Studio    文件:BundleCacher.java   
@Override
protected NodeTuple representJavaBeanProperty(Object javaBean, Property property, Object propertyValue,
        Tag customTag)
{
    if (javaBean instanceof AbstractElement)
    {
        if ("path".equals(property.getName()) || "buildPath".equals(property.getName())) //$NON-NLS-1$ //$NON-NLS-2$
        {
            String path = (String) propertyValue;
            IPath relative = Path.fromOSString(path).makeRelativeTo(
                    Path.fromOSString(bundleDirectory.getAbsolutePath()));
            propertyValue = relative.toOSString();
        }
    }
    return super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
}
项目:APICloud-Studio    文件:BundleCacher.java   
@Override
protected Set<Property> getProperties(Class<? extends Object> type) throws IntrospectionException
{
    if (type.equals(Ruby.class) || type.equals(KCode.class) || type.equals(RubyProc.class))
    {
        return Collections.emptySet();
    }
    Set<Property> set = super.getProperties(type);
    if (CommandElement.class.isAssignableFrom(type) || type.equals(EnvironmentElement.class))
    {
        // drop runtime, invoke, and invoke block properties
        Set<Property> toRemove = new HashSet<Property>();
        for (Property prop : set)
        {
            if ("invokeBlock".equals(prop.getName()) || "runtime".equals(prop.getName()) //$NON-NLS-1$ //$NON-NLS-2$
                    || "invoke".equals(prop.getName())) //$NON-NLS-1$
            {
                toRemove.add(prop);
            }
        }

        set.removeAll(toRemove);
    }
    return set;
}
项目:jesterj    文件:PropertyManager.java   
@Override
protected Set<Property> getProperties(Class<?> type) throws IntrospectionException {
  Set<Property> set = super.getProperties(type);
  Set<Property> filtered = new TreeSet<>();

  BeanInfo beanInfo = Introspector.getBeanInfo(type);
  PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
  Map<String, PropertyDescriptor> propMap = Arrays.asList(propertyDescriptors).stream().collect(Collectors.toMap(PropertyDescriptor::getName, Function.identity()));
  for (Property prop : set) {
    PropertyDescriptor pd = propMap.get(prop.getName());
    if (pd != null) {
      Method readMethod = pd.getReadMethod();
      AUTIL.runIfMethodAnnotated(readMethod, () -> filtered.add(prop), false, Transient.class);
    }
  }
  return filtered;
}
项目:cats    文件:SlotConnectionRepresenter.java   
@Override
/**
 * This method is not called. It was earlier and we had to filter the representation of URI in the yaml
 * Leaving this method here as an example of how to use filters for YAML for any future use.
 * 
 * @author skurup00c
 */
protected Set< Property > getProperties( Class< ? extends Object > type ) throws IntrospectionException
{
    Set< Property > set = super.getProperties( type );
    Set< Property > filtered = new TreeSet< Property >();
    for ( Property prop : set )
    {
        Class typeClass = prop.getType();
        if ( !typeClass.equals( URI.class ) )
        {
            filtered.add( prop );
        }
    }
    return filtered;
}
项目:BungeeTabListPlus    文件:YamlConfig.java   
@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;
}
项目:MooPerms    文件:Configuration.java   
@Override
protected NodeTuple representJavaBeanProperty(Object javaBean, Property property, Object propertyValue, Tag customTag) {
    if(propertyValue == null) {
        return null;
    }
    if(propertyValue instanceof Object[]) {
        Object[] objectArray = (Object[])propertyValue;
        if(objectArray.length == 0) {
            return null;
        }
    }
    if(propertyValue instanceof List<?>) {
        List<?> list = (List<?>)propertyValue;
        if(list.size() == 0) {
            return null;
        }
    }
    if(propertyValue instanceof Map<?, ?>) {
        Map<?, ?> map = (Map<?, ?>)propertyValue;
        if(map.size() == 0) {
            return null;
        }
    }

    return super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
}
项目:ServerListPlus    文件:ConfigurationRepresenter.java   
@Override // Skip null values for configuration generating
protected NodeTuple representJavaBeanProperty(Object javaBean, Property property, Object value, Tag customTag) {
    if (value != null) {
        NodeTuple tuple = super.representJavaBeanProperty(javaBean, property, value, customTag);
        Node valueNode = tuple.getValueNode();

        // Avoid using tags for enums
        if (customTag == null && valueNode.getNodeId() == NodeId.scalar && value instanceof Enum<?>) {
            valueNode.setTag(Tag.STR);
        }

        return tuple;
    } else {
        return null;
    }
}
项目:ServerListPlus    文件:OutdatedConfigurationPropertyUtils.java   
@Override
public Property getProperty(Class<?> type, String name, BeanAccess bAccess) throws IntrospectionException {
    if (bAccess != BeanAccess.FIELD) return super.getProperty(type, name, bAccess);
    Map<String, Property> properties = getPropertiesMap(type, bAccess);
    Property property = properties.get(Helper.toLowerCase(name));

    if (property == null) { // Check if property was missing and notify user if necessary
        if (type != UnknownConf.class)
            core.getLogger().log(WARN, "Unknown configuration property: %s @ %s", name, type.getSimpleName());
        return new OutdatedMissingProperty(name);
    }

    if (!property.isWritable()) // Throw exception from super method
        throw new YAMLException("Unable to find writable property '" + name + "' on class: " + type.getName());

    return property;
}
项目:org.openntf.domino    文件:CompactConstructor.java   
/**
 * Provide the name of the property which is used when the entries form a sequence. The property must be a List.
 * 
 * @throws IntrospectionException
 */
protected String getSequencePropertyName(final Class<?> bean) throws IntrospectionException {
    Set<Property> properties = getPropertyUtils().getProperties(bean);
    for (Iterator<Property> iterator = properties.iterator(); iterator.hasNext();) {
        Property property = iterator.next();
        if (!List.class.isAssignableFrom(property.getType())) {
            iterator.remove();
        }
    }
    if (properties.size() == 0) {
        throw new YAMLException("No list property found in " + bean);
    } else if (properties.size() > 1) {
        throw new YAMLException("Many list properties found in " + bean
                + "; Please override getSequencePropertyName() to specify which property to use.");
    }
    return properties.iterator().next().getName();
}
项目:microbean-helm    文件:AbstractChartWriter.java   
/**
 * Overrides the {@link
 * Representer#representJavaBeanProperty(Object, Property, Object,
 * Tag)} method to return {@code null} when the given property
 * value can be omitted from its YAML representation without loss
 * of information.
 *
 * @param bean the Java bean whose property value is being
 * represented; may be {@code null}
 *
 * @param property the {@link Property} whose value is being
 * represented; may be {@code null}
 *
 * @param value the value being represented; may be {@code null}
 *
 * @param tag the {@link Tag} in effect; may be {@code null}
 *
 * @return {@code null} or the result of invoking the {@link
 * Representer#representJavaBeanProperty(Object, Property, Object,
 * Tag)} method with the supplied values
 */
@Override
protected final NodeTuple representJavaBeanProperty(final Object bean, final Property property, final Object value, final Tag tag) {
  final NodeTuple returnValue;
  if (value == null || value.equals(Boolean.FALSE)) {
    returnValue = null;
  } else if (value instanceof CharSequence) {
    if (((CharSequence)value).length() <= 0) {
      returnValue = null;
    } else {
      returnValue = super.representJavaBeanProperty(bean, property, value, tag);
    }
  } else if (value instanceof Collection) {
    if (((Collection<?>)value).isEmpty()) {
      returnValue = null;
    } else {
      returnValue = super.representJavaBeanProperty(bean, property, value, tag);
    }
  } else if (value instanceof Map) {
    if (((Map<?, ?>)value).isEmpty()) {
      returnValue = null;
    } else {
      returnValue = super.representJavaBeanProperty(bean, property, value, tag);
    }
  } else if (value.getClass().isArray()) {
    if (Array.getLength(value) <= 0) {
      returnValue = null;
    } else {
      returnValue = super.representJavaBeanProperty(bean, property, value, tag);
    }
  } else {
    returnValue = super.representJavaBeanProperty(bean, property, value, tag);
  }
  return returnValue;
}
项目:AndroidApktool    文件:Representer.java   
/**
 * Tag logic:<br/>
 * - explicit root tag is set in serializer <br/>
 * - if there is a predefined class tag it is used<br/>
 * - a global tag with class name is always used as tag. The JavaBean parent
 * of the specified JavaBean may set another tag (tag:yaml.org,2002:map)
 * when the property class is the same as runtime class
 * 
 * @param properties
 *            JavaBean getters
 * @param javaBean
 *            instance for Node
 * @return Node to get serialized
 */
protected MappingNode representJavaBean(Set<Property> properties, Object javaBean) {
    List<NodeTuple> value = new ArrayList<NodeTuple>(properties.size());
    Tag tag;
    Tag customTag = classTags.get(javaBean.getClass());
    tag = customTag != null ? customTag : new Tag(javaBean.getClass());
    // flow style will be chosen by BaseRepresenter
    MappingNode node = new MappingNode(tag, value, null);
    representedObjects.put(javaBean, node);
    boolean bestStyle = true;
    for (Property property : properties) {
        Object memberValue = property.get(javaBean);
        Tag customPropertyTag = memberValue == null ? null : classTags.get(memberValue
                .getClass());
        NodeTuple tuple = representJavaBeanProperty(javaBean, property, memberValue,
                customPropertyTag);
        if (tuple == null) {
            continue;
        }
        if (((ScalarNode) tuple.getKeyNode()).getStyle() != null) {
            bestStyle = false;
        }
        Node nodeValue = tuple.getValueNode();
        if (!(nodeValue instanceof ScalarNode && ((ScalarNode) nodeValue).getStyle() == null)) {
            bestStyle = false;
        }
        value.add(tuple);
    }
    if (defaultFlowStyle != FlowStyle.AUTO) {
        node.setFlowStyle(defaultFlowStyle.getStyleBoolean());
    } else {
        node.setFlowStyle(bestStyle);
    }
    return node;
}
项目:AndroidApktool    文件:Representer.java   
/**
 * Represent one JavaBean property.
 * 
 * @param javaBean
 *            - the instance to be represented
 * @param property
 *            - the property of the instance
 * @param propertyValue
 *            - value to be represented
 * @param customTag
 *            - user defined Tag
 * @return NodeTuple to be used in a MappingNode. Return null to skip the
 *         property
 */
protected NodeTuple representJavaBeanProperty(Object javaBean, Property property,
        Object propertyValue, Tag customTag) {
    ScalarNode nodeKey = (ScalarNode) representData(property.getName());
    // the first occurrence of the node must keep the tag
    boolean hasAlias = this.representedObjects.containsKey(propertyValue);

    Node nodeValue = representData(propertyValue);

    if (propertyValue != null && !hasAlias) {
        NodeId nodeId = nodeValue.getNodeId();
        if (customTag == null) {
            if (nodeId == NodeId.scalar) {
                if (propertyValue instanceof Enum<?>) {
                    nodeValue.setTag(Tag.STR);
                }
            } else {
                if (nodeId == NodeId.mapping) {
                    if (property.getType() == propertyValue.getClass()) {
                        if (!(propertyValue instanceof Map<?, ?>)) {
                            if (!nodeValue.getTag().equals(Tag.SET)) {
                                nodeValue.setTag(Tag.MAP);
                            }
                        }
                    }
                }
                checkGlobalTag(property, nodeValue, propertyValue);
            }
        }
    }

    return new NodeTuple(nodeKey, nodeValue);
}
项目:AndroidApktool    文件:CompactConstructor.java   
protected void setProperties(Object bean, Map<String, Object> data) throws Exception {
    if (data == null) {
        throw new NullPointerException("Data for Compact Object Notation cannot be null.");
    }
    for (Map.Entry<String, Object> entry : data.entrySet()) {
        String key = entry.getKey();
        Property property = getPropertyUtils().getProperty(bean.getClass(), key);
        try {
            property.set(bean, entry.getValue());
        } catch (IllegalArgumentException e) {
            throw new YAMLException("Cannot set property='" + key + "' with value='"
                    + data.get(key) + "' (" + data.get(key).getClass() + ") in " + bean);
        }
    }
}
项目:AndroidApktool    文件:CompactConstructor.java   
protected void applySequence(Object bean, List<?> value) {
    try {
        Property property = getPropertyUtils().getProperty(bean.getClass(),
                getSequencePropertyName(bean.getClass()));
        property.set(bean, value);
    } catch (Exception e) {
        throw new YAMLException(e);
    }
}
项目:coteafs-config    文件:ConfigLoader.java   
/**
 * @author wasiq.bhamla
 * @since 09-Jun-2017 5:00:19 PM
 * @param cls
 */
@SuppressWarnings ("unchecked")
private <T> T loadSettings (final Class <T> cls) {
    final String path = System.getProperty (this.key, this.value);
    try (final InputStream in = getClass ().getResourceAsStream (path)) {
        if (in != null) {
            final Constructor ctor = new Constructor (cls);
            final PropertyUtils propertyUtils = new PropertyUtils () {
                @Override
                public Property getProperty (final Class <? extends Object> obj, final String name) {
                    String propertyName = name;
                    if (propertyName.indexOf ('_') > -1) {
                        propertyName = CaseFormat.LOWER_UNDERSCORE.to (CaseFormat.LOWER_CAMEL, propertyName);
                    }
                    return super.getProperty (obj, propertyName);
                }
            };
            ctor.setPropertyUtils (propertyUtils);
            final Yaml yaml = new Yaml (ctor);
            return (T) yaml.load (in);
        }
    }
    catch (final Exception e) {
        fail (CoteafsConfigNotLoadedError.class, "Error loading config file.", e);
    }
    final String MSG = "%s not found.";
    fail (CoteafsConfigFileNotFoundError.class, String.format (MSG, path));
    return null;
}
项目:5zig-TIMV-Plugin    文件:Representer.java   
/**
 * Tag logic:
 * - explicit root tag is set in serializer
 * - if there is a predefined class tag it is used
 * - a global tag with class name is always used as tag. The JavaBean parent
 * of the specified JavaBean may set another tag (tag:yaml.org,2002:map)
 * when the property class is the same as runtime class
 * 
 * @param properties
 *            JavaBean getters
 * @param javaBean
 *            instance for Node
 * @return Node to get serialized
 */
protected MappingNode representJavaBean(Set<Property> properties, Object javaBean) {
    List<NodeTuple> value = new ArrayList<NodeTuple>(properties.size());
    Tag tag;
    Tag customTag = classTags.get(javaBean.getClass());
    tag = customTag != null ? customTag : new Tag(javaBean.getClass());
    // flow style will be chosen by BaseRepresenter
    MappingNode node = new MappingNode(tag, value, null);
    representedObjects.put(javaBean, node);
    boolean bestStyle = true;
    for (Property property : properties) {
        Object memberValue = property.get(javaBean);
        Tag customPropertyTag = memberValue == null ? null : classTags.get(memberValue
                .getClass());
        NodeTuple tuple = representJavaBeanProperty(javaBean, property, memberValue,
                customPropertyTag);
        if (tuple == null) {
            continue;
        }
        if (((ScalarNode) tuple.getKeyNode()).getStyle() != null) {
            bestStyle = false;
        }
        Node nodeValue = tuple.getValueNode();
        if (!(nodeValue instanceof ScalarNode && ((ScalarNode) nodeValue).getStyle() == null)) {
            bestStyle = false;
        }
        value.add(tuple);
    }
    if (defaultFlowStyle != FlowStyle.AUTO) {
        node.setFlowStyle(defaultFlowStyle.getStyleBoolean());
    } else {
        node.setFlowStyle(bestStyle);
    }
    return node;
}
项目:5zig-TIMV-Plugin    文件:Representer.java   
/**
 * Represent one JavaBean property.
 * 
 * @param javaBean
 *            - the instance to be represented
 * @param property
 *            - the property of the instance
 * @param propertyValue
 *            - value to be represented
 * @param customTag
 *            - user defined Tag
 * @return NodeTuple to be used in a MappingNode. Return null to skip the
 *         property
 */
protected NodeTuple representJavaBeanProperty(Object javaBean, Property property,
        Object propertyValue, Tag customTag) {
    ScalarNode nodeKey = (ScalarNode) representData(property.getName());
    // the first occurrence of the node must keep the tag
    boolean hasAlias = this.representedObjects.containsKey(propertyValue);

    Node nodeValue = representData(propertyValue);

    if (propertyValue != null && !hasAlias) {
        NodeId nodeId = nodeValue.getNodeId();
        if (customTag == null) {
            if (nodeId == NodeId.scalar) {
                if (propertyValue instanceof Enum<?>) {
                    nodeValue.setTag(Tag.STR);
                }
            } else {
                if (nodeId == NodeId.mapping) {
                    if (property.getType() == propertyValue.getClass()) {
                        if (!(propertyValue instanceof Map<?, ?>)) {
                            if (!nodeValue.getTag().equals(Tag.SET)) {
                                nodeValue.setTag(Tag.MAP);
                            }
                        }
                    }
                }
                checkGlobalTag(property, nodeValue, propertyValue);
            }
        }
    }

    return new NodeTuple(nodeKey, nodeValue);
}
项目:5zig-TIMV-Plugin    文件:CompactConstructor.java   
protected void setProperties(Object bean, Map<String, Object> data) throws Exception {
    if (data == null) {
        throw new NullPointerException("Data for Compact Object Notation cannot be null.");
    }
    for (Map.Entry<String, Object> entry : data.entrySet()) {
        String key = entry.getKey();
        Property property = getPropertyUtils().getProperty(bean.getClass(), key);
        try {
            property.set(bean, entry.getValue());
        } catch (IllegalArgumentException e) {
            throw new YAMLException("Cannot set property='" + key + "' with value='"
                    + data.get(key) + "' (" + data.get(key).getClass() + ") in " + bean);
        }
    }
}
项目:5zig-TIMV-Plugin    文件:CompactConstructor.java   
protected void applySequence(Object bean, List<?> value) {
    try {
        Property property = getPropertyUtils().getProperty(bean.getClass(),
                getSequencePropertyName(bean.getClass()));
        property.set(bean, value);
    } catch (Exception e) {
        throw new YAMLException(e);
    }
}
项目:opentest    文件:SkipNullRepresenter.java   
@Override
protected NodeTuple representJavaBeanProperty(Object javaBean, Property property, Object propertyValue, Tag customTag) {
    if (propertyValue == null) { 
            return null; 
        } else { 
            return super.representJavaBeanProperty(javaBean, property, propertyValue, customTag); 
        }
}
项目:flow-platform    文件:NodeUtil.java   
@Override
public int compare(Property o1, Property o2) {
    Integer index1 = order.get(o1.getName());
    Integer index2 = order.get(o2.getName());

    if (Objects.isNull(index1) || Objects.isNull(index2)) {
        return 0;
    }

    return index1.compareTo(index2);
}
项目:flow-platform    文件:NodeUtil.java   
@Override
protected MappingNode representJavaBean(Set<Property> properties, Object javaBean) {
    List<NodeTuple> value = new ArrayList<>(properties.size());
    Tag tag;
    Tag customTag = classTags.get(javaBean.getClass());
    tag = customTag != null ? customTag : new Tag(javaBean.getClass());
    MappingNode node = new MappingNode(tag, value, null);
    representedObjects.put(javaBean, node);
    boolean bestStyle = true;

    List<Property> orderProperties = new ArrayList<>(properties);
    orderProperties.sort(sorter);

    for (Property property : orderProperties) {
        Object memberValue = property.get(javaBean);
        Tag customPropertyTag = memberValue == null ? null
            : classTags.get(memberValue.getClass());
        NodeTuple tuple = representJavaBeanProperty(javaBean, property, memberValue,
            customPropertyTag);
        if (tuple == null) {
            continue;
        }
        if (((ScalarNode) tuple.getKeyNode()).getStyle() != null) {
            bestStyle = false;
        }
        org.yaml.snakeyaml.nodes.Node nodeValue = tuple.getValueNode();
        if (!(nodeValue instanceof ScalarNode && ((ScalarNode) nodeValue).getStyle() == null)) {
            bestStyle = false;
        }
        value.add(tuple);
    }
    if (defaultFlowStyle != FlowStyle.AUTO) {
        node.setFlowStyle(defaultFlowStyle.getStyleBoolean());
    } else {
        node.setFlowStyle(bestStyle);
    }
    return node;
}
项目:waggle-dance    文件:YamlFactory.java   
@Override
protected Set<Property> createPropertySet(Class<? extends Object> type, BeanAccess bAccess)
  throws IntrospectionException {
  if (Federations.class.equals(type)) {
    // Serializing on Field order for Federations.
    Set<Property> fieldOrderedProperties = new LinkedHashSet<>(getPropertiesMap(type, BeanAccess.FIELD).values());
    Set<Property> defaultOrderPropertySet = super.createPropertySet(type, bAccess);
    Set<Property> filtered = Sets.difference(fieldOrderedProperties, defaultOrderPropertySet);
    fieldOrderedProperties.removeAll(filtered);
    return fieldOrderedProperties;
  } else {
    return super.createPropertySet(type, bAccess);
  }
}
项目:waggle-dance    文件:AdvancedPropertyUtils.java   
@Override
public Property getProperty(Class<? extends Object> type, String name) throws IntrospectionException {
  if (name.indexOf('-') > -1) {
    name = CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, name);
  }
  return super.getProperty(type, name);
}
项目:waggle-dance    文件:AdvancedPropertyUtils.java   
@Override
protected Set<Property> createPropertySet(Class<? extends Object> type, BeanAccess beanAccess)
  throws IntrospectionException {
  Set<Property> properties = new TreeSet<>();
  Collection<Property> props = getPropertiesMap(type, beanAccess).values();
  for (Property property : props) {
    if (include(property)) {
      properties.add(property);
    }
  }
  return properties;
}