1 15 package org.apache.tapestry.vlib.pages.admin; 16 17 import java.rmi.RemoteException ; 18 import java.util.List ; 19 20 import javax.ejb.FinderException ; 21 import javax.ejb.RemoveException ; 22 23 import org.apache.hivemind.ApplicationRuntimeException; 24 import org.apache.tapestry.IRequestCycle; 25 import org.apache.tapestry.PageRedirectException; 26 import org.apache.tapestry.Tapestry; 27 import org.apache.tapestry.event.PageEvent; 28 import org.apache.tapestry.event.PageRenderListener; 29 import org.apache.tapestry.form.ListEditMap; 30 import org.apache.tapestry.vlib.AdminPage; 31 import org.apache.tapestry.vlib.VirtualLibraryEngine; 32 import org.apache.tapestry.vlib.ejb.IOperations; 33 import org.apache.tapestry.vlib.ejb.Publisher; 34 35 43 44 public abstract class EditPublishers extends AdminPage implements PageRenderListener 45 { 46 public abstract ListEditMap getListEditMap(); 47 48 public abstract void setListEditMap(ListEditMap listEditMap); 49 50 public abstract Publisher getPublisher(); 51 52 public abstract void setPublisher(Publisher publisher); 53 54 public void synchronizePublisher(IRequestCycle cycle) 55 { 56 ListEditMap map = getListEditMap(); 57 58 Publisher publisher = (Publisher) map.getValue(); 59 60 if (publisher == null) 61 { 62 setError(getMessage("out-of-date")); 63 throw new PageRedirectException(this); 64 } 65 66 setPublisher(publisher); 67 } 68 69 75 76 private void readPublishers() 77 { 78 VirtualLibraryEngine vengine = (VirtualLibraryEngine) getEngine(); 79 Publisher[] publishers = null; 80 81 int i = 0; 82 while (true) 83 { 84 try 85 { 86 IOperations operations = vengine.getOperations(); 87 88 publishers = operations.getPublishers(); 89 90 break; 91 } 92 catch (RemoteException ex) 93 { 94 vengine.rmiFailure(getMessage("read-failure"), ex, i++); 95 } 96 } 97 98 ListEditMap map = new ListEditMap(); 99 100 int count = Tapestry.size(publishers); 101 102 for (i = 0; i < count; i++) 103 map.add(publishers[i].getId(), publishers[i]); 104 105 setListEditMap(map); 106 } 107 108 public void processForm(IRequestCycle cycle) 109 { 110 if (isInError()) 111 return; 112 113 ListEditMap map = getListEditMap(); 114 List updateList = map.getValues(); 115 List deletedIds = map.getDeletedKeys(); 116 117 Publisher[] updated = (Publisher[]) updateList.toArray(new Publisher[updateList.size()]); 118 119 Integer [] deleted = 120 deletedIds == null 121 ? null 122 : (Integer []) deletedIds.toArray(new Integer [deletedIds.size()]); 123 124 126 VirtualLibraryEngine vengine = (VirtualLibraryEngine) getEngine(); 127 128 int i = 0; 129 while (true) 130 { 131 try 132 { 133 IOperations operations = vengine.getOperations(); 134 135 operations.updatePublishers(updated, deleted); 136 137 break; 138 } 139 catch (FinderException ex) 140 { 141 throw new ApplicationRuntimeException(ex); 142 } 143 catch (RemoveException ex) 144 { 145 throw new ApplicationRuntimeException(ex); 146 } 147 catch (RemoteException ex) 148 { 149 vengine.rmiFailure(getMessage("update-failure"), ex, i++); 150 } 151 } 152 153 155 vengine.clearCache(); 156 } 157 158 public void pageBeginRender(PageEvent event) 159 { 160 readPublishers(); 161 } 162 163 } | Popular Tags |