Example usage for org.springframework.core Conventions attributeNameToPropertyName

List of usage examples for org.springframework.core Conventions attributeNameToPropertyName

Introduction

In this page you can find the example usage for org.springframework.core Conventions attributeNameToPropertyName.

Prototype

public static String attributeNameToPropertyName(String attributeName) 

Source Link

Document

Convert String s in attribute name format (e.g.

Usage

From source file:org.jdal.beans.BeanDefinitionUtils.java

/**
 * Add property value to {@link BeanDefinitionBuilder} if needed, following the naming {@link Conventions}
 * @param bdb BeanDefintionBuilder to operate on.
 * @param element Element holding the attribute
 * @param attributeName the attribute name
 *//*from  w ww .  jav a2  s . co m*/
public static void addPropertyValueIfNeeded(BeanDefinitionBuilder bdb, Element element, String attributeName) {
    if (element.hasAttribute(attributeName))
        bdb.addPropertyValue(Conventions.attributeNameToPropertyName(attributeName),
                element.getAttribute(attributeName));
}

From source file:org.jdal.beans.BeanDefinitionUtils.java

/**
 * Add property reference to {@link BeanDefinitionBuilder} if needed, following the naming {@link Conventions}
 * @param bdb BeanDefintionBuilder to operate on.
 * @param element Element holding the attribute
 * @param attributeName the attribute name
 *///from  ww w .j a  v  a  2  s . com
public static void addPropertyReferenceIfNeeded(BeanDefinitionBuilder bdb, Element element,
        String attributeName) {
    if (element.hasAttribute(attributeName))
        bdb.addPropertyReference(Conventions.attributeNameToPropertyName(attributeName),
                element.getAttribute(attributeName));
}

From source file:org.activiti.spring.components.config.xml.ActivitiAnnotationDrivenBeanDefinitionParser.java

private void configureProcessEngine(AbstractBeanDefinition abstractBeanDefinition, Element element) {
    String procEngineRef = element.getAttribute(processEngineAttribute);
    if (StringUtils.hasText(procEngineRef))
        abstractBeanDefinition.getPropertyValues().add(
                Conventions.attributeNameToPropertyName(processEngineAttribute),
                new RuntimeBeanReference(procEngineRef));
}

From source file:com.shopzilla.spring.util.config.ShopzillaNamespaceUtils.java

/**
 * Populates the bean definition property corresponding to the specified attributeName with the value of that attribute if it is defined in the given element. <p>The property name will be the camel-case equivalent of the lower case hyphen separated attribute (e.g. the "foo-bar" attribute would
 * match the "fooBar" property).//from  w  w w  . j  a v  a2 s .  c  om
 *
 * @param beanDefinitionBuilder - the bean definition to be configured
 * @param element               - the XML element where the attribute should be defined
 * @param attributeName         - the name of the attribute whose value will be set on the property
 *
 * @see org.springframework.core.Conventions#attributeNameToPropertyName(String)
 */
public void setValueIfAttributeDefined(BeanDefinitionBuilder beanDefinitionBuilder, Element element,
        String attributeName) {
    setValueIfAttributeDefined(beanDefinitionBuilder, element, attributeName,
            Conventions.attributeNameToPropertyName(attributeName));
}

From source file:com.shopzilla.spring.util.config.ShopzillaNamespaceUtils.java

/**
 * Populates the bean definition property corresponding to the specified attributeName with the reference to a bean identified by the value of that attribute if the attribute is defined in the given element. <p>The property name will be the camel-case equivalent of the lower case hyphen
 * separated attribute (e.g. the "foo-bar" attribute would match the "fooBar" property).
 *
 * @param builder       - the bean definition to be configured
 * @param element       - the XML element where the attribute should be defined
 * @param attributeName - the name of the attribute whose value will be used as a bean reference to populate the property
 *
 * @see Conventions#attributeNameToPropertyName(String)
 * @see Conventions#attributeNameToPropertyName(String)
 *//*from   w  w w  .  ja v a  2  s  . com*/
public void setReferenceIfAttributeDefined(BeanDefinitionBuilder builder, Element element,
        String attributeName) {
    setReferenceIfAttributeDefined(builder, element, attributeName,
            Conventions.attributeNameToPropertyName(attributeName));
}

From source file:org.jdal.beans.TableBeanDefinitionParser.java

/**
 * {@inheritDoc}/* w  w  w .  j  a v  a  2  s.c  o m*/
 */
@SuppressWarnings("rawtypes")
public BeanDefinition parse(Element element, ParserContext parserContext) {
    // Defaults
    String entity = null;

    if (element.hasAttribute(ENTITY))
        entity = element.getAttribute(ENTITY);

    String name = StringUtils.uncapitalize(StringUtils.substringAfterLast(entity, "."));

    if (element.hasAttribute(ID))
        name = element.getAttribute(ID);

    parserContext.pushContainingComponent(
            new CompositeComponentDefinition(name, parserContext.extractSource(element)));

    // Bean names
    String tableModelBeanName = name + LIST_TABLE_MODEL_SUFFIX;
    String tablePanelBeanName = name + TABLE_PANEL_SUFFIX;
    String pageableTableBeanName = name + PAGEABLE_TABLE_SUFFIX;
    String dataSource = name + SERVICE_SUFFIX;
    String paginator = PAGINATOR_VIEW;
    String editor = name + EDITOR_SUFFIX;
    String actions = DefaultsBeanDefinitionParser.DEFAULT_TABLE_ACTIONS;
    String guiFactory = DefaultsBeanDefinitionParser.DEFAULT_GUI_FACTORY;
    String scope = BeanDefinition.SCOPE_PROTOTYPE;

    if (element.hasAttribute(SERVICE_ATTRIBUTE))
        dataSource = element.getAttribute(SERVICE_ATTRIBUTE);

    if (element.hasAttribute(PAGINATOR))
        paginator = element.getAttribute(PAGINATOR);

    if (element.hasAttribute(ACTIONS))
        actions = element.getAttribute(ACTIONS);

    if (element.hasAttribute(GUI_FACTORY))
        guiFactory = element.getAttribute(GUI_FACTORY);

    if (element.hasAttribute(EDITOR))
        editor = element.getAttribute(EDITOR);

    if (element.hasAttribute(SCOPE))
        scope = element.getAttribute(SCOPE);

    // create ListTableModel
    BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition(ListTableModel.class);
    bdb.setScope(scope);
    bdb.addPropertyValue("modelClass", entity);
    NodeList nl = element.getElementsByTagNameNS(element.getNamespaceURI(), COLUMNS);

    if (nl.getLength() > 0) {
        List columns = parserContext.getDelegate().parseListElement((Element) nl.item(0),
                bdb.getRawBeanDefinition());
        bdb.addPropertyValue(COLUMNS, columns);
    }
    registerBeanDefinition(element, parserContext, tableModelBeanName, bdb);

    // create PageableTable
    bdb = BeanDefinitionBuilder.genericBeanDefinition(PageableTable.class);
    bdb.setScope(BeanDefinition.SCOPE_PROTOTYPE);
    bdb.addPropertyReference(DATA_SOURCE, dataSource);
    bdb.addPropertyReference(PAGINATOR_VIEW, paginator);
    bdb.addPropertyReference(TABLE_MODEL, tableModelBeanName);
    bdb.addPropertyValue(NAME, pageableTableBeanName);

    if (element.hasAttribute(TABLE_SERVICE))
        bdb.addPropertyReference(Conventions.attributeNameToPropertyName(TABLE_SERVICE),
                element.getAttribute(TABLE_SERVICE));

    if (element.hasAttribute(FILTER))
        bdb.addPropertyReference(FILTER, element.getAttribute(FILTER));

    if (element.hasAttribute(SHOW_MENU))
        bdb.addPropertyValue(Conventions.attributeNameToPropertyName(SHOW_MENU),
                element.getAttribute(SHOW_MENU));

    if (element.hasAttribute(MESSAGE_SOURCE))
        bdb.addPropertyReference(MESSAGE_SOURCE, element.getAttribute(MESSAGE_SOURCE));

    registerBeanDefinition(element, parserContext, pageableTableBeanName, bdb);

    // create TablePanel
    String tablePanelClassName = "org.jdal.swing.table.TablePanel";
    if (element.hasAttribute(TABLE_PANEL_CLASS))
        tablePanelClassName = element.getAttribute(TABLE_PANEL_CLASS);

    bdb = BeanDefinitionBuilder.genericBeanDefinition(tablePanelClassName);
    bdb.setScope(BeanDefinition.SCOPE_PROTOTYPE);
    bdb.addPropertyReference(TABLE, pageableTableBeanName);
    bdb.addPropertyReference(GUI_FACTORY, guiFactory);
    bdb.addPropertyValue(EDITOR_NAME, editor);
    bdb.addPropertyReference(PERSISTENT_SERVICE, dataSource);

    if (element.hasAttribute(FILTER_VIEW))
        bdb.addPropertyReference(Conventions.attributeNameToPropertyName(FILTER_VIEW),
                element.getAttribute(FILTER_VIEW));

    if (!element.hasAttribute(USE_ACTIONS) || "true".equals(element.getAttribute(USE_ACTIONS)))
        bdb.addPropertyReference(ACTIONS, actions);

    registerBeanDefinition(element, parserContext, tablePanelBeanName, bdb);

    parserContext.popAndRegisterContainingComponent();

    return null;
}

From source file:com.apporiented.spring.override.GenericBeanDefinitionParser.java

/**
 * Extract a JavaBean property name from the supplied attribute name.
 * <p>The default implementation first looks for a translation set via
 * {@link #addTranslation(String, String)}. If no translation is found,
 * the {@link org.springframework.core.Conventions#attributeNameToPropertyName(String)}
 * method to perform the extraction.//from   w w  w.  j a va  2 s. c o  m
 * <p>The name returned must obey the standard JavaBean property name
 * conventions. For example for a class with a setter method
 * '<code>setBingoHallFavourite(String)</code>', the name returned had
 * better be '<code>bingoHallFavourite</code>' (with that exact casing).
 * @param attributeName the attribute name taken straight from the
 * XML element being parsed (never <code>null</code>)
 * @return the extracted JavaBean property name (must never be <code>null</code>)
 */
protected String extractPropertyName(String attributeName) {
    String property = (String) translations.get(attributeName);
    if (property == null) {
        property = Conventions.attributeNameToPropertyName(attributeName);
    }
    return property;
}

From source file:com.mtgi.analytics.aop.config.TemplateBeanDefinitionParser.java

/**
 * Convenience method to update a template bean definition from overriding XML data.  
 * If <code>overrides</code> contains attribute <code>attribute</code> or a child element
 * with name <code>attribute</code>, transfer that
 * attribute as a bean property onto <code>template</code>, overwriting the default value.
 * @param reference if true, the value of the attribute is to be interpreted as a runtime bean name reference; otherwise it is interpreted as a literal value
 *///w w w  .j a va2s  .c  o m
public static boolean overrideProperty(String attribute, BeanDefinition template, Element overrides,
        boolean reference) {
    Object value = null;
    if (overrides.hasAttribute(attribute)) {
        value = overrides.getAttribute(attribute);
    } else {
        NodeList children = overrides.getElementsByTagNameNS("*", attribute);
        if (children.getLength() == 1) {
            Element child = (Element) children.item(0);
            value = child.getTextContent();
        }
    }

    if (value != null) {
        if (reference)
            value = new RuntimeBeanReference(value.toString());

        String propName = Conventions.attributeNameToPropertyName(attribute);
        MutablePropertyValues props = template.getPropertyValues();
        props.removePropertyValue(propName);
        props.addPropertyValue(propName, value);
        return true;
    }

    return false;
}

From source file:org.openspaces.core.config.LocalTxManagerBeanDefinitionParser.java

protected String extractPropertyName(String attributeName) {
    return Conventions.attributeNameToPropertyName(attributeName);
}

From source file:org.springframework.data.gemfire.config.ParsingUtils.java

@SuppressWarnings("unused")
static void setPropertyReference(Element element, BeanDefinitionBuilder builder, String attributeName) {
    setPropertyReference(element, builder, attributeName,
            Conventions.attributeNameToPropertyName(attributeName));
}