001    // Copyright 2008, 2009, 2010 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.InternalUtils;
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            assert InternalUtils.isNonBlank(activePageName);
034            assert InternalUtils.isNonBlank(containingPageName);
035            assert nestedComponentId != null;
036            assert InternalUtils.isNonBlank(eventType);
037            assert pageActivationContext != null;
038            assert eventContext != null;
039            this.activePageName = activePageName;
040            this.containingPageName = containingPageName;
041            this.nestedComponentId = nestedComponentId;
042            this.eventType = eventType;
043            this.pageActivationContext = pageActivationContext;
044            this.eventContext = eventContext;
045        }
046    
047        @Override
048        public String toString()
049        {
050            return String.format("ComponentEventParameters[page=%s component=%s:%s event=%s]",
051                                 activePageName,
052                                 containingPageName, nestedComponentId,
053                                 eventType);
054        }
055    
056        // Implements equals() as a convienience for testing.
057    
058        public boolean equals(Object o)
059        {
060            if (this == o) return true;
061            if (o == null || getClass() != o.getClass()) return false;
062    
063            ComponentEventRequestParameters that = (ComponentEventRequestParameters) o;
064    
065            if (!activePageName.equals(that.activePageName)) return false;
066            if (!containingPageName.equals(that.containingPageName)) return false;
067            if (!eventType.equals(that.eventType)) return false;
068            if (!nestedComponentId.equals(that.nestedComponentId)) return false;
069    
070            if (!TapestryInternalUtils.isEqual(eventContext, that.eventContext)) return false;
071    
072            return TapestryInternalUtils.isEqual(pageActivationContext, that.pageActivationContext);
073        }
074    
075    
076        /**
077         * The name of the active page which rendered the link.  This is usually, but not always, the page which contains
078         * the component.
079         * 
080         * @return {@link ComponentClassResolver#canonicalizePageName(String) canonicalized} page name
081         */
082        public String getActivePageName()
083        {
084            return activePageName;
085        }
086    
087        /**
088         * The name of the page containing the component that was triggered. Usually this is the same as the active page,
089         * but because of {@link org.apache.tapestry5.Block} and similar constructs, a component from other than the active
090         * page may be rendered with the active page.
091         * 
092         * @return {@link ComponentClassResolver#canonicalizePageName(String) canonicalized} page name
093         */
094        public String getContainingPageName()
095        {
096            return containingPageName;
097        }
098    
099        /**
100         * The path from the containing page down to the component in question. This may be the empty string if the action
101         * request is routed directly to the page rather than a component.
102         */
103        public String getNestedComponentId()
104        {
105            return nestedComponentId;
106        }
107    
108        /**
109         * The type of event.  When not specified in the URL, a default type of "action" ({@link
110         * org.apache.tapestry5.EventConstants#ACTION}) is provided.
111         */
112        public String getEventType()
113        {
114            return eventType;
115        }
116    
117        /**
118         * The activation context for the <em>active page</em>, possibly empty (but not null).
119         *
120         * @see org.apache.tapestry5.ComponentResourcesCommon#triggerContextEvent(String, org.apache.tapestry5.EventContext,
121         *      org.apache.tapestry5.ComponentEventCallback)
122         */
123        public EventContext getPageActivationContext()
124        {
125            return pageActivationContext;
126        }
127    
128        /**
129         * The event context information passed in the URL.  Possibly empty (not not null).
130         *
131         * @see org.apache.tapestry5.ComponentResourcesCommon#triggerContextEvent(String, org.apache.tapestry5.EventContext,
132         *      org.apache.tapestry5.ComponentEventCallback)
133         */
134        public EventContext getEventContext()
135        {
136            return eventContext;
137        }
138    }