Search in sources :

Example 1 with BindingFactory

use of org.apache.tapestry5.services.BindingFactory 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 2 with BindingFactory

use of org.apache.tapestry5.services.BindingFactory 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 3 with BindingFactory

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

the class BindingFactoryTest method symbol_binding.

@Test
public void symbol_binding() {
    ComponentResources res = mockInternalComponentResources();
    Location l = mockLocation();
    replay();
    BindingFactory factory = getService("SymbolBindingFactory", BindingFactory.class);
    Binding binding = factory.newBinding("Test binding", res, null, SymbolConstants.START_PAGE_NAME, l);
    assertEquals(binding.get(), "start");
    verify();
}
Also used : Binding(org.apache.tapestry5.Binding) ComponentResources(org.apache.tapestry5.ComponentResources) Location(org.apache.tapestry5.commons.Location) BindingFactory(org.apache.tapestry5.services.BindingFactory) Test(org.testng.annotations.Test)

Example 4 with BindingFactory

use of org.apache.tapestry5.services.BindingFactory 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 5 with BindingFactory

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

the class BindingFactoryTest method translate_binding.

@Test
public void translate_binding() {
    FieldTranslator translator = mockFieldTranslator();
    FieldTranslatorSource source = newMock(FieldTranslatorSource.class);
    ComponentResources resources = mockComponentResources();
    Location l = mockLocation();
    String description = "foo bar";
    String expression = "mock";
    expect(source.createTranslator(resources, expression)).andReturn(translator);
    replay();
    BindingFactory factory = new TranslateBindingFactory(source, new StringInternerImpl());
    Binding binding = factory.newBinding(description, resources, resources, expression, l);
    assertSame(binding.get(), translator);
    assertSame(InternalUtils.locationOf(binding), l);
    verify();
}
Also used : Binding(org.apache.tapestry5.Binding) StringInternerImpl(org.apache.tapestry5.commons.internal.services.StringInternerImpl) FieldTranslatorSource(org.apache.tapestry5.services.FieldTranslatorSource) FieldTranslator(org.apache.tapestry5.FieldTranslator) ComponentResources(org.apache.tapestry5.ComponentResources) Location(org.apache.tapestry5.commons.Location) BindingFactory(org.apache.tapestry5.services.BindingFactory) Test(org.testng.annotations.Test)

Aggregations

BindingFactory (org.apache.tapestry5.services.BindingFactory)10 ComponentResources (org.apache.tapestry5.ComponentResources)9 Location (org.apache.tapestry5.commons.Location)9 Test (org.testng.annotations.Test)9 Binding (org.apache.tapestry5.Binding)7 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)4 BindingSource (org.apache.tapestry5.services.BindingSource)4 FieldComponent (org.apache.tapestry5.root.FieldComponent)2 FieldValidatorSource (org.apache.tapestry5.services.FieldValidatorSource)2 FieldTranslator (org.apache.tapestry5.FieldTranslator)1 FieldValidator (org.apache.tapestry5.FieldValidator)1 StringInternerImpl (org.apache.tapestry5.commons.internal.services.StringInternerImpl)1 BlockBindingFactory (org.apache.tapestry5.internal.bindings.BlockBindingFactory)1 ComponentBindingFactory (org.apache.tapestry5.internal.bindings.ComponentBindingFactory)1 LiteralBindingFactory (org.apache.tapestry5.internal.bindings.LiteralBindingFactory)1 RenderVariableBindingFactory (org.apache.tapestry5.internal.bindings.RenderVariableBindingFactory)1 Component (org.apache.tapestry5.runtime.Component)1 FieldTranslatorSource (org.apache.tapestry5.services.FieldTranslatorSource)1