Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
DirectLink |
|
| 1.8888888888888888;1.889 |
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 org.apache.tapestry.*; |
|
18 | import org.apache.tapestry.engine.DirectServiceParameter; |
|
19 | import org.apache.tapestry.engine.IEngineService; |
|
20 | import org.apache.tapestry.engine.ILink; |
|
21 | import org.apache.tapestry.listener.ListenerInvoker; |
|
22 | ||
23 | import java.util.List; |
|
24 | ||
25 | /** |
|
26 | * A component for creating a link using the direct service; used for actions that are not dependant |
|
27 | * on dynamic page state. [ <a href="../../../../../ComponentReference/DirectLink.html">Component |
|
28 | * Reference </a>] |
|
29 | * |
|
30 | */ |
|
31 | ||
32 | 0 | public abstract class DirectLink extends AbstractLinkComponent implements IDirect |
33 | { |
|
34 | public abstract IActionListener getListener(); |
|
35 | ||
36 | /** |
|
37 | * Returns true if the stateful parameter is bound to a true value. If stateful is not bound, |
|
38 | * also returns the default, true. |
|
39 | */ |
|
40 | ||
41 | public abstract boolean isStateful(); |
|
42 | ||
43 | public ILink getLink(IRequestCycle cycle) |
|
44 | { |
|
45 | 0 | Object[] serviceParameters = constructServiceParameters(getParameters()); |
46 | ||
47 | 0 | DirectServiceParameter dsp = new DirectServiceParameter(this, serviceParameters); |
48 | ||
49 | 0 | return getEngine().getLink(isStateful(), dsp); |
50 | } |
|
51 | ||
52 | /** |
|
53 | * Converts a service parameters value to an array of objects. This is used by the |
|
54 | * {@link DirectLink},{@link ServiceLink}and {@link ExternalLink}components. |
|
55 | * |
|
56 | * @param parameterValue |
|
57 | * the input value which may be |
|
58 | * <ul> |
|
59 | * <li>null (returns null) |
|
60 | * <li>An array of Object (returns the array) |
|
61 | * <li>A {@link List}(returns an array of the values in the List}) |
|
62 | * <li>A single object (returns the object as a single-element array) |
|
63 | * </ul> |
|
64 | * @return An array representation of the input object. |
|
65 | * @since 2.2 |
|
66 | */ |
|
67 | ||
68 | public static Object[] constructServiceParameters(Object parameterValue) |
|
69 | { |
|
70 | 4 | if (parameterValue == null) |
71 | 2 | return null; |
72 | ||
73 | 2 | if (parameterValue instanceof Object[]) |
74 | 2 | return (Object[]) parameterValue; |
75 | ||
76 | 0 | if (parameterValue instanceof List) |
77 | { |
|
78 | 0 | List list = (List) parameterValue; |
79 | ||
80 | 0 | return list.toArray(); |
81 | } |
|
82 | ||
83 | 0 | return new Object[] { parameterValue }; |
84 | } |
|
85 | ||
86 | /** |
|
87 | * Invoked by the direct service to trigger the application-specific action by notifying the |
|
88 | * {@link IActionListener listener}. |
|
89 | * |
|
90 | * @throws org.apache.tapestry.StaleSessionException |
|
91 | * if the component is stateful, and the session is new. |
|
92 | */ |
|
93 | ||
94 | public void trigger(IRequestCycle cycle) |
|
95 | { |
|
96 | 0 | IActionListener listener = getListener(); |
97 | ||
98 | 0 | if (listener == null) |
99 | 0 | throw Tapestry.createRequiredParameterException(this, "listener"); |
100 | ||
101 | 0 | getListenerInvoker().invokeListener(listener, this, cycle); |
102 | 0 | } |
103 | ||
104 | /** @since 2.2 * */ |
|
105 | ||
106 | public abstract Object getParameters(); |
|
107 | ||
108 | /** |
|
109 | * Injected. |
|
110 | * |
|
111 | * @since 4.0 |
|
112 | */ |
|
113 | ||
114 | public abstract ListenerInvoker getListenerInvoker(); |
|
115 | ||
116 | /** |
|
117 | * Injected. |
|
118 | * |
|
119 | * @since 4.1 |
|
120 | */ |
|
121 | public abstract IEngineService getEngine(); |
|
122 | ||
123 | /** |
|
124 | * Injected. |
|
125 | * @return The script to process asynchronous connection hookups. |
|
126 | */ |
|
127 | public abstract IScript getScript(); |
|
128 | } |