Package org.apache.tapestry5.annotations

Examples of org.apache.tapestry5.annotations.PageActivationContext


    @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 transformField(ClassTransformation transformation, MutableComponentModel model, TransformField field)
    {
        PageActivationContext annotation = field.getAnnotation(PageActivationContext.class);

        FieldAccess access = field.getAccess();

        if (annotation.activate())
        {
            transformation.addComponentEventHandler(EventConstants.ACTIVATE, 1,
                    "PageActivationContextWorker activate event handler",
                    createActivationHandler(field.getType(), access));
        }

        if (annotation.passivate())
        {
            transformation.addComponentEventHandler(EventConstants.PASSIVATE, 0,
                    "PageActivationContextWorker passivate event handler", createPassivateHandler(access));
        }
View Full Code Here

        }
    }

    private void transformField(TransformationSupport support, PlasticField field)
    {
        PageActivationContext annotation = field.getAnnotation(PageActivationContext.class);

        FieldHandle handle = field.getHandle();

        if (annotation.activate())
        {
            support.addEventHandler(EventConstants.ACTIVATE, 1,
                    "PageActivationContextWorker activate event handler",
                    createActivationHandler(field.getTypeName(), handle));
        }

        if (annotation.passivate())
        {
            support.addEventHandler(EventConstants.PASSIVATE, 0,
                    "PageActivationContextWorker passivate event handler", createPassivateHandler(handle));
        }
View Full Code Here

        List<PlasticField> sortedFields = CollectionFactory.newList(fields);
        Collections.sort(sortedFields, INDEX_COMPARATOR);
        validateSortedFields(sortedFields);

        PlasticField firstField = sortedFields.get(0);
        PageActivationContext firstAnnotation = firstField.getAnnotation(PageActivationContext.class);

        // these arrays reduce memory usage and allow the PlasticField instances to be garbage collected
        FieldHandle[] handles = new FieldHandle[sortedFields.size()];
        String[] typeNames = new String[sortedFields.size()];

        int i = 0;
        for (PlasticField field : sortedFields) {
            handles[i] = field.getHandle();
            typeNames[i] = field.getTypeName();
            ++i;
        }

        if (firstAnnotation.activate())
        {
            support.addEventHandler(EventConstants.ACTIVATE, 1,
                    "PageActivationContextWorker activate event handler", createActivationHandler(handles, typeNames));
        }

        if (firstAnnotation.passivate())
        {
            support.addEventHandler(EventConstants.PASSIVATE, 0,
                    "PageActivationContextWorker passivate event handler", createPassivateHandler(handles));
        }
View Full Code Here

        Set<Boolean> activates = CollectionFactory.newSet();
        Set<Boolean> passivates = CollectionFactory.newSet();

        for (int i = 0; i < sortedFields.size(); ++i) {
            PlasticField field = sortedFields.get(i);
            PageActivationContext annotation = field.getAnnotation(PageActivationContext.class);
            expectedIndexes.add(i);
            actualIndexes.add(annotation.index());
            activates.add(annotation.activate());
            passivates.add(annotation.passivate());
        }

        List<String> errors = CollectionFactory.newList();
        if (!expectedIndexes.equals(actualIndexes)) {
            errors.add(String.format("Index values must start at 0 and increment by 1 (expected [%s], found [%s])",
View Full Code Here

        }
    }

    private void transformField(ClassTransformation transformation, MutableComponentModel model, TransformField field)
    {
        PageActivationContext annotation = field.getAnnotation(PageActivationContext.class);

        FieldAccess access = field.getAccess();

        if (annotation.activate())
        {
            transformation.addComponentEventHandler(EventConstants.ACTIVATE, 1,
                    "PageActivationContextWorker activate event handler",
                    createActivationHandler(field.getType(), access));
        }

        if (annotation.passivate())
        {
            transformation.addComponentEventHandler(EventConstants.PASSIVATE, 0,
                    "PageActivationContextWorker passivate event handler", createPassivateHandler(access));
        }
View Full Code Here

        if (fields.size() > 1)
            throw new RuntimeException(TransformMessages.illegalNumberOfPageActivationContextHandlers(fields));

        for (String fieldName : fields)
        {
            PageActivationContext annotation = transformation.getFieldAnnotation(fieldName,
                                                                                 PageActivationContext.class);

            String fieldType = transformation.getFieldType(fieldName);

            if (annotation.activate())
            {
                TransformMethodSignature activate
                        = new TransformMethodSignature(Modifier.PROTECTED | Modifier.FINAL, "void",
                                                       "onActivate",
                                                       new String[] { fieldType }, null);
                transformation.addTransformedMethod(activate, fieldName + " = $1;");
            }

            if (annotation.passivate())
            {
                TransformMethodSignature passivate
                        = new TransformMethodSignature(Modifier.PROTECTED | Modifier.FINAL, "java.lang.Object",
                                                       "onPassivate",
                                                       null, null);
View Full Code Here

        }
    }

    private void transformField(TransformationSupport support, PlasticField field)
    {
        PageActivationContext annotation = field.getAnnotation(PageActivationContext.class);

        FieldHandle handle = field.getHandle();

        if (annotation.activate())
        {
            support.addEventHandler(EventConstants.ACTIVATE, 1,
                    "PageActivationContextWorker activate event handler",
                    createActivationHandler(field.getTypeName(), handle));
        }

        if (annotation.passivate())
        {
            support.addEventHandler(EventConstants.PASSIVATE, 0,
                    "PageActivationContextWorker passivate event handler", createPassivateHandler(handle));
        }
View Full Code Here

    @Test
    public void activate_dafault_passivate_false()
    {
        ClassTransformation ct = mockClassTransformation();
        MutableComponentModel model = mockMutableComponentModel();
        PageActivationContext annotation = newMock(PageActivationContext.class);
        ComponentClassTransformWorker worker = new PageActivationContextWorker();

        train_findFieldsWithAnnotation(ct, PageActivationContext.class,
                                       "myfield");
        train_getFieldAnnotation(ct, "myfield", PageActivationContext.class,
                                 annotation);
        train_getFieldType(ct, "myfield", CLASS_NAME);
        expect(annotation.activate()).andReturn(true);

        TransformMethodSignature sig = new TransformMethodSignature(
                Modifier.PROTECTED | Modifier.FINAL, "void", "onActivate",
                new String[]{CLASS_NAME}, null);

        ct.addTransformedMethod(sig, "myfield = $1;");

        expect(annotation.passivate()).andReturn(false);

        replay();

        worker.transform(ct, model);
View Full Code Here

    @Test
    public void activate_false_passivate_default()
    {
        ClassTransformation ct = mockClassTransformation();
        MutableComponentModel model = mockMutableComponentModel();
        PageActivationContext annotation = newMock(PageActivationContext.class);
        ComponentClassTransformWorker worker = new PageActivationContextWorker();

        train_findFieldsWithAnnotation(ct, PageActivationContext.class,
                                       "myfield");
        train_getFieldAnnotation(ct, "myfield", PageActivationContext.class,
                                 annotation);
        train_getFieldType(ct, "myfield", CLASS_NAME);
        expect(annotation.activate()).andReturn(false);

        expect(annotation.passivate()).andReturn(true);

        TransformMethodSignature sig = new TransformMethodSignature(
                Modifier.PROTECTED | Modifier.FINAL, "java.lang.Object",
                "onPassivate", null, null);
View Full Code Here

TOP

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

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.