Package org.apache.tapestry5.annotations

Examples of org.apache.tapestry5.annotations.Cached


    @SuppressWarnings("unchecked")
    @Test
    public void validator_with_constraint() throws Exception
    {
        ValidationMessagesSource messagesSource = mockValidationMessagesSource();
        Validator validator = mockValidator();
        TypeCoercer coercer = mockTypeCoercer();
        FieldComponent field = newFieldComponent();
        Messages messages = mockMessages();
        MessageFormatter formatter = mockMessageFormatter();
        Object inputValue = new Object();
        ComponentResources resources = mockComponentResources();
        Messages containerMessages = mockMessages();
        Integer five = 5;
        FormSupport fs = mockFormSupport();

        Map<String, Validator> map = singletonMap("minLength", validator);

        train_getConstraintType(validator, Integer.class);

        train_getFormValidationId(fs, "myform");

        train_coerce(coercer, "5", Integer.class, five);

        train_getComponentResources(field, resources);
        train_getId(resources, "fred");
        train_getContainerMessages(resources, containerMessages);
        train_contains(containerMessages, "myform-fred-minLength-message", false);
        train_contains(containerMessages, "fred-minLength-message", false);

        train_getLocale(resources, Locale.FRENCH);

        train_getValidationMessages(messagesSource, Locale.FRENCH, messages);

        train_getMessageKey(validator, "key");
        train_getMessageFormatter(messages, "key", formatter);

        train_isRequired(validator, false);
        train_getValueType(validator, Object.class);
        validator.validate(field, five, formatter, inputValue);

        replay();

        FieldValidatorSource source = new FieldValidatorSourceImpl(messagesSource, coercer, fs, map, null);
View Full Code Here


                // Each instance will get a new PerThreadValue
                return perThreadManager.createValue();
            }
        });

        Cached annotation = method.getAnnotation(Cached.class);

        MethodResultCacheFactory factory = createFactory(plasticClass, annotation.watch(), method);

        MethodAdvice advice = createAdvice(cacheField, factory);

        method.addAdvice(advice);
    }
View Full Code Here

        // between different instances of the same component within or across pages). This
        // name can't be calculated until page instantiation time.

        FieldAccess fieldAccess = createPerThreadValueField(transformation, method);

        Cached annotation = method.getAnnotation(Cached.class);

        MethodResultCacheFactory factory = createFactory(transformation, annotation.watch(), method);

        ComponentMethodAdvice advice = createAdvice(fieldAccess, factory);

        method.addAdvice(advice);
    }
View Full Code Here

                // Each instance will get a new PerThreadValue
                return perThreadManager.createValue();
            }
        });

        Cached annotation = method.getAnnotation(Cached.class);

        MethodResultCacheFactory factory = createFactory(plasticClass, annotation.watch(), method);

        MethodAdvice advice = createAdvice(cacheField, factory);

        method.addAdvice(advice);
    }
View Full Code Here

            // add a property to store whether or not the method has been called
            String fieldName = transformation.addField(PRIVATE, method.getReturnType(), propertyName);
            String calledField = transformation.addField(PRIVATE, "boolean", fieldName + "$called");

            Cached once = transformation.getMethodAnnotation(method, Cached.class);
            String bindingField = null;
            String bindingValueField = null;
            boolean watching = once.watch().length() > 0;

            if (watching)
            {
                // add fields to store the binding and the value
                bindingField = transformation.addField(PRIVATE, Binding.class.getCanonicalName(),
                                                       fieldName + "$binding");
                bindingValueField = transformation.addField(PRIVATE, "java.lang.Object", fieldName + "$bindingValue");

                String bindingSourceField = transformation.addInjectedField(BindingSource.class,
                                                                            fieldName + "$bindingsource",
                                                                            bindingSource);

                String body = String.format("%s = %s.newBinding(\"Watch expression\", %s, \"%s\", \"%s\");",
                                            bindingField,
                                            bindingSourceField,
                                            transformation.getResourcesFieldName(),
                                            BindingConstants.PROP,
                                            once.watch());

                transformation.extendMethod(TransformConstants.CONTAINING_PAGE_DID_LOAD_SIGNATURE, body);
            }

            BodyBuilder b = new BodyBuilder();
View Full Code Here

                {
                    setupRequestFromLink(link);
                    continue;
                }

                Document result = response.getRenderedDocument();

                if (result == null)
                    throw new RuntimeException(String.format("Render of page '%s' did not result in a Document.",
                            pageName));
View Full Code Here

                {
                    setupRequestFromLink(link);
                    continue;
                }

                Document result = response.getRenderedDocument();

                if (result == null)
                    throw new RuntimeException(String.format("Render request '%s' did not result in a Document.",
                            request.getPath()));
View Full Code Here

    {
        assert submitButton != null;

        assertIsSubmit(submitButton);

        Element form = getFormAncestor(submitButton);

        request.clear().setPath(stripContextFromPath(extractNonBlank(form, "action")));

        pushFieldValuesIntoRequest(form);
View Full Code Here

        return findAncestor(element, "form");
    }

    private Element findAncestor(Element element, String ancestorName)
    {
        Element e = element;

        while (e != null)
        {
            if (e.getName().equalsIgnoreCase(ancestorName))
                return e;

            e = e.getContainer();
        }

        throw new RuntimeException(String.format("Could not locate an ancestor element of type '%s'.", ancestorName));

    }
View Full Code Here

        }
    }

    private void pushFieldValuesIntoRequest(Element form)
    {
        Visitor visitor = new Visitor()
        {
            public void visit(Element element)
            {
                if (InternalUtils.isNonBlank(element.getAttribute("disabled")))
                    return;
View Full Code Here

TOP

Related Classes of org.apache.tapestry5.annotations.Cached

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.