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 2:05:16
6    */
7   package org.asyrinx.joey.tapestry.components.entity;
8   
9   import org.apache.tapestry.ApplicationRuntimeException;
10  import org.apache.tapestry.IRequestCycle;
11  import org.asyrinx.brownie.core.lang.ClassUtils;
12  import org.asyrinx.joey.tapestry.page.EntityPageDictionary;
13  
14  /***
15   * @author takeshi
16   */
17  public abstract class EntityCreationLink extends AbstractEntityActionLink implements EntityPagingAction {
18  
19      public abstract EntityPageDictionary getDetailPageDictionary();
20  
21      public abstract String getDetailPageDictionaryName();
22  
23      public abstract String getDetailPageName();
24  
25      private final EntityPagingStrategy pagingStrategy = new EntityPagingStrategy(this);
26  
27      public abstract Class getEntityClass();
28  
29      /***
30       * @param cycle
31       */
32      protected void doAction(IRequestCycle cycle) {
33          final Object entity = deserialize(cycle);
34          pagingStrategy.showEntity(cycle, entity);
35      }
36  
37      /***
38       * @param cycle
39       * @return
40       */
41      protected Object deserialize(IRequestCycle cycle) {
42          final Object[] parameters = cycle.getServiceParameters();
43          final String entityClassName = (String) parameters[0];
44          final Object entity;
45          try {
46              entity = ClassUtils.newObject(entityClassName, null);
47          } catch (InstantiationException e) {
48              throw new ApplicationRuntimeException(e);
49          }
50          return entity;
51      }
52  
53      protected Object[] serialize() {
54          return new Object[] { getEntityClass().getName() };
55      }
56  
57  }