Search in sources :

Example 46 with Location

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

the class Form method executeStoredActions.

/**
 * Pulls the stored actions out of the request, converts them from MIME
 * stream back to object stream and then
 * objects, and executes them.
 */
private void executeStoredActions(boolean forFormCancel) {
    String[] values = request.getParameters(FORM_DATA);
    if (!request.getMethod().equals("POST") || values == null)
        throw new RuntimeException(messages.format("core-invalid-form-request", FORM_DATA));
    for (String clientEncodedActions : values) {
        if (InternalUtils.isBlank(clientEncodedActions))
            continue;
        logger.debug("Processing actions: {}", clientEncodedActions);
        ObjectInputStream ois = null;
        Component component = null;
        try {
            ois = clientDataEncoder.decodeClientData(clientEncodedActions);
            while (!eventCallback.isAborted()) {
                String componentId = ois.readUTF();
                boolean cancelAction = ois.readBoolean();
                ComponentAction action = (ComponentAction) ois.readObject();
                // based on whether the form was submitted or cancelled.
                if (forFormCancel != cancelAction) {
                    continue;
                }
                component = source.getComponent(componentId);
                logger.debug("Processing: {} {}", componentId, action);
                action.execute(component);
                component = null;
            }
        } catch (EOFException ex) {
        // Expected
        } catch (Exception ex) {
            Location location = component == null ? null : component.getComponentResources().getLocation();
            throw new TapestryException(ex.getMessage(), location, ex);
        } finally {
            InternalUtils.close(ois);
        }
    }
}
Also used : EOFException(java.io.EOFException) Component(org.apache.tapestry5.runtime.Component) IOException(java.io.IOException) EOFException(java.io.EOFException) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException) ObjectInputStream(java.io.ObjectInputStream) Location(org.apache.tapestry5.commons.Location)

Example 47 with Location

use of org.apache.tapestry5.commons.Location 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)

Example 48 with Location

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

the class BindingFactoryTest method literal_binding.

@Test
public void literal_binding() {
    ComponentResources res = mockInternalComponentResources();
    Location l = mockLocation();
    replay();
    BindingFactory factory = new LiteralBindingFactory();
    Binding b = factory.newBinding("test binding", res, null, "Tapestry5", l);
    assertSame(InternalUtils.locationOf(b), l);
    assertEquals(b.get(), "Tapestry5");
    assertTrue(b.isInvariant());
    assertSame(b.getBindingType(), String.class);
    try {
        b.set(null);
        unreachable();
    } catch (TapestryException ex) {
        assertSame(ex.getLocation(), l);
    }
    verify();
}
Also used : Binding(org.apache.tapestry5.Binding) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException) ComponentResources(org.apache.tapestry5.ComponentResources) Location(org.apache.tapestry5.commons.Location) BindingFactory(org.apache.tapestry5.services.BindingFactory) Test(org.testng.annotations.Test)

Example 49 with Location

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

the class PropBindingFactoryTest method property_path_with_explicit_method_in_preamble.

/**
 * The "preamble" are the non-terminal property or method names.
 */
@Test
public void property_path_with_explicit_method_in_preamble() {
    TargetBean bean = new TargetBean();
    ComponentResources resources = newComponentResources(bean);
    Location l = mockLocation();
    replay();
    Binding binding = factory.newBinding("test binding", resources, null, "stringHolderMethod().value", l);
    assertSame(binding.getBindingType(), String.class);
    bean.getStringHolder().setValue("first");
    assertEquals(binding.get(), "first");
    assertEquals(binding.toString(), "PropBinding[test binding foo.Bar:baz(stringHolderMethod().value)]");
    verify();
}
Also used : Binding(org.apache.tapestry5.Binding) ComponentResources(org.apache.tapestry5.ComponentResources) Location(org.apache.tapestry5.commons.Location) Test(org.testng.annotations.Test)

Example 50 with Location

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

the class PropBindingFactoryTest method special_prop_binding_values.

@Test(dataProvider = "values")
public void special_prop_binding_values(String expression, Object expected) {
    Location l = mockLocation();
    String description = "my description";
    ComponentResources resources = mockComponentResources();
    Component component = mockComponent();
    train_getComponent(resources, component);
    train_getCompleteId(resources, "Does.not.matter");
    replay();
    Binding binding = factory.newBinding(description, resources, null, expression, l);
    assertEquals(binding.get(), expected);
    // All of these are invariatns, even though they are generated from the PropertyConduit.
    assertTrue(binding.isInvariant());
    verify();
}
Also used : Binding(org.apache.tapestry5.Binding) Component(org.apache.tapestry5.runtime.Component) Location(org.apache.tapestry5.commons.Location) ComponentResources(org.apache.tapestry5.ComponentResources) Test(org.testng.annotations.Test)

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