use of org.apache.tapestry5.internal.structure.ComponentPageElement in project tapestry-5 by apache.
the class PageLoaderImpl method connectInheritedParameter.
private void connectInheritedParameter(ComponentPageElement container, ComponentPageElement embedded, String parameterName, String containerParameterName) {
// TODO: This assumes that the two parameters are both on the core component and not on
// a mixin. I think this could be improved with more static analysis.
Binding containerBinding = container.getBinding(containerParameterName);
if (containerBinding == null)
return;
// This helps with debugging, and re-orients any thrown exceptions
// to the location of the inherited binding, rather than the container component's
// binding.
// Binding inherited = new InheritedBinding(description, containerBinding, embedded.getLocation());
embedded.bindParameter(parameterName, containerBinding);
}
use of org.apache.tapestry5.internal.structure.ComponentPageElement in project tapestry-5 by apache.
the class PageLoaderImpl method copyInformalParameters.
private void copyInformalParameters(ComponentPageElement container, ComponentPageElement embedded) {
// TODO: Much more, this is an area where we can make things a bit more efficient by tracking
// what has and hasn't been bound in the EmbeddedComponentAssembler (and identifying what is
// and isn't informal).
ComponentModel model = embedded.getComponentResources().getComponentModel();
Map<String, Binding> informals = container.getInformalParameterBindings();
for (String name : informals.keySet()) {
if (model.getParameterModel(name) != null)
continue;
Binding binding = informals.get(name);
embedded.bindParameter(name, binding);
}
}
use of org.apache.tapestry5.internal.structure.ComponentPageElement in project tapestry-5 by apache.
the class ComponentSourceImpl method getComponent.
public Component getComponent(String completeId) {
assert InternalUtils.isNonBlank(completeId);
int colonx = completeId.indexOf(':');
if (colonx < 0) {
Page page = pageCache.get(completeId);
return page.getRootComponent();
}
String pageName = completeId.substring(0, colonx);
Page page = pageCache.get(pageName);
String nestedId = completeId.substring(colonx + 1);
String mixinId = null;
int dollarx = nestedId.indexOf("$");
if (dollarx > 0) {
mixinId = nestedId.substring(dollarx + 1);
nestedId = nestedId.substring(0, dollarx);
}
ComponentPageElement element = page.getComponentElementByNestedId(nestedId);
if (mixinId == null)
return element.getComponent();
ComponentResources resources = element.getMixinResources(mixinId);
return resources.getComponent();
}
use of org.apache.tapestry5.internal.structure.ComponentPageElement in project tapestry-5 by apache.
the class PageActivationContextCollectorImpl method collectPageActivationContext.
public Object[] collectPageActivationContext(String pageName) {
Boolean hasHandler = cache.get(pageName);
if (hasHandler == null) {
ComponentModel model = modelSource.getPageModel(pageName);
hasHandler = model.handlesEvent(EventConstants.PASSIVATE);
cache.put(pageName, hasHandler);
}
if (!hasHandler)
return EMPTY;
// Get or create a page instance and trigger the event.
Page page = requestPageCache.get(pageName);
ComponentPageElement element = page.getRootElement();
final Holder<Object[]> holder = Holder.create();
ComponentEventCallback callback = new ComponentEventCallback() {
public boolean handleResult(Object result) {
holder.put(typeCoercer.coerce(result, Object[].class));
return true;
}
};
element.triggerEvent(EventConstants.PASSIVATE, null, callback);
if (!holder.hasValue())
return EMPTY;
return holder.get();
}
use of org.apache.tapestry5.internal.structure.ComponentPageElement in project tapestry-5 by apache.
the class PageActivationContextCollectorImplTest method tryWithContext.
private void tryWithContext(String pageName, final Object context, Object... expected) {
ComponentModelSource modelSource = mockComponentModelSource();
RequestPageCache pageCache = mockRequestPageCache();
ComponentPageElement element = mockComponentPageElement();
ComponentModel model = mockComponentModel();
Page page = mockPage();
expect(modelSource.getPageModel(pageName)).andReturn(model);
expect(model.handlesEvent(EventConstants.PASSIVATE)).andReturn(true);
train_get(pageCache, pageName, page);
train_getRootElement(page, element);
IAnswer answer = new IAnswer() {
public Object answer() throws Throwable {
Object[] args = EasyMock.getCurrentArguments();
ComponentEventCallback callback = (ComponentEventCallback) args[2];
return callback.handleResult(context);
}
};
expect(element.triggerEvent(EasyMock.eq(EventConstants.PASSIVATE), (Object[]) EasyMock.isNull(), EasyMock.isA(ComponentEventCallback.class))).andAnswer(answer);
replay();
PageActivationContextCollector collector = new PageActivationContextCollectorImpl(coercer, pageCache, modelSource);
Object[] actual = collector.collectPageActivationContext(pageName);
assertArraysEqual(actual, expected);
}
Aggregations