use of org.apache.tapestry5.commons.services.PropertyAdapter in project tapestry-5 by apache.
the class ExceptionAnalyzerImpl method extractData.
private ExceptionData extractData(Throwable t) {
Map<String, Object> properties = CollectionFactory.newMap();
ClassPropertyAdapter adapter = propertyAccess.getAdapter(t);
Throwable cause = null;
for (String name : adapter.getPropertyNames()) {
PropertyAdapter pa = adapter.getPropertyAdapter(name);
if (!pa.isRead())
continue;
if (cause == null && Throwable.class.isAssignableFrom(pa.getType())) {
// Ignore the property, but track it as the cause.
Throwable nestedException = (Throwable) pa.get(t);
// Handle the case where an exception is its own cause (avoid endless loop!)
if (t != nestedException)
cause = nestedException;
continue;
}
if (throwableProperties.contains(name))
continue;
Object value = pa.get(t);
if (value == null)
continue;
// An interesting property, let's save it for the analysis.
properties.put(name, value);
}
// Provide the stack trace only at the deepest exception.
List<StackTraceElement> stackTrace = Collections.emptyList();
if (cause == null)
stackTrace = Arrays.asList(t.getStackTrace());
ExceptionInfo info = new ExceptionInfoImpl(t, properties, stackTrace);
return new ExceptionData(info, cause);
}
use of org.apache.tapestry5.commons.services.PropertyAdapter in project tapestry-5 by apache.
the class BeanModelSourceImpl method orderProperties.
/**
* @param classAdapter defines the bean that contains the properties
* @param propertyNames the initial set of property names, which will be rebuilt in the correct order
*/
private void orderProperties(ClassPropertyAdapter classAdapter, List<String> propertyNames) {
List<PropertyOrder> properties = CollectionFactory.newList();
for (String name : propertyNames) {
PropertyAdapter pa = classAdapter.getPropertyAdapter(name);
Method readMethod = pa.getReadMethod();
Location location = readMethod == null ? null : proxyFactory.getMethodLocation(readMethod);
int line = location == null ? -1 : location.getLine();
properties.add(new PropertyOrder(name, computeDepth(pa), line));
}
Collections.sort(properties);
propertyNames.clear();
for (PropertyOrder po : properties) {
propertyNames.add(po.propertyName);
}
}
use of org.apache.tapestry5.commons.services.PropertyAdapter 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.services.PropertyAdapter in project tapestry-5 by apache.
the class ComponentDefaultProviderImplTest method default_property_exists.
@Test
public void default_property_exists() {
String parameterName = "myparam";
String id = "mycomponentid";
ComponentResources resources = mockComponentResources();
Component container = mockComponent();
PropertyAccess access = mockPropertyAccess();
ClassPropertyAdapter classPropertyAdapter = mockClassPropertyAdapter();
PropertyAdapter propertyAdapter = mockPropertyAdapter();
BindingSource bindingSource = mockBindingSource();
Binding binding = mockBinding();
ComponentResources containerResources = mockComponentResources();
train_getId(resources, id);
train_getContainer(resources, container);
train_getAdapter(access, container, classPropertyAdapter);
train_getPropertyAdapter(classPropertyAdapter, id, propertyAdapter);
train_getContainerResources(resources, containerResources);
train_newBinding(bindingSource, "default myparam", containerResources, BindingConstants.PROP, id, binding);
replay();
ComponentDefaultProvider source = new ComponentDefaultProviderImpl(access, bindingSource, null, null, null);
assertSame(source.defaultBinding(parameterName, resources), binding);
verify();
}
use of org.apache.tapestry5.commons.services.PropertyAdapter in project tapestry-5 by apache.
the class PropertyValueLabelProvider method getLabel.
@SuppressWarnings({ "unchecked", "rawtypes" })
public String getLabel(Object object) {
final ClassPropertyAdapter classPropertyAdapter = this.propertyAccess.getAdapter(object);
final PropertyAdapter propertyAdapter = classPropertyAdapter.getPropertyAdapter(labelProperty);
final ValueEncoder encoder = this.valueEncoderSource.getValueEncoder(propertyAdapter.getType());
final Object label = propertyAdapter.get(object);
return encoder.toClient(label);
}
Aggregations