| // Copyright 2008 The Apache Software Foundation |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| package org.apache.tapestry.services; |
| |
| import org.apache.tapestry.EventContext; |
| import org.apache.tapestry.ioc.internal.util.Defense; |
| |
| /** |
| * Encapsulates all the information that may be provided in a component event request URL. |
| */ |
| public final class ComponentEventRequestParameters |
| { |
| private final String activePageName, containingPageName, nestedComponentId, eventType; |
| private final EventContext pageActivationContext, eventContext; |
| |
| public ComponentEventRequestParameters(String activePageName, String containingPageName, String nestedComponentId, |
| String eventType, EventContext pageActivationContext, |
| EventContext eventContext) |
| { |
| Defense.notBlank(activePageName, "activePageName"); |
| Defense.notBlank(containingPageName, "containingPageName"); |
| Defense.notNull(nestedComponentId, "nestedComponentId"); |
| Defense.notBlank(eventType, "eventType"); |
| Defense.notNull(pageActivationContext, "pageActivationContext"); |
| Defense.notNull(eventContext, "eventContext"); |
| |
| this.activePageName = activePageName; |
| this.containingPageName = containingPageName; |
| this.nestedComponentId = nestedComponentId; |
| this.eventType = eventType; |
| this.pageActivationContext = pageActivationContext; |
| this.eventContext = eventContext; |
| } |
| |
| // Implements equals() as a convienience for testing. |
| |
| public boolean equals(Object o) |
| { |
| if (this == o) return true; |
| if (o == null || getClass() != o.getClass()) return false; |
| |
| ComponentEventRequestParameters that = (ComponentEventRequestParameters) o; |
| |
| if (!activePageName.equals(that.activePageName)) return false; |
| if (!containingPageName.equals(that.containingPageName)) return false; |
| if (!eventType.equals(that.eventType)) return false; |
| if (!nestedComponentId.equals(that.nestedComponentId)) return false; |
| |
| if (!isEqual(eventContext, that.eventContext)) return false; |
| |
| return isEqual(pageActivationContext, that.pageActivationContext); |
| } |
| |
| private boolean isEqual(EventContext left, EventContext right) |
| { |
| if (left == right) return true; |
| |
| int count = left.getCount(); |
| |
| if (count != right.getCount()) return false; |
| |
| for (int i = 0; i < count; i++) |
| { |
| if (!left.get(Object.class, i).equals(right.get(Object.class, i))) |
| return false; |
| } |
| |
| return true; |
| } |
| |
| |
| /** |
| * The name of the active page which rendered the link. This is usually, but not always, the page which contains |
| * the component. |
| */ |
| public String getActivePageName() |
| { |
| return activePageName; |
| } |
| |
| /** |
| * The name of the page containing the component that was triggered. Usually this is the same as the active page, |
| * but because of {@link org.apache.tapestry.Block} and similar constructs, a component from other than the active |
| * page may be rendered with the active page. |
| */ |
| public String getContainingPageName() |
| { |
| return containingPageName; |
| } |
| |
| /** |
| * The path from the containing page down to the component in question. This may be the empty string if the action |
| * request is routed directly to the page rather than a component. |
| */ |
| public String getNestedComponentId() |
| { |
| return nestedComponentId; |
| } |
| |
| /** |
| * The type of event. When not specified in the URL, a default type of "action" ({@link |
| * org.apache.tapestry.EventConstants#ACTION}) is provided. |
| */ |
| public String getEventType() |
| { |
| return eventType; |
| } |
| |
| /** |
| * The activation context for the <em>active page</em>, possibly empty (but not null). |
| * |
| * @see org.apache.tapestry.ComponentResourcesCommon#triggerContextEvent(String, org.apache.tapestry.EventContext, |
| * org.apache.tapestry.ComponentEventCallback) |
| */ |
| public EventContext getPageActivationContext() |
| { |
| return pageActivationContext; |
| } |
| |
| /** |
| * The event context information passed in the URL. Possibly empty (not not null). |
| * |
| * @see org.apache.tapestry.ComponentResourcesCommon#triggerContextEvent(String, org.apache.tapestry.EventContext, |
| * org.apache.tapestry.ComponentEventCallback) |
| */ |
| public EventContext getEventContext() |
| { |
| return eventContext; |
| } |
| } |