use of org.apache.tapestry5.ioc.annotations.Value in project tapestry-5 by apache.
the class PropBindingFactoryTest method method_not_found_in_preamble.
@Test
public void method_not_found_in_preamble() {
TargetBean bean = new TargetBean();
ComponentResources resources = mockComponentResources();
Location l = mockLocation();
train_getComponent(resources, bean);
replay();
try {
factory.newBinding("test binding", resources, null, "isThatRealBlood().value", l);
unreachable();
} catch (RuntimeException ex) {
assertMessageContains(ex, "Class org.apache.tapestry5.internal.bindings.TargetBean does not contain a public method named 'isThatRealBlood()'");
}
verify();
}
use of org.apache.tapestry5.ioc.annotations.Value in project tapestry-5 by apache.
the class TypeCoercerImpl method findOrCreateCoercion.
/**
* Here's the real meat; we do a search of the space to find coercions, or a system of
* coercions, that accomplish
* the desired coercion.
*
* There's <strong>TREMENDOUS</strong> room to improve this algorithm. For example, inheritance lists could be
* cached. Further, there's probably more ways to early prune the search. However, even with dozens or perhaps
* hundreds of tuples, I suspect the search will still grind to a conclusion quickly.
*
* The order of operations should help ensure that the most efficient tuple chain is located. If you think about how
* tuples are added to the queue, there are two factors: size (the number of steps in the coercion) and
* "class distance" (that is, number of steps up the inheritance hiearchy). All the appropriate 1 step coercions
* will be considered first, in class distance order. Along the way, we'll queue up all the 2 step coercions, again
* in class distance order. By the time we reach some of those, we'll have begun queueing up the 3 step coercions, and
* so forth, until we run out of input tuples we can use to fabricate multi-step compound coercions, or reach a
* final response.
*
* This does create a good number of short lived temporary objects (the compound tuples), but that's what the GC is
* really good at.
*
* @param sourceType
* @param targetType
* @return coercer from sourceType to targetType
*/
@SuppressWarnings("unchecked")
private Coercion findOrCreateCoercion(Class sourceType, Class targetType) {
if (sourceType == Void.class) {
return searchForNullCoercion(targetType);
}
// Trying to find exact match.
Optional<CoercionTuple> maybeTuple = getTuples(sourceType, targetType).stream().filter((t) -> sourceType.equals(t.getSourceType()) && targetType.equals(t.getTargetType())).findFirst();
if (maybeTuple.isPresent()) {
return maybeTuple.get().getCoercion();
}
// These are instance variables because this method may be called concurrently.
// On a true race, we may go to the work of seeking out and/or fabricating
// a tuple twice, but it's more likely that different threads are looking
// for different source/target coercions.
Set<CoercionTuple.Key> consideredTuples = CollectionFactory.newSet();
LinkedList<CoercionTuple> queue = CollectionFactory.newLinkedList();
seedQueue(sourceType, targetType, consideredTuples, queue);
while (!queue.isEmpty()) {
CoercionTuple tuple = queue.removeFirst();
// If the tuple results in a value type that is assignable to the desired target type,
// we're done! Later, we may add a concept of "cost" (i.e. number of steps) or
// "quality" (how close is the tuple target type to the desired target type). Cost
// is currently implicit, as compound tuples are stored deeper in the queue,
// so simpler coercions will be located earlier.
Class tupleTargetType = tuple.getTargetType();
if (targetType.isAssignableFrom(tupleTargetType)) {
return tuple.getCoercion();
}
// So .. this tuple doesn't get us directly to the target type.
// However, it *may* get us part of the way. Each of these
// represents a coercion from the source type to an intermediate type.
// Now we're going to look for conversions from the intermediate type
// to some other type.
queueIntermediates(sourceType, targetType, tuple, consideredTuples, queue);
}
throw new CoercionNotFoundException(String.format("Could not find a coercion from type %s to type %s.", sourceType.getName(), targetType.getName()), buildCoercionCatalog(), sourceType, targetType);
}
use of org.apache.tapestry5.ioc.annotations.Value in project tapestry-5 by apache.
the class AjaxComponentInstanceEventResultProcessor method processResultValue.
public void processResultValue(Component value) throws IOException {
ComponentResources resources = value.getComponentResources();
boolean isPage = value == resources.getPage();
String pageName = resources.getPageName();
if (isPage) {
// This will ultimately send a JSON response to redirect to the page
masterProcessor.processResultValue(pageName);
return;
}
// Otherwise, a component within a page. Components are transformed to implement RenderCommand, but if we just
// pass the component itself to the master processor, we'll get in a loop, so we instead
// pass the ComponentPageElement (which implements RenderCommand as well).
Page page = cache.get(pageName);
String nestedId = resources.getNestedId();
RenderCommand command = page.getComponentElementByNestedId(nestedId);
masterProcessor.processResultValue(command);
}
use of org.apache.tapestry5.ioc.annotations.Value in project tapestry-5 by apache.
the class DynamicTemplateSaxParser method element.
private DynamicTemplateElement element() {
String elementURI = tokenStream.getNamespaceURI();
String elementName = tokenStream.getLocalName();
String blockId = null;
int count = tokenStream.getAttributeCount();
List<DynamicTemplateAttribute> attributes = CollectionFactory.newList();
Location location = getLocation();
for (int i = 0; i < count; i++) {
QName qname = tokenStream.getAttributeName(i);
// The name will be blank for an xmlns: attribute
String localName = qname.getLocalPart();
if (InternalUtils.isBlank(localName))
continue;
String uri = qname.getNamespaceURI();
String value = tokenStream.getAttributeValue(i);
if (localName.equals("id")) {
Matcher matcher = PARAM_ID_PATTERN.matcher(value);
if (matcher.matches()) {
blockId = matcher.group(1);
continue;
}
}
Mapper<DynamicDelegate, String> attributeValueExtractor = createCompositeExtractorFromText(value, location);
attributes.add(new DynamicTemplateAttribute(uri, localName, attributeValueExtractor));
}
if (blockId != null)
return block(blockId);
List<DynamicTemplateElement> body = CollectionFactory.newList();
boolean atEnd = false;
while (!atEnd) {
switch(tokenStream.next()) {
case START_ELEMENT:
// Recurse into this new element
body.add(element());
break;
case END_ELEMENT:
body.add(END);
atEnd = true;
break;
default:
addTextContent(body);
}
}
return createElementWriterElement(elementURI, elementName, attributes, body);
}
use of org.apache.tapestry5.ioc.annotations.Value in project tapestry-5 by apache.
the class OutputRawTest method value_is_non_blank.
@Test
public void value_is_non_blank() {
String value = " ";
MarkupWriter writer = mockMarkupWriter();
writer.writeRaw(value);
replay();
OutputRaw component = new OutputRaw();
component.setValue(value);
assertFalse(component.beginRender(writer));
verify();
}
Aggregations