001    // Copyright 2008, 2009 The Apache Software Foundation
002    //
003    // Licensed under the Apache License, Version 2.0 (the "License");
004    // you may not use this file except in compliance with the License.
005    // You may obtain a copy of the License at
006    //
007    //     http://www.apache.org/licenses/LICENSE-2.0
008    //
009    // Unless required by applicable law or agreed to in writing, software
010    // distributed under the License is distributed on an "AS IS" BASIS,
011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012    // See the License for the specific language governing permissions and
013    // limitations under the License.
014    
015    package org.apache.tapestry5.services;
016    
017    import org.apache.tapestry5.EventContext;
018    import org.apache.tapestry5.internal.TapestryInternalUtils;
019    import org.apache.tapestry5.ioc.internal.util.Defense;
020    
021    /**
022     * Encapsulates all the information that may be provided in a component event request URL.
023     */
024    public final class ComponentEventRequestParameters
025    {
026        private final String activePageName, containingPageName, nestedComponentId, eventType;
027        private final EventContext pageActivationContext, eventContext;
028    
029        public ComponentEventRequestParameters(String activePageName, String containingPageName, String nestedComponentId,
030                                               String eventType, EventContext pageActivationContext,
031                                               EventContext eventContext)
032        {
033            Defense.notBlank(activePageName, "activePageName");
034            Defense.notBlank(containingPageName, "containingPageName");
035            Defense.notNull(nestedComponentId, "nestedComponentId");
036            Defense.notBlank(eventType, "eventType");
037            Defense.notNull(pageActivationContext, "pageActivationContext");
038            Defense.notNull(eventContext, "eventContext");
039    
040            this.activePageName = activePageName;
041            this.containingPageName = containingPageName;
042            this.nestedComponentId = nestedComponentId;
043            this.eventType = eventType;
044            this.pageActivationContext = pageActivationContext;
045            this.eventContext = eventContext;
046        }
047    
048        @Override
049        public String toString()
050        {
051            return String.format("ComponentEventParameters[page=%s component=%s:%s event=%s]",
052                                 activePageName,
053                                 containingPageName, nestedComponentId,
054                                 eventType);
055        }
056    
057        // Implements equals() as a convienience for testing.
058    
059        public boolean equals(Object o)
060        {
061            if (this == o) return true;
062            if (o == null || getClass() != o.getClass()) return false;
063    
064            ComponentEventRequestParameters that = (ComponentEventRequestParameters) o;
065    
066            if (!activePageName.equals(that.activePageName)) return false;
067            if (!containingPageName.equals(that.containingPageName)) return false;
068            if (!eventType.equals(that.eventType)) return false;
069            if (!nestedComponentId.equals(that.nestedComponentId)) return false;
070    
071            if (!TapestryInternalUtils.isEqual(eventContext, that.eventContext)) return false;
072    
073            return TapestryInternalUtils.isEqual(pageActivationContext, that.pageActivationContext);
074        }
075    
076    
077        /**
078         * The name of the active page which rendered the link.  This is usually, but not always, the page which contains
079         * the component.
080         */
081        public String getActivePageName()
082        {
083            return activePageName;
084        }
085    
086        /**
087         * The name of the page containing the component that was triggered. Usually this is the same as the active page,
088         * but because of {@link org.apache.tapestry5.Block} and similar constructs, a component from other than the active
089         * page may be rendered with the active page.
090         */
091        public String getContainingPageName()
092        {
093            return containingPageName;
094        }
095    
096        /**
097         * The path from the containing page down to the component in question. This may be the empty string if the action
098         * request is routed directly to the page rather than a component.
099         */
100        public String getNestedComponentId()
101        {
102            return nestedComponentId;
103        }
104    
105        /**
106         * The type of event.  When not specified in the URL, a default type of "action" ({@link
107         * org.apache.tapestry5.EventConstants#ACTION}) is provided.
108         */
109        public String getEventType()
110        {
111            return eventType;
112        }
113    
114        /**
115         * The activation context for the <em>active page</em>, possibly empty (but not null).
116         *
117         * @see org.apache.tapestry5.ComponentResourcesCommon#triggerContextEvent(String, org.apache.tapestry5.EventContext,
118         *      org.apache.tapestry5.ComponentEventCallback)
119         */
120        public EventContext getPageActivationContext()
121        {
122            return pageActivationContext;
123        }
124    
125        /**
126         * The event context information passed in the URL.  Possibly empty (not not null).
127         *
128         * @see org.apache.tapestry5.ComponentResourcesCommon#triggerContextEvent(String, org.apache.tapestry5.EventContext,
129         *      org.apache.tapestry5.ComponentEventCallback)
130         */
131        public EventContext getEventContext()
132        {
133            return eventContext;
134        }
135    }