Example usage for org.apache.commons.beanutils BeanMap getReadMethod

List of usage examples for org.apache.commons.beanutils BeanMap getReadMethod

Introduction

In this page you can find the example usage for org.apache.commons.beanutils BeanMap getReadMethod.

Prototype

protected Method getReadMethod(Object name) 

Source Link

Document

Returns the accessor for the property with the given name.

Usage

From source file:org.sindice.rdfcommons.beanmapper.BeanSerializer.java

@SuppressWarnings("unchecked")
public Identifier serialize(SerializationContext context, Object bean, Annotation[] annotations,
        TripleSet buffer) throws SerializationException {

    // Handling adapted object.
    Object adapted = getAdapted(bean);
    if (adapted != null) {
        return context.serialize(context, adapted, annotations, buffer);
    }//  w w  w . j  av  a 2  s . com

    // Handling common bean.
    try {
        BeanMap beanMap = new BeanMap(bean);
        final String classUrl = getClassURL(bean.getClass());
        final String instanceUrl = getObjectURL(bean);

        buffer.addTriple(instanceUrl, RDFVocabulary.TYPE, classUrl);

        for (Map.Entry<String, Object> entry : (Set<Map.Entry<String, Object>>) beanMap.entrySet()) {
            final String propertyName = entry.getKey();
            final Method propertyReadMethod = beanMap.getReadMethod(propertyName);

            // Skipping self description.
            if ("class".equals(entry.getKey())) {
                continue;
            }
            // Skipping properties marked as ignored.
            if (isIgnored(propertyReadMethod)) {
                continue;
            }
            // Avoid serialization of null values.
            final Object propertyValue = entry.getValue();
            if (propertyValue == null) {
                continue;
            }

            Identifier identifierEntry = context.serialize(context, propertyValue,
                    getAnnotations(propertyReadMethod), buffer);

            buffer.addTriple(instanceUrl, getPropertyURL(classUrl, propertyName, propertyReadMethod),
                    identifierEntry.getId(), identifierEntry.isLiteral() ? ObjectType.literal : ObjectType.uri);

        }
        return null;
    } catch (Exception e) {
        throw new SerializationException(e);
    }
}

From source file:org.sindice.rdfcommons.beanmapper.StaticBeanSerializer.java

public Identifier serialize(SerializationContext context, Object bean, Annotation[] annotations,
        TripleSet buffer) throws SerializationException {
    try {//w ww .  j a  va2 s. com
        BeanMap beanMap = new BeanMap(bean);
        final String classURL = getClassURL(bean.getClass());
        for (Map.Entry<String, Object> entry : (Set<Map.Entry<String, Object>>) beanMap.entrySet()) {

            final String propertyName = entry.getKey();
            final Method propertyReadMethod = beanMap.getReadMethod(propertyName);

            // Skipping self description.
            if ("class".equals(propertyName)) {
                continue;
            }
            // Skipping properties marked as ignored.
            if (isIgnored(propertyReadMethod)) {
                continue;
            }

            Object propertyValue = entry.getValue();

            Identifier identifierEntry = context.serialize(context, propertyValue,
                    getAnnotations(propertyReadMethod), buffer);

            buffer.addTriple(classURL, getPropertyURL(classURL, propertyName, propertyReadMethod),
                    identifierEntry.getId(), identifierEntry.isLiteral() ? ObjectType.literal : ObjectType.uri);

        }
        return null;
    } catch (Exception e) {
        e.printStackTrace();
        throw new SerializationException(e);
    }
}