Package org.apache.tapestry5.annotations

Examples of org.apache.tapestry5.annotations.Environmental


    @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


        }
    }

    private void transform(final String componentClassName, PlasticField field)
    {
        Environmental annotation = field.getAnnotation(Environmental.class);

        field.claim(annotation);

        final String fieldName = field.getName();

        final Class fieldType = classCache.forName(field.getTypeName());

        final boolean required = annotation.value();

        ComputedValue<FieldConduit<Object>> provider = new ComputedValue<FieldConduit<Object>>()
        {
            public FieldConduit<Object> get(InstanceContext context)
            {
View Full Code Here

        }
    }

    private void transform(TransformField field)
    {
        Environmental annotation = field.getAnnotation(Environmental.class);

        field.claim(annotation);

        final String fieldName = field.getName();

        final Class fieldType = classCache.forName(field.getType());

        final boolean required = annotation.value();

        ComponentValueProvider<FieldValueConduit> provider = new ComponentValueProvider<FieldValueConduit>()
        {
            public FieldValueConduit get(ComponentResources resources)
            {
View Full Code Here

                "environment",
                environment);

        for (String name : names)
        {
            Environmental annotation = transformation.getFieldAnnotation(name, Environmental.class);

            transformation.claimField(name, annotation);

            String typeName = transformation.getFieldType(name);

            // TODO: Check for primitives

            // TAP5-417: Calls to javassist.runtime.Desc.getType() are showing up as method hot spots.

            Class type = null;

            try
            {
                type = classLoader.loadClass(typeName);
            }
            catch (ClassNotFoundException ex)
            {
                throw new RuntimeException(ex);
            }

            // TAP5-417: Changed the code to use EnvironmentalAccess, which encapsulates
            // efficient caching.

            String injectedTypeFieldName = transformation.addInjectedField(Class.class, "type", type);

            // First we need (at page attach) to acquire the closure for the type.

            String accessFieldName = transformation.addField(Modifier.PRIVATE, EnvironmentalAccess.class.getName(),
                                                             name + "_access");

            String attachBody = String.format("%s = %s.getAccess(%s);",
                                              accessFieldName, envField, injectedTypeFieldName);

            transformation.extendMethod(TransformConstants.CONTAINING_PAGE_DID_ATTACH_SIGNATURE, attachBody);

            // Clear the closure field when the page detaches.  We'll get a new one when we next attach.

            transformation.extendMethod(TransformConstants.CONTAINING_PAGE_DID_DETACH_SIGNATURE,
                                        accessFieldName + " = null;");

            // Now build a read method that invokes peek() or peekRequired() on the closure. The closure
            // is responsible for safe caching of the environmental value.

            String methodName = transformation.newMemberName("environment_read", name);

            TransformMethodSignature sig = new TransformMethodSignature(Modifier.PRIVATE, typeName, methodName, null,
                                                                        null);

            String body = String.format(
                    "return ($r) %s.%s();",
                    accessFieldName,
                    annotation.value() ? "peekRequired" : "peek");

            transformation.addMethod(sig, body);

            transformation.replaceReadAccess(name, methodName);
            transformation.makeReadOnly(name);
View Full Code Here

                "environment",
                environment);

        for (String name : names)
        {
            Environmental annotation = transformation.getFieldAnnotation(name, Environmental.class);

            String type = transformation.getFieldType(name);

            // TODO: Check for primitives

            // Caching might be good for efficiency at some point.

            String methodName = transformation.newMemberName("environment_read", name);

            TransformMethodSignature sig = new TransformMethodSignature(Modifier.PRIVATE, type, methodName, null,
                                                                        null);

            String body = String.format(
                    "return ($r) %s.%s($type);",
                    envField,
                    annotation.value() ? "peekRequired" : "peek");

            transformation.addMethod(sig, body);

            transformation.replaceReadAccess(name, methodName);
            transformation.makeReadOnly(name);
View Full Code Here

                "environment",
                environment);

        for (String name : names)
        {
            Environmental annotation = transformation.getFieldAnnotation(name, Environmental.class);
           
            transformation.claimField(name, annotation);

            String type = transformation.getFieldType(name);

            // TODO: Check for primitives

            // Caching might be good for efficiency at some point.

            String methodName = transformation.newMemberName("environment_read", name);

            TransformMethodSignature sig = new TransformMethodSignature(Modifier.PRIVATE, type, methodName, null,
                                                                        null);

            String body = String.format(
                    "return ($r) %s.%s($type);",
                    envField,
                    annotation.value() ? "peekRequired" : "peek");

            transformation.addMethod(sig, body);

            transformation.replaceReadAccess(name, methodName);
            transformation.makeReadOnly(name);
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

TOP

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

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.