View Javadoc

1   /*
2    * joey-rt and its relative products are published under the terms
3    * of the Apache Software License.
4    * 
5    * Created on 2004/12/13 1:29:35
6    */
7   package org.asyrinx.joey.tapestry.components.entity;
8   
9   import org.apache.commons.lang.StringUtils;
10  import org.apache.tapestry.ApplicationRuntimeException;
11  import org.apache.tapestry.BaseComponent;
12  import org.apache.tapestry.IRequestCycle;
13  import org.asyrinx.brownie.seasar.tapestry.S2AppEngine;
14  import org.asyrinx.joey.entity.service.EntityServiceDispatcher;
15  import org.seasar.framework.container.S2Container;
16  
17  /***
18   * @author takeshi
19   */
20  public abstract class AbstractEntityActionLink extends BaseComponent {
21  
22      public abstract EntityServiceDispatcher getEntityServiceDispatcher();
23  
24      public abstract String getEntityServiceDispatcherName();
25  
26      //public abstract IActionListener getListener();
27  
28      public S2Container getS2Container() {
29          if (!(getPage().getEngine() instanceof S2AppEngine))
30              throw new ApplicationRuntimeException("EntityDetailLink must work with " + S2AppEngine.class.getName());
31          final S2AppEngine engine = (S2AppEngine) getPage().getEngine();
32          final S2Container result = engine.getContainer();
33          if (result == null)
34              throw new ApplicationRuntimeException("S2Container was not found in global object.");
35          return result;
36      }
37  
38      private EntityServiceDispatcher dispatcher = null;
39  
40      public EntityServiceDispatcher getDispatcher() {
41          EntityServiceDispatcher result = getEntityServiceDispatcher();
42          if (result != null)
43              return result;
44          if (this.dispatcher != null)
45              return this.dispatcher;
46          if (!StringUtils.isEmpty(getEntityServiceDispatcherName())) {
47              result = (EntityServiceDispatcher) getS2Container().getComponent(getEntityServiceDispatcherName());
48              if (result != null)
49                  return result;
50          }
51          result = (EntityServiceDispatcher) getS2Container().getComponent(EntityServiceDispatcher.class);
52          if (result == null)
53              throw new ApplicationRuntimeException("Component was not found. '" + getEntityServiceDispatcherName()
54                      + "'.");
55          return result;
56      }
57  
58      public void linkAction(IRequestCycle cycle) {
59          //        if (getListener() != null) {
60          //            getListener().actionTriggered(this, cycle);
61          //            return;
62          //        }
63          doAction(cycle);
64      }
65  
66      protected abstract void doAction(IRequestCycle cycle);
67  
68      /***
69       * @param cycle
70       * @return
71       */
72      protected abstract Object deserialize(IRequestCycle cycle);
73  
74      protected abstract Object[] serialize();
75  
76      public Object[] getEntityParameter() {
77          return serialize();
78      }
79  
80  }