Search in sources :

Example 16 with Location

use of org.apache.tapestry5.commons.Location in project tapestry-5 by apache.

the class PropBindingFactoryTest method unknown_property.

@Test
public void unknown_property() {
    TargetBean bean = new TargetBean();
    ComponentResources resources = mockComponentResources();
    Location l = mockLocation();
    train_getComponent(resources, bean);
    replay();
    try {
        factory.newBinding("test binding", resources, null, "missingProperty", l);
        unreachable();
    } catch (RuntimeException ex) {
        assertMessageContains(ex, "Class org.apache.tapestry5.internal.bindings.TargetBean does not contain a property", "\'missingProperty\'");
    }
    verify();
}
Also used : ComponentResources(org.apache.tapestry5.ComponentResources) Location(org.apache.tapestry5.commons.Location) Test(org.testng.annotations.Test)

Example 17 with Location

use of org.apache.tapestry5.commons.Location 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();
}
Also used : ComponentResources(org.apache.tapestry5.ComponentResources) Location(org.apache.tapestry5.commons.Location) Test(org.testng.annotations.Test)

Example 18 with Location

use of org.apache.tapestry5.commons.Location in project tapestry-5 by apache.

the class PlasticProxyFactoryImpl method getMemberLocation.

public Location getMemberLocation(Member member, String methodName, String memberTypeDesc, ObjectCreator<String> textDescriptionCreator) {
    String className = member.getDeclaringClass().getName();
    String key = className + ":" + methodName + ":" + memberTypeDesc;
    Location location = memberToLocation.get(key);
    if (location == null) {
        location = constructMemberLocation(member, methodName, memberTypeDesc, textDescriptionCreator.createObject());
        memberToLocation.put(key, location);
    }
    return location;
}
Also used : StringLocation(org.apache.tapestry5.commons.internal.services.StringLocation) Location(org.apache.tapestry5.commons.Location)

Example 19 with Location

use of org.apache.tapestry5.commons.Location in project tapestry-5 by apache.

the class BindingSourceImpl method newBinding.

public Binding newBinding(String description, ComponentResources container, ComponentResources component, String defaultPrefix, String expression, Location location) {
    assert InternalUtils.isNonBlank(description);
    assert container != null;
    assert InternalUtils.isNonBlank(defaultPrefix);
    assert component != null;
    // TAP5-845: The expression may be the empty string. This is ok, if it's compatible with
    // the default prefix (the empty string is not a valid property expression, but is valid
    // as a literal string, perhaps as an informal parameter).
    // Location might be null
    String subexpression = expression;
    int colonx = expression.indexOf(':');
    BindingFactory factory = null;
    if (colonx > 0) {
        String prefix = expression.substring(0, colonx);
        factory = factories.get(prefix);
        if (factory != null)
            subexpression = expression.substring(colonx + 1);
    }
    if (factory == null)
        factory = factories.get(defaultPrefix);
    try {
        return factory.newBinding(interner.intern(description), container, component, subexpression, location);
    } catch (Exception ex) {
        throw new TapestryException(String.format("Could not convert '%s' into a component parameter binding: %s", expression, ExceptionUtils.toMessage(ex)), location, ex);
    }
}
Also used : TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException) BindingFactory(org.apache.tapestry5.services.BindingFactory)

Example 20 with Location

use of org.apache.tapestry5.commons.Location 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);
}
Also used : Matcher(java.util.regex.Matcher) QName(javax.xml.namespace.QName) DynamicDelegate(org.apache.tapestry5.services.dynamic.DynamicDelegate) Location(org.apache.tapestry5.commons.Location)

Aggregations

Location (org.apache.tapestry5.commons.Location)51 Test (org.testng.annotations.Test)41 ComponentResources (org.apache.tapestry5.ComponentResources)33 Binding (org.apache.tapestry5.Binding)25 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)21 BindingFactory (org.apache.tapestry5.services.BindingFactory)10 BindingSource (org.apache.tapestry5.services.BindingSource)6 Resource (org.apache.tapestry5.commons.Resource)4 UnknownValueException (org.apache.tapestry5.commons.util.UnknownValueException)4 Component (org.apache.tapestry5.runtime.Component)4 MutableEmbeddedComponentModel (org.apache.tapestry5.model.MutableEmbeddedComponentModel)3 Environment (org.apache.tapestry5.services.Environment)3 Logger (org.slf4j.Logger)3 Matcher (java.util.regex.Matcher)2 QName (javax.xml.namespace.QName)2 MarkupWriter (org.apache.tapestry5.MarkupWriter)2 PropertyOverrides (org.apache.tapestry5.PropertyOverrides)2 PropertyConduit (org.apache.tapestry5.beanmodel.PropertyConduit)2 PropertyModel (org.apache.tapestry5.beanmodel.PropertyModel)2 Messages (org.apache.tapestry5.commons.Messages)2