Example usage for java.beans MetaData getClass

List of usage examples for java.beans MetaData getClass

Introduction

In this page you can find the example usage for java.beans MetaData getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:com.googlecode.wicketwebbeans.model.BeanMetaData.java

/**
 * Applies any metadata-based CSS classes for the given bean or property to the component.
 * @param bean/*w  ww .  j  a v a2  s .  c om*/
 * @param metaData
 * @param applyToComponent
 */
public void applyCss(Object bean, MetaData metaData, Component applyToComponent) {
    String css = metaData.getParameter(PARAM_CSS);

    if (!Strings.isEmpty(css)) {
        applyToComponent.add(new AttributeAppender("class", new Model<String>(css), " "));
    }

    String dynamicCssMethod = metaData.getParameter(PARAM_DYNAMIC_CSS);
    if (!Strings.isEmpty(dynamicCssMethod)) {
        Method method = null;
        String cssReturn = null;
        try {
            method = component.getClass().getMethod(dynamicCssMethod,
                    new Class[] { beanClass, metaData.getClass() });
        } catch (NoSuchMethodException ex) {
            throw new RuntimeException("dynamicCss method " + dynamicCssMethod + "(" + beanClass.getName()
                    + ", " + metaData.getClass().getName() + ") is not defined in " + component.getClass());
        } catch (SecurityException ex) {
            throw new RuntimeException("securty exception accessing dynamicCss method " + dynamicCssMethod + "("
                    + beanClass.getName() + ", " + metaData.getClass().getName() + ") in "
                    + component.getClass(), ex);
        }
        if (bean instanceof IModel) {
            bean = ((IModel) bean).getObject();
        }
        try {
            cssReturn = (String) method.invoke(component, new Object[] { bean, metaData });
        } catch (IllegalAccessException ex) {
            throw new RuntimeException("access to dynamicCss method " + dynamicCssMethod + "("
                    + beanClass.getName() + ", " + metaData.getClass().getName() + ") in "
                    + component.getClass() + " is not allowed");
        } catch (IllegalArgumentException ex) {
            throw new RuntimeException(
                    "illegal arguments for dynamicCss method " + dynamicCssMethod + "(" + beanClass.getName()
                            + ", " + metaData.getClass().getName() + ") in " + component.getClass());
        } catch (InvocationTargetException ex) {
            throw new RuntimeException("invocation to dynamicCss method " + dynamicCssMethod + "("
                    + beanClass.getName() + ", " + metaData.getClass().getName() + ") in "
                    + component.getClass() + " has thrown an exception", ex);
        }
        if (!Strings.isEmpty(cssReturn)) {
            applyToComponent.add(new AttributeAppender("class", new Model<String>(cssReturn), " "));
        }
    }
}