Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
DirectLink |
|
| 1.7777777777777777;1.778 |
1 | // Copyright 2004, 2005 The Apache Software Foundation |
|
2 | // |
|
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
|
4 | // you may not use this file except in compliance with the License. |
|
5 | // You may obtain a copy of the License at |
|
6 | // |
|
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
|
8 | // |
|
9 | // Unless required by applicable law or agreed to in writing, software |
|
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
12 | // See the License for the specific language governing permissions and |
|
13 | // limitations under the License. |
|
14 | ||
15 | package org.apache.tapestry.link; |
|
16 | ||
17 | import java.util.List; |
|
18 | ||
19 | import org.apache.tapestry.IActionListener; |
|
20 | import org.apache.tapestry.IDirect; |
|
21 | import org.apache.tapestry.IRequestCycle; |
|
22 | import org.apache.tapestry.IScript; |
|
23 | import org.apache.tapestry.engine.DirectServiceParameter; |
|
24 | import org.apache.tapestry.engine.IEngineService; |
|
25 | import org.apache.tapestry.engine.ILink; |
|
26 | import org.apache.tapestry.listener.ListenerInvoker; |
|
27 | ||
28 | /** |
|
29 | * A component for creating a link using the direct service; used for actions that are not dependant |
|
30 | * on dynamic page state. [ <a href="../../../../../ComponentReference/DirectLink.html">Component |
|
31 | * Reference </a>] |
|
32 | * |
|
33 | */ |
|
34 | ||
35 | 0 | public abstract class DirectLink extends AbstractLinkComponent implements IDirect |
36 | { |
|
37 | public abstract IActionListener getListener(); |
|
38 | ||
39 | /** |
|
40 | * Returns true if the stateful parameter is bound to a true value. If stateful is not bound, |
|
41 | * also returns the default, true. |
|
42 | */ |
|
43 | ||
44 | public abstract boolean isStateful(); |
|
45 | ||
46 | public ILink getLink(IRequestCycle cycle) |
|
47 | { |
|
48 | 0 | Object[] serviceParameters = constructServiceParameters(getParameters()); |
49 | ||
50 | 0 | DirectServiceParameter dsp = new DirectServiceParameter(this, serviceParameters); |
51 | ||
52 | 0 | return getEngine().getLink(isStateful(), dsp); |
53 | } |
|
54 | ||
55 | /** |
|
56 | * Converts a service parameters value to an array of objects. This is used by the |
|
57 | * {@link DirectLink},{@link ServiceLink}and {@link ExternalLink}components. |
|
58 | * |
|
59 | * @param parameterValue |
|
60 | * the input value which may be |
|
61 | * <ul> |
|
62 | * <li>null (returns null) |
|
63 | * <li>An array of Object (returns the array) |
|
64 | * <li>A {@link List}(returns an array of the values in the List}) |
|
65 | * <li>A single object (returns the object as a single-element array) |
|
66 | * </ul> |
|
67 | * @return An array representation of the input object. |
|
68 | * @since 2.2 |
|
69 | */ |
|
70 | ||
71 | public static Object[] constructServiceParameters(Object parameterValue) |
|
72 | { |
|
73 | 4 | if (parameterValue == null) |
74 | 2 | return null; |
75 | ||
76 | 2 | if (parameterValue instanceof Object[]) |
77 | 2 | return (Object[]) parameterValue; |
78 | ||
79 | 0 | if (parameterValue instanceof List) |
80 | { |
|
81 | 0 | List list = (List) parameterValue; |
82 | ||
83 | 0 | return list.toArray(); |
84 | } |
|
85 | ||
86 | 0 | return new Object[] { parameterValue }; |
87 | } |
|
88 | ||
89 | /** |
|
90 | * Invoked by the direct service to trigger the application-specific action by notifying the |
|
91 | * {@link IActionListener listener}. If the listener parameter is not bound, attempt to locate |
|
92 | * an implicit listener named by the capitalized component id, prefixed by "do". |
|
93 | * |
|
94 | * @throws org.apache.tapestry.StaleSessionException |
|
95 | * if the component is stateful, and the session is new. |
|
96 | */ |
|
97 | ||
98 | public void trigger(IRequestCycle cycle) |
|
99 | { |
|
100 | 0 | IActionListener listener = getListener(); |
101 | ||
102 | 0 | if (listener == null) |
103 | 0 | listener = getContainer().getListeners().getImplicitListener(this); |
104 | ||
105 | 0 | getListenerInvoker().invokeListener(listener, this, cycle); |
106 | 0 | } |
107 | ||
108 | /** @since 2.2 * */ |
|
109 | ||
110 | public abstract Object getParameters(); |
|
111 | ||
112 | /** |
|
113 | * Injected. |
|
114 | * |
|
115 | * @since 4.0 |
|
116 | */ |
|
117 | ||
118 | public abstract ListenerInvoker getListenerInvoker(); |
|
119 | ||
120 | /** |
|
121 | * Injected. |
|
122 | * |
|
123 | * @since 4.1 |
|
124 | */ |
|
125 | public abstract IEngineService getEngine(); |
|
126 | ||
127 | /** |
|
128 | * Injected. |
|
129 | * @return The script to process asynchronous connection hookups. |
|
130 | */ |
|
131 | public abstract IScript getScript(); |
|
132 | } |