
com.google.sitebricks.rendering.control.ChooseWidget Maven / Gradle / Ivy
package com.google.sitebricks.rendering.control;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.sitebricks.Evaluator;
import com.google.sitebricks.Renderable;
import com.google.sitebricks.Respond;
import com.google.sitebricks.binding.FlashCache;
import com.google.sitebricks.compiler.Parsing;
import com.google.sitebricks.rendering.SelfRendering;
import net.jcip.annotations.Immutable;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
/**
* @author Dhanji R. Prasanna ([email protected])
*/
@Immutable @SelfRendering
class ChooseWidget implements Renderable {
private final WidgetChain widgetChain;
private final Map map;
private final Evaluator evaluator;
private volatile Provider cache;
public ChooseWidget(WidgetChain widgetChain, String expression, Evaluator evaluator) {
this.evaluator = evaluator;
this.map = Parsing.toBindMap(expression);
this.widgetChain = widgetChain;
//TODO validate expression
}
public void render(Object bound, Respond respond) {
final String from = map.get("from");
Object o = evaluator.read(from, bound);
if (!(o instanceof Collection))
throw new IllegalArgumentException("@Choose widget's from argument MUST be of type java.util.Collection " +
"but was: " + (null == o ? "null" : o.getClass()));
respond.write("");
//store for later retrieval during binding
cache.get().put(from, collection);
}
public Set collect(Class clazz) {
return widgetChain.collect(clazz);
}
@Inject
public void setCache(Provider cache) {
this.cache = cache;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy