Search in sources :

Example 1 with BindingSource

use of org.apache.tapestry5.services.BindingSource 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();
}
Also used : BindingSource(org.apache.tapestry5.services.BindingSource) ClassPropertyAdapter(org.apache.tapestry5.commons.services.ClassPropertyAdapter) Component(org.apache.tapestry5.runtime.Component) ComponentResources(org.apache.tapestry5.ComponentResources) PropertyAccess(org.apache.tapestry5.commons.services.PropertyAccess) ComponentDefaultProvider(org.apache.tapestry5.services.ComponentDefaultProvider) Test(org.testng.annotations.Test)

Example 2 with BindingSource

use of org.apache.tapestry5.services.BindingSource in project tapestry-5 by apache.

the class BindingSourceImplTest method expression_has_no_prefix.

@Test
public void expression_has_no_prefix() {
    BindingFactory factory = mockBindingFactory();
    Binding binding = mockBinding();
    ComponentResources container = mockComponentResources();
    ComponentResources component = mockComponentResources();
    Location l = mockLocation();
    String defaultPrefix = "def";
    String description = "descrip";
    String expression = "full expression";
    train_newBinding(factory, description, container, component, expression, l, binding);
    replay();
    Map<String, BindingFactory> map = newMap();
    map.put(defaultPrefix, factory);
    BindingSource source = new BindingSourceImpl(map, interner);
    Binding actual = source.newBinding(description, container, component, defaultPrefix, expression, l);
    assertSame(actual, binding);
    verify();
}
Also used : Binding(org.apache.tapestry5.Binding) BindingSource(org.apache.tapestry5.services.BindingSource) BindingFactory(org.apache.tapestry5.services.BindingFactory) ComponentResources(org.apache.tapestry5.ComponentResources) Location(org.apache.tapestry5.commons.Location) Test(org.testng.annotations.Test)

Example 3 with BindingSource

use of org.apache.tapestry5.services.BindingSource in project tapestry-5 by apache.

the class BindingSourceImplTest method expression_prefix_not_in_configuration.

@Test
public void expression_prefix_not_in_configuration() {
    BindingFactory factory = mockBindingFactory();
    Binding binding = mockBinding();
    ComponentResources container = mockComponentResources();
    ComponentResources component = mockComponentResources();
    Location l = mockLocation();
    String defaultPrefix = "def";
    String description = "descrip";
    String expression = "javascript:not-a-known-prefix";
    train_newBinding(factory, description, container, component, expression, l, binding);
    replay();
    Map<String, BindingFactory> map = newMap();
    map.put(defaultPrefix, factory);
    BindingSource source = new BindingSourceImpl(map, interner);
    Binding actual = source.newBinding(description, container, component, defaultPrefix, expression, l);
    assertSame(actual, binding);
    verify();
}
Also used : Binding(org.apache.tapestry5.Binding) BindingSource(org.apache.tapestry5.services.BindingSource) BindingFactory(org.apache.tapestry5.services.BindingFactory) ComponentResources(org.apache.tapestry5.ComponentResources) Location(org.apache.tapestry5.commons.Location) Test(org.testng.annotations.Test)

Example 4 with BindingSource

use of org.apache.tapestry5.services.BindingSource 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);
            }
        }
    };
}
Also used : Binding(org.apache.tapestry5.Binding) Mapper(org.apache.tapestry5.func.Mapper) DynamicDelegate(org.apache.tapestry5.services.dynamic.DynamicDelegate) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException)

Example 5 with BindingSource

use of org.apache.tapestry5.services.BindingSource in project tapestry-5 by apache.

the class DynamicTemplateSaxParser method createCompositeExtractorFromText.

private Mapper<DynamicDelegate, String> createCompositeExtractorFromText(String text, Location location) {
    Matcher matcher = EXPANSION_PATTERN.matcher(text);
    List<Mapper<DynamicDelegate, String>> extractors = CollectionFactory.newList();
    int startx = 0;
    while (matcher.find()) {
        int matchStart = matcher.start();
        if (matchStart != startx) {
            String prefix = text.substring(startx, matchStart);
            extractors.add(createTextExtractor(prefix));
        }
        // Group 1 includes the real text of the expansion, with whitespace
        // around the
        // expression (but inside the curly braces) excluded.
        String expression = matcher.group(1);
        extractors.add(createExpansionExtractor(expression, location, bindingSource));
        startx = matcher.end();
    }
    if (startx < text.length())
        extractors.add(createTextExtractor(text.substring(startx, text.length())));
    if (extractors.size() == 1)
        return extractors.get(0);
    return creatCompositeExtractor(extractors);
}
Also used : Mapper(org.apache.tapestry5.func.Mapper) Matcher(java.util.regex.Matcher)

Aggregations

BindingSource (org.apache.tapestry5.services.BindingSource)8 Test (org.testng.annotations.Test)8 ComponentResources (org.apache.tapestry5.ComponentResources)7 Location (org.apache.tapestry5.commons.Location)6 Binding (org.apache.tapestry5.Binding)5 BindingFactory (org.apache.tapestry5.services.BindingFactory)4 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)3 ClassPropertyAdapter (org.apache.tapestry5.commons.services.ClassPropertyAdapter)2 PropertyAccess (org.apache.tapestry5.commons.services.PropertyAccess)2 TypeCoercer (org.apache.tapestry5.commons.services.TypeCoercer)2 Mapper (org.apache.tapestry5.func.Mapper)2 AttributeToken (org.apache.tapestry5.internal.parser.AttributeToken)2 Component (org.apache.tapestry5.runtime.Component)2 ComponentDefaultProvider (org.apache.tapestry5.services.ComponentDefaultProvider)2 Matcher (java.util.regex.Matcher)1 MarkupWriter (org.apache.tapestry5.MarkupWriter)1 PropertyAdapter (org.apache.tapestry5.commons.services.PropertyAdapter)1 RenderCommand (org.apache.tapestry5.runtime.RenderCommand)1 RenderQueue (org.apache.tapestry5.runtime.RenderQueue)1 DynamicDelegate (org.apache.tapestry5.services.dynamic.DynamicDelegate)1