1 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.Tapestry; 23 import org.apache.tapestry.engine.DirectServiceParameter; 24 import org.apache.tapestry.engine.ILink; 25 import org.apache.tapestry.listener.ListenerInvoker; 26 27 34 35 public abstract class DirectLink extends AbstractLinkComponent implements IDirect 36 { 37 public abstract IActionListener getListener(); 38 39 43 44 public abstract boolean isStateful(); 45 46 public ILink getLink(IRequestCycle cycle) 47 { 48 Object [] serviceParameters = constructServiceParameters(getParameters()); 49 50 DirectServiceParameter dsp = new DirectServiceParameter(this, serviceParameters); 51 52 return getLink(cycle, Tapestry.DIRECT_SERVICE, dsp); 53 } 54 55 70 71 public static Object [] constructServiceParameters(Object parameterValue) 72 { 73 if (parameterValue == null) 74 return null; 75 76 if (parameterValue instanceof Object []) 77 return (Object []) parameterValue; 78 79 if (parameterValue instanceof List ) 80 { 81 List list = (List ) parameterValue; 82 83 return list.toArray(); 84 } 85 86 return new Object [] 87 { parameterValue }; 88 } 89 90 97 98 public void trigger(IRequestCycle cycle) 99 { 100 IActionListener listener = getListener(); 101 102 if (listener == null) 103 throw Tapestry.createRequiredParameterException(this, "listener"); 104 105 getListenerInvoker().invokeListener(listener, this, cycle); 106 } 107 108 109 110 public abstract Object getParameters(); 111 112 117 118 public abstract ListenerInvoker getListenerInvoker(); 119 } | Popular Tags |