Search in sources :

Example 11 with ComponentModel

use of org.apache.tapestry5.model.ComponentModel in project tapestry-5 by apache.

the class PersistentFieldManagerImplTest method strategy_name_is_case_insensitive.

public void strategy_name_is_case_insensitive() {
    String pageName = "foo.Bar";
    String nestedId = "nested";
    String fieldName = "field";
    String strategyName = "FOO";
    ComponentResources resources = mockComponentResources();
    ComponentModel model = mockComponentModel();
    PersistentFieldStrategy strat = newPersistentFieldStrategy();
    Object value = new Object();
    Map<String, PersistentFieldStrategy> strategies = newMap();
    strategies.put("foo", strat);
    train_getComponentModel(resources, model);
    train_getFieldPersistenceStrategy(model, fieldName, strategyName);
    train_getNestedId(resources, nestedId);
    strat.postChange(pageName, nestedId, fieldName, value);
    replay();
    PersistentFieldManager manager = new PersistentFieldManagerImpl(null, strategies);
    manager.postChange(pageName, resources, fieldName, value);
    verify();
}
Also used : PersistentFieldStrategy(org.apache.tapestry5.services.PersistentFieldStrategy) ComponentModel(org.apache.tapestry5.model.ComponentModel) ComponentResources(org.apache.tapestry5.ComponentResources)

Example 12 with ComponentModel

use of org.apache.tapestry5.model.ComponentModel in project tapestry-5 by apache.

the class PersistentFieldManagerImplTest method post_change_with_unknown_strategy.

@Test
public void post_change_with_unknown_strategy() {
    String fieldName = "field";
    PersistentFieldStrategy strat1 = newPersistentFieldStrategy();
    PersistentFieldStrategy strat2 = newPersistentFieldStrategy();
    ComponentResources resources = mockComponentResources();
    ComponentModel model = mockComponentModel();
    Map<String, PersistentFieldStrategy> strategies = newMap();
    strategies.put("foo", strat1);
    strategies.put("bar", strat2);
    train_getComponentModel(resources, model);
    train_getFieldPersistenceStrategy(model, fieldName, "braveheart");
    replay();
    PersistentFieldManager manager = new PersistentFieldManagerImpl(null, strategies);
    try {
        manager.postChange("foo.Bar", resources, fieldName, null);
        unreachable();
    } catch (UnknownValueException ex) {
        assertEquals(ex.getMessage(), "'braveheart' is not a defined persistent strategy.");
        assertListsEquals(ex.getAvailableValues().getValues(), "bar", "foo");
    }
    verify();
}
Also used : PersistentFieldStrategy(org.apache.tapestry5.services.PersistentFieldStrategy) ComponentModel(org.apache.tapestry5.model.ComponentModel) UnknownValueException(org.apache.tapestry5.commons.util.UnknownValueException) ComponentResources(org.apache.tapestry5.ComponentResources) Test(org.testng.annotations.Test)

Example 13 with ComponentModel

use of org.apache.tapestry5.model.ComponentModel in project tapestry-5 by apache.

the class PageActivationContextCollectorImplTest method page_with_no_context.

@Test
public void page_with_no_context() {
    String pageName = "mypage";
    ComponentModel model = mockComponentModel();
    ComponentModelSource modelSource = mockComponentModelSource();
    RequestPageCache pageCache = mockRequestPageCache();
    Page page = mockPage();
    ComponentPageElement element = mockComponentPageElement();
    expect(modelSource.getPageModel(pageName)).andReturn(model);
    expect(model.handlesEvent(EventConstants.PASSIVATE)).andReturn(true);
    train_get(pageCache, pageName, page);
    train_getRootElement(page, element);
    expect(element.triggerEvent(EasyMock.eq(EventConstants.PASSIVATE), (Object[]) EasyMock.isNull(), EasyMock.isA(ComponentEventCallback.class))).andReturn(false);
    replay();
    PageActivationContextCollector collector = new PageActivationContextCollectorImpl(coercer, pageCache, modelSource);
    Object[] actual = collector.collectPageActivationContext(pageName);
    assertEquals(actual.length, 0);
}
Also used : ComponentPageElement(org.apache.tapestry5.internal.structure.ComponentPageElement) ComponentModel(org.apache.tapestry5.model.ComponentModel) Page(org.apache.tapestry5.internal.structure.Page) ComponentEventCallback(org.apache.tapestry5.ComponentEventCallback) Test(org.testng.annotations.Test)

Example 14 with ComponentModel

use of org.apache.tapestry5.model.ComponentModel in project tapestry-5 by apache.

the class DefaultInjectionProvider method provideInjection.

public boolean provideInjection(final PlasticField field, ObjectLocator locator, MutableComponentModel componentModel) {
    Class fieldType = classCache.forName(field.getTypeName());
    Object injectionValue = masterObjectProvider.provide(fieldType, new AnnotationProvider() {

        public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
            return field.getAnnotation(annotationClass);
        }
    }, this.locator, false);
    if (injectionValue != null) {
        field.inject(injectionValue);
        return true;
    }
    return false;
}
Also used : AnnotationProvider(org.apache.tapestry5.commons.AnnotationProvider)

Example 15 with ComponentModel

use of org.apache.tapestry5.model.ComponentModel in project tapestry-5 by apache.

the class BindParameterWorker method identifyParameterName.

private String identifyParameterName(ComponentResources resources, String firstGuess, String... otherGuesses) {
    ComponentModel model = resources.getContainerResources().getComponentModel();
    List<String> guesses = CollectionFactory.newList();
    guesses.add(firstGuess);
    for (String name : otherGuesses) {
        guesses.add(name);
    }
    for (String name : guesses) {
        if (model.isFormalParameter(name))
            return name;
        if (isPublishedParameter(model, name))
            return name;
    }
    String message = String.format("Containing component %s does not contain a formal parameter or a published parameter %s %s.", model.getComponentClassName(), guesses.size() == 1 ? "matching" : "matching any of", InternalUtils.joinSorted(guesses));
    List<String> formalAndPublishedParameters = CollectionFactory.newList(model.getParameterNames());
    formalAndPublishedParameters.addAll(getPublishedParameters(model));
    throw new UnknownValueException(message, new AvailableValues("Formal and published parameters", formalAndPublishedParameters));
}
Also used : ComponentModel(org.apache.tapestry5.model.ComponentModel) MutableComponentModel(org.apache.tapestry5.model.MutableComponentModel) EmbeddedComponentModel(org.apache.tapestry5.model.EmbeddedComponentModel) UnknownValueException(org.apache.tapestry5.commons.util.UnknownValueException) AvailableValues(org.apache.tapestry5.commons.util.AvailableValues)

Aggregations

ComponentModel (org.apache.tapestry5.model.ComponentModel)64 Test (org.testng.annotations.Test)48 ComponentResources (org.apache.tapestry5.ComponentResources)16 ComponentEventCallback (org.apache.tapestry5.ComponentEventCallback)15 Logger (org.slf4j.Logger)14 ComponentEvent (org.apache.tapestry5.runtime.ComponentEvent)12 Instantiator (org.apache.tapestry5.internal.services.Instantiator)11 MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)11 Resource (org.apache.tapestry5.commons.Resource)10 InternalComponentResources (org.apache.tapestry5.internal.InternalComponentResources)10 Component (org.apache.tapestry5.runtime.Component)10 SymbolSource (org.apache.tapestry5.ioc.services.SymbolSource)9 EventContext (org.apache.tapestry5.EventContext)8 ClasspathResource (org.apache.tapestry5.ioc.internal.util.ClasspathResource)7 EmbeddedComponentModel (org.apache.tapestry5.model.EmbeddedComponentModel)7 ComponentTemplate (org.apache.tapestry5.internal.parser.ComponentTemplate)6 ComponentPageElementResources (org.apache.tapestry5.internal.structure.ComponentPageElementResources)6 ComponentResourceLocator (org.apache.tapestry5.services.pageload.ComponentResourceLocator)6 Messages (org.apache.tapestry5.commons.Messages)5 PersistentFieldStrategy (org.apache.tapestry5.services.PersistentFieldStrategy)5