use of org.apache.tapestry5.commons.internal.util.TapestryException in project tapestry-5 by apache.
the class DynamicTemplateSaxParser method createExpansionExtractor.
private static Mapper<DynamicDelegate, String> createExpansionExtractor(final String expression, final Location location, final BindingSource bindingSource) {
return new Mapper<DynamicDelegate, String>() {
public String map(DynamicDelegate delegate) {
try {
Binding binding = bindingSource.newBinding("dynamic template binding", delegate.getComponentResources().getContainerResources(), delegate.getComponentResources(), BindingConstants.PROP, expression, location);
Object boundValue = binding.get();
return boundValue == null ? null : boundValue.toString();
} catch (Throwable t) {
throw new TapestryException(ExceptionUtils.toMessage(t), location, t);
}
}
};
}
use of org.apache.tapestry5.commons.internal.util.TapestryException in project tapestry-5 by apache.
the class PageLoaderImpl method startComponent.
private EmbeddedComponentAssembler startComponent(AssemblerContext context) {
StartComponentToken token = context.next(StartComponentToken.class);
ComponentAssembler assembler = context.assembler;
String elementName = token.getElementName();
// Initial guess: the type from the token (but this may be null in many cases).
String embeddedType = token.getComponentType();
// This may be null for an anonymous component.
String embeddedId = token.getId();
String embeddedComponentClassName = null;
final EmbeddedComponentModel embeddedModel = embeddedId == null ? null : assembler.getModel().getEmbeddedComponentModel(embeddedId);
if (embeddedId == null)
embeddedId = assembler.generateEmbeddedId(embeddedType);
if (embeddedModel != null) {
String modelType = embeddedModel.getComponentType();
if (InternalUtils.isNonBlank(modelType) && embeddedType != null) {
throw new TapestryException(String.format("Embedded component '%s' provides a type attribute in the template ('%s') " + "as well as in the component class ('%s'). You should not provide a type attribute " + "in the template when defining an embedded component within the component class.", embeddedId, embeddedType, modelType), token, null);
}
embeddedType = modelType;
embeddedComponentClassName = embeddedModel.getComponentClassName();
}
String componentClassName = embeddedComponentClassName;
if (InternalUtils.isNonBlank(embeddedType)) {
try {
componentClassName = componentClassResolver.resolveComponentTypeToClassName(embeddedType);
} catch (RuntimeException ex) {
throw new TapestryException(ex.getMessage(), token, ex);
}
}
// OK, now we can record an action to get it instantiated.
EmbeddedComponentAssembler embeddedAssembler = assembler.createEmbeddedAssembler(embeddedId, componentClassName, embeddedModel, token.getMixins(), token.getLocation());
addActionForEmbeddedComponent(context, embeddedAssembler, embeddedId, elementName, componentClassName);
addParameterBindingActions(context, embeddedAssembler, embeddedModel);
if (embeddedModel != null && embeddedModel.getInheritInformalParameters()) {
// Another two-step: The first "captures" the container and embedded component. The second
// occurs at the end of the page setup.
assembler.add(new PageAssemblyAction() {
public void execute(PageAssembly pageAssembly) {
final ComponentPageElement container = pageAssembly.activeElement.peek();
final ComponentPageElement embedded = pageAssembly.createdElement.peek();
pageAssembly.deferred.add(new PageAssemblyAction() {
public void execute(PageAssembly pageAssembly) {
copyInformalParameters(container, embedded);
}
});
}
});
}
return embeddedAssembler;
}
use of org.apache.tapestry5.commons.internal.util.TapestryException in project tapestry-5 by apache.
the class PropertyEditorTest method no_editor_block_available.
@Test
public void no_editor_block_available() {
PropertyModel model = mockPropertyModel();
PropertyOverrides overrides = mockPropertyOverrides();
ComponentResources resources = mockComponentResources();
BeanBlockSource source = newMock(BeanBlockSource.class);
RuntimeException exception = new RuntimeException("Simulated failure.");
Messages messages = mockMessages();
Location l = mockLocation();
String propertyId = "foo";
String dataType = "unk";
String propertyName = "fooProp";
Object object = "[OBJECT]";
String formattedMessage = "formatted-message";
expect(model.getId()).andReturn(propertyId);
train_getOverrideBlock(overrides, propertyId, null);
expect(model.getDataType()).andReturn(dataType);
expect(source.getEditBlock(dataType)).andThrow(exception);
expect(model.getPropertyName()).andReturn(propertyName);
train_getLocation(resources, l);
expect(messages.format("core-block-error", propertyName, dataType, object, exception)).andReturn(formattedMessage);
replay();
PropertyEditor pe = new PropertyEditor();
pe.inject(resources, overrides, model, source, messages, object);
try {
pe.beginRender();
unreachable();
} catch (TapestryException ex) {
assertEquals(ex.getMessage(), formattedMessage);
assertSame(ex.getLocation(), l);
}
}
use of org.apache.tapestry5.commons.internal.util.TapestryException in project tapestry-5 by apache.
the class PageElementFactoryImplTest method unclosed_attribute_expression.
@Test
public void unclosed_attribute_expression() {
TypeCoercer typeCoercer = mockTypeCoercer();
BindingSource bindingSource = mockBindingSource();
ComponentResources resources = mockComponentResources();
Location location = mockLocation();
AttributeToken token = new AttributeToken(null, "fred", "${flintstone", location);
replay();
PageElementFactory factory = new PageElementFactoryImpl(typeCoercer, bindingSource);
try {
factory.newAttributeElement(resources, token);
unreachable();
} catch (TapestryException ex) {
assertEquals(ex.getMessage(), "Attribute expression \'${flintstone\' is missing a closing brace.");
assertSame(ex.getLocation(), location);
}
verify();
}
use of org.apache.tapestry5.commons.internal.util.TapestryException in project tapestry-5 by apache.
the class TemplateParserImplTest method resource_that_throws_exception.
@Test
public // TAP5-2516
void resource_that_throws_exception() throws Exception {
Resource resource = new AbstractResource("throwfoo") {
@Override
public URL toURL() {
return null;
}
@Override
public boolean exists() {
return true;
}
@Override
protected Resource newResource(String path) {
return null;
}
@Override
public InputStream openStream() throws IOException {
throw new IOException("foo");
}
};
try {
getParser().parseTemplate(resource);
unreachable();
} catch (RuntimeException ex) {
if (ex.getCause() instanceof TapestryException && ex.getCause().getCause() instanceof IOException) {
assertMessageContains(ex, "foo");
} else {
throw ex;
}
}
}
Aggregations