use of org.apache.tapestry5.commons.services.TypeCoercer in project tapestry-5 by apache.
the class MetaDataLocatorImplTest method not_found_by_page_name_but_found_in_configuration.
@Test
public void not_found_by_page_name_but_found_in_configuration() {
ComponentModel model = mockComponentModel();
SymbolSource symbolSource = mockSymbolSource();
ComponentModelSource modelSource = mockComponentModelSource();
String key = "foo.bar";
String value = "zaphod";
String pageName = "gnip/Gnop";
expect(modelSource.getPageModel(pageName)).andReturn(model);
train_getMeta(model, key, null);
train_expandSymbols(symbolSource, value, "*expanded*");
replay();
Map<String, String> configuration = CollectionFactory.newMap();
configuration.put("gnip:foo.bar", value);
MetaDataLocator locator = new MetaDataLocatorImpl(symbolSource, typeCoercer, modelSource, configuration);
assertSame(locator.findMeta(key, pageName, String.class), "*expanded*");
verify();
}
use of org.apache.tapestry5.commons.services.TypeCoercer in project tapestry-5 by apache.
the class MetaDataLocatorImplTest method find_by_page_name.
@Test
public void find_by_page_name() {
ComponentModel model = mockComponentModel();
SymbolSource symbolSource = mockSymbolSource();
ComponentModelSource modelSource = mockComponentModelSource();
String key = "foo.bar";
String value = "zaphod";
String pageName = "foo/Bar";
expect(modelSource.getPageModel(pageName)).andReturn(model);
train_getMeta(model, key, value);
train_expandSymbols(symbolSource, value, "*expanded*");
replay();
Map<String, String> configuration = Collections.emptyMap();
MetaDataLocator locator = new MetaDataLocatorImpl(symbolSource, typeCoercer, modelSource, configuration);
assertSame(locator.findMeta(key, pageName, String.class), "*expanded*");
verify();
}
use of org.apache.tapestry5.commons.services.TypeCoercer in project tapestry-5 by apache.
the class MetaDataLocatorImplTest method default_to_symbol_source.
@Test
public void default_to_symbol_source() {
ComponentResources resources = mockComponentResources();
ComponentModel model = mockComponentModel();
SymbolSource symbolSource = mockSymbolSource();
ComponentModelSource modelSource = mockComponentModelSource();
String key = "foo.bar";
String value = "zaphod";
String completeId = "foo/Bar:baz";
train_getCompleteId(resources, completeId);
train_getComponentModel(resources, model);
train_getMeta(model, key, null);
train_getContainerResources(resources, null);
train_getPageName(resources, "foo/Bar");
train_valueForSymbol(symbolSource, key, value);
replay();
Map<String, String> configuration = Collections.emptyMap();
MetaDataLocator locator = new MetaDataLocatorImpl(symbolSource, typeCoercer, modelSource, configuration);
assertSame(locator.findMeta(key, resources, String.class), value);
verify();
// And check that it's cached:
train_getCompleteId(resources, completeId);
replay();
assertSame(locator.findMeta(key, resources, String.class), value);
verify();
}
use of org.apache.tapestry5.commons.services.TypeCoercer in project tapestry-5 by apache.
the class TapestryModule method contributeObjectRenderer.
/**
* Contributes a default object renderer for type Object, plus specialized
* renderers for {@link org.apache.tapestry5.http.services.Request}, {@link org.apache.tapestry5.commons.Location},
* {@link org.apache.tapestry5.ComponentResources}, {@link org.apache.tapestry5.EventContext},
* {@link AvailableValues},
* List, and Object[].
*/
@SuppressWarnings("unchecked")
public void contributeObjectRenderer(MappedConfiguration<Class, ObjectRenderer> configuration, @InjectService("LocationRenderer") ObjectRenderer locationRenderer, final TypeCoercer typeCoercer) {
configuration.add(Object.class, new DefaultObjectRenderer());
configuration.addInstance(Request.class, RequestRenderer.class);
configuration.add(Location.class, locationRenderer);
ObjectRenderer preformatted = new ObjectRenderer<Object>() {
public void render(Object object, MarkupWriter writer) {
writer.element("pre");
writer.write(typeCoercer.coerce(object, String.class));
writer.end();
}
};
configuration.addInstance(List.class, ListRenderer.class);
configuration.addInstance(Object[].class, ObjectArrayRenderer.class);
configuration.addInstance(ComponentResources.class, ComponentResourcesRenderer.class);
configuration.addInstance(EventContext.class, EventContextRenderer.class);
configuration.add(AvailableValues.class, new AvailableValuesRenderer());
}
use of org.apache.tapestry5.commons.services.TypeCoercer in project tapestry-5 by apache.
the class BeanModelSourceImpl method create.
public <T> BeanModel<T> create(Class<T> beanClass, boolean filterReadOnlyProperties, Messages messages) {
assert beanClass != null;
assert messages != null;
ClassPropertyAdapter adapter = propertyAccess.getAdapter(beanClass);
BeanModel<T> model = new BeanModelImpl<T>(beanClass, propertyConduitSource, typeCoercer, messages, locator);
for (final String propertyName : adapter.getPropertyNames()) {
PropertyAdapter pa = adapter.getPropertyAdapter(propertyName);
if (!pa.isRead()) {
continue;
}
if (isStaticFieldProperty(pa)) {
continue;
}
if (pa.getAnnotation(NonVisual.class) != null) {
continue;
}
if (filterReadOnlyProperties && !pa.isUpdate()) {
continue;
}
final String dataType = dataTypeAnalyzer.identifyDataType(pa);
if (dataType == null) {
continue;
}
model.add(propertyName).dataType(dataType);
}
// First, order the properties based on the location of the getter method
// within the class.
List<String> propertyNames = model.getPropertyNames();
orderProperties(adapter, propertyNames);
model.reorder(propertyNames.toArray(new String[propertyNames.size()]));
// Next, check for an annotation with specific ordering information.
ReorderProperties reorderAnnotation = beanClass.getAnnotation(ReorderProperties.class);
if (reorderAnnotation != null) {
BeanModelUtils.reorder(model, reorderAnnotation.value());
}
return model;
}
Aggregations