Java Code Examples for groovy.lang.MetaClass#setProperty()

The following examples show how to use groovy.lang.MetaClass#setProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GrailsHibernateUtil.java    From gorm-hibernate5 with Apache License 2.0 5 votes vote down vote up
/**
 * Increments the entities version number in order to force an update
 * @param target The target entity
 */
public static void incrementVersion(Object target) {
    MetaClass metaClass = GroovySystem.getMetaClassRegistry().getMetaClass(target.getClass());
    if (metaClass.hasProperty(target, GormProperties.VERSION)!=null) {
        Object version = metaClass.getProperty(target, GormProperties.VERSION);
        if (version instanceof Long) {
            Long newVersion = (Long) version + 1;
            metaClass.setProperty(target, GormProperties.VERSION, newVersion);
        }
    }
}
 
Example 2
Source File: InvokerHelper.java    From groovy with Apache License 2.0 5 votes vote down vote up
private static void setPropertySafe(Object object, MetaClass mc, String key, Object value) {
    try {
        mc.setProperty(object, key, value);
    } catch (MissingPropertyException mpe) {
        // Ignore
    } catch (InvokerInvocationException iie) {
        // GROOVY-5802 IAE for missing properties with classes that extend List
        Throwable cause = iie.getCause();
        if (!(cause instanceof IllegalArgumentException)) throw iie;
    }
}
 
Example 3
Source File: IndyGuardsFiltersAndSignatures.java    From groovy with Apache License 2.0 5 votes vote down vote up
/**
 * This method is called by the handle to realize the bean constructor
 * with property map.
 */
public static Object setBeanProperties(MetaClass mc, Object bean, Map properties) {
    for (Object o : properties.entrySet()) {
        Map.Entry entry = (Map.Entry) o;
        String key = entry.getKey().toString();

        Object value = entry.getValue();
        mc.setProperty(bean, key, value);
    }
    return bean;
}
 
Example 4
Source File: OwnedMetaClass.java    From groovy with Apache License 2.0 4 votes vote down vote up
public void setProperty(Object object, String property, Object newValue) {
    final Object owner = getOwner();
    final MetaClass ownerMetaClass = getOwnerMetaClass(owner);
    ownerMetaClass.setProperty(object, property, newValue);
}
 
Example 5
Source File: OwnedMetaClass.java    From groovy with Apache License 2.0 4 votes vote down vote up
public void setProperty(Class sender, Object receiver, String messageName, Object messageValue, boolean useSuper, boolean fromInsideClass) {
    final Object owner = getOwner();
    final MetaClass ownerMetaClass = getOwnerMetaClass(owner);
    ownerMetaClass.setProperty(sender, owner, messageName, messageValue, useSuper, fromInsideClass);
}