/** * Returns a {@link FieldToolSub} holding a {@link Map} * of all the public static field names to values (or a placeholder * if the value is not final) for the {@link Class} of the * specified Object. * @param instance target instance * @return {@link FieldToolSub} object * @see #in(Class clazz) */ public FieldToolSub in(Object instance) { if (instance == null) { return null; } return in(instance.getClass()); }
/** * Retrieves and returns the value of the specified {@link Field} * in the specified {@link Class}. Returns {@code null} in case of failure. * * @param field target field * @param clazz target class * @return field value */ protected Object retrieve(Field field, Class clazz) { try { return field.get(clazz); } catch(IllegalAccessException iae) { getLog().warn("IllegalAccessException while trying to access {}", field.getName(), iae); return null; } }
public Object getValue() { return retrieve(field, clazz); } }
private Context getContext(final Model model, final Node subject) { final FieldTool fieldTool = new FieldTool(); final Context context = new VelocityContext(); final String[] baseUrl = uriInfo.getBaseUri().getPath().split("/"); if (baseUrl.length > 0) { final String staticBaseUrl = String.join("/", Arrays.copyOf(baseUrl, baseUrl.length - 1)); context.put("staticBaseUrl", staticBaseUrl); } else { context.put("staticBaseUrl", "/"); } context.put("rdfLexicon", fieldTool.in(RdfLexicon.class)); context.put("helpers", VIEW_HELPERS); context.put("esc", escapeTool); context.put("rdf", model.getGraph()); context.put("model", model); context.put("subjects", model.listSubjects()); context.put("nodeany", ANY); context.put("topic", subject); context.put("originalResource", VIEW_HELPERS.getOriginalResource(subject)); context.put("uriInfo", uriInfo); return context; }
/** * Returns a {@link FieldToolSub} holding a {@link Map} * of all the public static field names to values (or a placeholder * if the value is not final) for the specified {@link Class}. * @param clazz target class * @return {@link FieldToolSub} object */ public FieldToolSub in(Class clazz) { if (clazz == null) { return null; } Map<String,Object> results = inspect(clazz); if (storeDynamicLookups && !results.isEmpty()) { storage.putAll(results); } return new FieldToolSub(results); }
/** * Returns a {@link FieldToolSub} holding a {@link Map} * of all the public static field names to values (or a placeholder * if the value is not final) for the specified class(name). If the * {@link Class} with the specified name cannot be loaded, this will * return {@code null}, rather than throw an exception. * * @param classname target class name * @return {@link FieldToolSub} object * @see #in(Class clazz) */ public FieldToolSub in(String classname) { try { return in(ClassUtils.getClass(classname)); } catch (ClassNotFoundException cnfe) { return null; } }
getLog().debug("Unable to retrieve value of field at {}", name, e);
protected void configure(ValueParser values) { // retrieve any classnames to be inspected and inspect them // *before* setting the storeDynamicLookups property! String[] classnames = values.getStrings(INCLUDE_KEY); if (classnames != null) { for (String classname : classnames) { // make sure we get results for each classname // since these come from the configuration, it's // an error if they're invalid if (in(classname) == null) { // shame that ClassNotFoundException is checked... throw new RuntimeException("Could not find "+classname+" in the classpath"); } } } // find out whether or not we should store dynamic lookups this.storeDynamicLookups = values.getBoolean(STORE_DYNAMIC_KEY, this.storeDynamicLookups); }