Example usage for org.apache.commons.beanutils DynaProperty getContentType

List of usage examples for org.apache.commons.beanutils DynaProperty getContentType

Introduction

In this page you can find the example usage for org.apache.commons.beanutils DynaProperty getContentType.

Prototype

public Class getContentType() 

Source Link

Document

Gets the (optional) type of the indexed content for DynaProperty's that support this feature.

Usage

From source file:com.github.haixing_hu.ilibrary.model.FieldTemplateTest.java

@Test
public void testToDynaProperty() {
    final FieldTemplate title = getTitleField();
    final DynaProperty titleProp = title.toDynaProperty();
    assertEquals("title", titleProp.getName());
    assertEquals(String.class, titleProp.getType());

    final FieldTemplate authors = getAuthorsField();
    final DynaProperty authorsProp = authors.toDynaProperty();
    assertEquals("authors", authorsProp.getName());
    assertEquals(List.class, authorsProp.getType());
    assertEquals(Responsibility.class, authorsProp.getContentType());
}

From source file:ddf.catalog.data.dynamic.impl.MetacardPropertyDescriptorImpl.java

/**
 * Creates a property desriptor based on the given DynaProperty object and the specified values for
 * indexedBySource, tokenized, and stored.
 * This works for the majority of cases. In cases where the underlying class representing this
 * property is the same as other property formats, {@link #setFormat(AttributeFormat)} should be
 * called after creation to set the correct format.
 * @param dynaProperty descriptor of the attribute (name, value, etc.)
 * @param indexedBySource indicates whether the source should index this attribute for search
 * @param stored indicates whether the source should store this value
 * @param tokenized indicates whether the value for this attribute should be parsed
 *//*from   www. j  av  a2s . com*/
public MetacardPropertyDescriptorImpl(DynaProperty dynaProperty, boolean indexedBySource, boolean stored,
        boolean tokenized) {
    super(dynaProperty.getName(), dynaProperty.getType(), dynaProperty.getContentType());
    this.indexedBySource = indexedBySource;
    this.stored = stored;
    this.tokenized = tokenized;
    format = getFormatFromClass(
            dynaProperty.getContentType() == null ? dynaProperty.getType() : dynaProperty.getContentType());
}

From source file:ddf.catalog.data.dynamic.impl.DynamicMetacardImpl.java

/**
 * Sets the value of the given attribute. If the attribute is a multi-valued
 * attribute, it adds the given value to the current collection. If the value
 * is multi-valued, it replaces the values of the named attribute.
 *
 * @param name  name of the attribute to set
 * @param value the value to be set/*from w  w  w .j a v a 2  s.com*/
 */
@Override
public void setAttribute(String name, Object value) {
    if (name == null) {
        LOGGER.warn("Call to set attribute with null name - no action taken.");
        return;
    }

    DynaProperty dynaProperty = attributesBean.getDynaClass().getDynaProperty(name);
    if (value == null) {
        attributesBean.set(name, value);
        return;
    }

    if (value instanceof URI) {
        value = ((URI) value).toString();
    }

    try {
        if (dynaProperty == null) {
            attributesBean.set(name, value);
        } else {
            if ((dynaProperty.getType() == Byte[].class) || !dynaProperty.isIndexed()) {
                attributesBean.set(name, value);
            } else {
                if (value instanceof Collection<?>) {
                    LOGGER.debug("Replacing current value of attribute {} with provided collection", name);
                    attributesBean.set(name, value);
                } else {
                    LOGGER.debug("Adding provided value to attribute {}", name);
                    attributesBean.set(name, attributesBean.size(name), value);
                }
            }
        }
    } catch (ConversionException e) {
        if (value != null && dynaProperty != null) {
            String classname = dynaProperty.getContentType() == null ? dynaProperty.getType().getSimpleName()
                    : dynaProperty.getContentType().getSimpleName();
            LOGGER.warn(
                    "Unable to to convert provided value of class {} to attribute {} value of class {} - no action taken.",
                    value.getClass().getSimpleName(), name, classname);
        }
    } catch (IllegalArgumentException e) {
        LOGGER.warn("Attribute {} has different than expected cardinality - no action taken", name);
    } catch (IndexOutOfBoundsException e) {
        LOGGER.warn("Trying to set attribute {} at index {} which is out of range.", name,
                attributesBean.size(name));
    } catch (NullPointerException e) {
        LOGGER.warn("Trying to set primitive type for attribute {} to a null value - no action taken", name);
    }
}

From source file:ddf.catalog.data.dynamic.impl.DynamicMetacardImpl.java

/**
 * Adds another value to the given attribute. If the attribute is not a multi-valued
 * attribute, it replaces the current value with the provided value.
 *
 * @param name  name of the attribute to set
 * @param value the value to be set//from   w  w  w . j a  v a 2s.co  m
 */
@Override
public void addAttribute(String name, Object value) {
    if (name == null) {
        LOGGER.warn("Call to add attribute with null name - no action taken.");
        return;
    }

    DynaProperty dynaProperty = attributesBean.getDynaClass().getDynaProperty(name);
    if (value instanceof URI) {
        value = ((URI) value).toString();
    }

    try {
        if (dynaProperty == null) {
            attributesBean.set(name, 0, value);
        } else {
            if (dynaProperty.isIndexed()) {
                if (value instanceof Collection) {
                    // add all attributes individually
                    for (Object o : (Collection) value) {
                        attributesBean.set(name, attributesBean.size(name), o);
                    }
                } else {
                    attributesBean.set(name, attributesBean.size(name), value);
                }
            } else {
                LOGGER.debug("Can't add another value to a simple attribute {} - replacing value.", name);
                attributesBean.set(name, value);
            }
        }
    } catch (ConversionException e) {
        if (value != null && dynaProperty != null) {
            LOGGER.warn(
                    "Unable to to convert provided value of class {} to attribute {} value of class {} - no action taken.",
                    value.getClass().getSimpleName(), name, dynaProperty.getContentType().getSimpleName());
        }
    } catch (IllegalArgumentException e) {
        LOGGER.warn("Attribute {} has different than expected cardinality - no action taken", name);
    } catch (IndexOutOfBoundsException e) {
        LOGGER.warn("Trying to set attribute {} at index {} which is out of range.", name,
                attributesBean.size(name));
    } catch (NullPointerException e) {
        LOGGER.warn("Trying to set primitive type for attribute {} to a null value - no action taken", name);
    }
}