use of org.apache.tapestry5.commons.services.ClassPropertyAdapter in project tapestry-5 by apache.
the class ComponentDefaultProviderImplTest method no_matching_property_for_default.
@Test
public void no_matching_property_for_default() {
String parameterName = "myparam";
String id = "mycomponentid";
ComponentResources resources = mockComponentResources();
Component container = mockComponent();
PropertyAccess access = mockPropertyAccess();
ClassPropertyAdapter classPropertyAdapter = mockClassPropertyAdapter();
BindingSource bindingSource = mockBindingSource();
train_getId(resources, id);
train_getContainer(resources, container);
train_getAdapter(access, container, classPropertyAdapter);
train_getPropertyAdapter(classPropertyAdapter, id, null);
replay();
ComponentDefaultProvider source = new ComponentDefaultProviderImpl(access, bindingSource, null, null, null);
assertNull(source.defaultBinding(parameterName, resources));
verify();
}
use of org.apache.tapestry5.commons.services.ClassPropertyAdapter in project tapestry-5 by apache.
the class PropertyAccessImpl method getAdapter.
@Override
public ClassPropertyAdapter getAdapter(Class forClass) {
ClassPropertyAdapter result = adapters.get(forClass);
if (result == null) {
result = buildAdapter(forClass);
adapters.put(forClass, result);
}
return result;
}
use of org.apache.tapestry5.commons.services.ClassPropertyAdapter 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.ClassPropertyAdapter 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.ClassPropertyAdapter 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