use of org.apache.tapestry5.commons.Location 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;
}
use of org.apache.tapestry5.commons.Location in project tapestry-5 by apache.
the class ValidateBindingFactory method newBinding.
public Binding newBinding(String description, ComponentResources container, ComponentResources component, final String expression, Location location) {
Object fieldAsObject = component.getComponent();
if (!Field.class.isInstance(fieldAsObject))
throw new TapestryException(String.format("Component '%s' is not a field (it does not implement the Field interface) and may not be used with the validate: binding prefix.", component.getCompleteId()), location, null);
final Field field = (Field) fieldAsObject;
return new InvariantBinding(location, FieldValidator.class, interner.intern(description + ": " + expression)) {
public Object get() {
return fieldValidatorSource.createValidators(field, expression);
}
};
}
use of org.apache.tapestry5.commons.Location in project tapestry-5 by apache.
the class DynamicTemplateSaxParser method block.
private DynamicTemplateElement block(final String blockId) {
Location location = getLocation();
removeContent();
return createBlockElement(blockId, location);
}
use of org.apache.tapestry5.commons.Location in project tapestry-5 by apache.
the class DynamicTemplateSaxParser method createBlockElement.
private static DynamicTemplateElement createBlockElement(final String blockId, final Location location) {
return new DynamicTemplateElement() {
public void render(MarkupWriter writer, RenderQueue queue, DynamicDelegate delegate) {
try {
Block block = delegate.getBlock(blockId);
queue.push((RenderCommand) block);
} catch (Exception ex) {
throw new TapestryException(String.format("Exception rendering block '%s' as part of dynamic template: %s", blockId, ExceptionUtils.toMessage(ex)), location, ex);
}
}
};
}
use of org.apache.tapestry5.commons.Location in project tapestry-5 by apache.
the class PageElementFactoryImplTest method attribute.
@Test
public void attribute() {
TypeCoercer typeCoercer = mockTypeCoercer();
BindingSource bindingSource = mockBindingSource();
MarkupWriter writer = new MarkupWriterImpl(xmlModel);
Location l = mockLocation();
RenderQueue queue = mockRenderQueue();
replay();
PageElementFactory factory = new PageElementFactoryImpl(typeCoercer, bindingSource);
AttributeToken token = new AttributeToken(null, "name", "value", l);
RenderCommand element = factory.newAttributeElement(null, token);
writer.element("root");
element.render(writer, queue);
verify();
assertEquals(writer.toString(), "<?xml version=\"1.0\"?>\n<root name=\"value\"/>");
}
Aggregations