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

com.bluenimble.platform.templating.impls.BasicVariableResolver Maven / Gradle / Ivy

There is a newer version: 2.50.0
Show newest version
package com.bluenimble.platform.templating.impls;

import java.util.Map;

import com.bluenimble.platform.Json;
import com.bluenimble.platform.Lang;
import com.bluenimble.platform.json.JsonObject;
import com.bluenimble.platform.templating.VariableResolver;

public class BasicVariableResolver implements VariableResolver {
	
	private static final long serialVersionUID = -485939153491337463L;
	
	private JsonObject data;
	
	public BasicVariableResolver (JsonObject data) {
		this.data = data;
	}
	
	@Override
	public Object resolve (String namespace, String... property) {
		if (Lang.isNullOrEmpty (namespace)) {
			return Json.find ((JsonObject)data, property);
		}
		Object root = data.get (namespace);
		if (property == null || property.length == 0) {
			return root;
		}
		if (!(root instanceof JsonObject)) {
			return null;
		}
		return Json.find ((JsonObject)root, property);
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public Map bindings () {
		return data;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy