Search in sources :

Example 16 with ComponentModel

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

the class BindParameterWorker method getEmbeddedComponentResourcesForPublishedParameter.

/**
 * Returns the {@link InternalComponentResources} of an embeddedComponent that contains the published parameter
 * publishedParameterName. This is basically a recursive search for published parameters.
 */
private InternalComponentResources getEmbeddedComponentResourcesForPublishedParameter(InternalComponentResources containerResources, String publishedParameterName) {
    List<InternalComponentResources> embeddedComponentResourcesList = CollectionFactory.newList();
    embeddedComponentResourcesList.add(containerResources);
    while (!embeddedComponentResourcesList.isEmpty()) {
        InternalComponentResources resources = embeddedComponentResourcesList.remove(0);
        ComponentModel containerComponentModel = resources.getComponentModel();
        for (String embeddedComponentId : containerComponentModel.getEmbeddedComponentIds()) {
            EmbeddedComponentModel embeddedComponentModel = containerComponentModel.getEmbeddedComponentModel(embeddedComponentId);
            InternalComponentResources embeddedComponentResources = (InternalComponentResources) resources.getEmbeddedComponent(embeddedComponentId).getComponentResources();
            /**
             * If the parameter is not a formal parameter, then the parameter must be a published parameter
             * of an embeddedComponent of the component we are currently examining.
             */
            if (embeddedComponentModel.getPublishedParameters().contains(publishedParameterName) && embeddedComponentResources.getComponentModel().isFormalParameter(publishedParameterName)) {
                return embeddedComponentResources;
            }
            embeddedComponentResourcesList.add(embeddedComponentResources);
        }
    }
    return null;
}
Also used : EmbeddedComponentModel(org.apache.tapestry5.model.EmbeddedComponentModel) InternalComponentResources(org.apache.tapestry5.internal.InternalComponentResources) ComponentModel(org.apache.tapestry5.model.ComponentModel) MutableComponentModel(org.apache.tapestry5.model.MutableComponentModel) EmbeddedComponentModel(org.apache.tapestry5.model.EmbeddedComponentModel)

Example 17 with ComponentModel

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

the class DefaultOpenApiDescriptionGenerator method processPageClass.

private void processPageClass(Page page, JSONObject paths, JSONArray tags) throws NoSuchMethodException {
    final Class<?> pageClass = page.getRootComponent().getClass();
    final String tagName = addPageTag(tags, pageClass);
    ComponentModel model = page.getRootComponent().getComponentResources().getComponentModel();
    JSONArray methodsAsJson = getMethodsAsJson(model);
    List<Method> methods = toMethods(methodsAsJson, pageClass);
    for (Method method : methods) {
        processMethod(method, pageClass, paths, tagName);
    }
}
Also used : ComponentModel(org.apache.tapestry5.model.ComponentModel) JSONArray(org.apache.tapestry5.json.JSONArray) Method(java.lang.reflect.Method)

Example 18 with ComponentModel

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

the class InternalComponentResourcesImplTest method add_page_lifecycle_listener.

@Test
public void add_page_lifecycle_listener() {
    Component component = mockComponent();
    Instantiator ins = mockInstantiator(component);
    ComponentModel model = mockComponentModel();
    ComponentPageElement element = mockComponentPageElement();
    Page page = mockPage();
    PageLifecycleListener listener = newMock(PageLifecycleListener.class);
    train_getModel(ins, model);
    page.addLifecycleListener(listener);
    replay();
    InternalComponentResources resources = new InternalComponentResourcesImpl(page, element, null, null, null, null, ins, false);
    resources.addPageLifecycleListener(listener);
    verify();
}
Also used : PageLifecycleListener(org.apache.tapestry5.runtime.PageLifecycleListener) InternalComponentResources(org.apache.tapestry5.internal.InternalComponentResources) ComponentModel(org.apache.tapestry5.model.ComponentModel) Instantiator(org.apache.tapestry5.internal.services.Instantiator) Component(org.apache.tapestry5.runtime.Component) Test(org.testng.annotations.Test)

Example 19 with ComponentModel

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

the class InternalComponentResourcesImplTest method post_render_cleanup_removes_all_variables.

@Test
public void post_render_cleanup_removes_all_variables() {
    Component component = mockComponent();
    Instantiator ins = mockInstantiator(component);
    ComponentModel model = mockComponentModel();
    train_getModel(ins, model);
    replay();
    InternalComponentResources resources = new InternalComponentResourcesImpl(null, null, null, elementResources, "Foo.bar", null, ins, false);
    resources.storeRenderVariable("fred", "FRED");
    resources.storeRenderVariable("barney", "BARNEY");
    resources.postRenderCleanup();
    try {
        resources.getRenderVariable("fred");
        unreachable();
    } catch (IllegalArgumentException ex) {
        assertEquals(ex.getMessage(), "Component Foo.bar does not contain a stored render variable with name 'fred'.  Stored render variables: (none).");
    }
    verify();
}
Also used : InternalComponentResources(org.apache.tapestry5.internal.InternalComponentResources) ComponentModel(org.apache.tapestry5.model.ComponentModel) Instantiator(org.apache.tapestry5.internal.services.Instantiator) Component(org.apache.tapestry5.runtime.Component) Test(org.testng.annotations.Test)

Example 20 with ComponentModel

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

the class InternalComponentResourcesImplTest method get_property_name.

@Test
public void get_property_name() {
    Component component = mockComponent();
    Instantiator ins = mockInstantiator(component);
    ComponentModel model = mockComponentModel();
    ComponentPageElement element = mockComponentPageElement();
    Page page = mockPage();
    Binding binding = mockBinding();
    train_getModel(ins, model);
    replay();
    InternalComponentResources resources = new InternalComponentResourcesImpl(page, element, null, null, null, null, ins, false);
    resources.bindParameter("bar", binding);
    assertNull(resources.getPropertyName("bar"));
    verify();
}
Also used : Binding(org.apache.tapestry5.Binding) InternalPropBinding(org.apache.tapestry5.internal.bindings.InternalPropBinding) InternalComponentResources(org.apache.tapestry5.internal.InternalComponentResources) ComponentModel(org.apache.tapestry5.model.ComponentModel) Instantiator(org.apache.tapestry5.internal.services.Instantiator) Component(org.apache.tapestry5.runtime.Component) Test(org.testng.annotations.Test)

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