All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.mvel2.util.StaticFieldStub Maven / Gradle / Ivy

Go to download

TBEL is a powerful expression language for ThingsBoard platform user-defined functions. Original implementation is based on MVEL.

The newest version!
package org.mvel2.util;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

import org.mvel2.integration.VariableResolverFactory;

/**
 * @author Mike Brock
 */
public class StaticFieldStub implements StaticStub {
  private final Field field;
  private final Object cachedValue;

  public StaticFieldStub(Field field) {
    this.field = field;

    if (!field.isAccessible() || (field.getModifiers() & Modifier.STATIC) == 0) {
      throw new RuntimeException("not an accessible static field: " + field.getDeclaringClass().getName()
          + "." + field.getName());
    }

    try {
      cachedValue = field.get(null);
    }
    catch (IllegalAccessException e) {
      throw new RuntimeException("error accessing static field", e);
    }
  }

  public Object call(Object ctx, Object thisCtx, VariableResolverFactory factory, Object[] parameters) {
    return cachedValue;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy