1 package edu.rice.rubis.beans; 2 3 import java.net.URLEncoder ; 4 import java.rmi.*; 5 import javax.ejb.*; 6 import javax.rmi.PortableRemoteObject ; 7 import javax.naming.InitialContext ; 8 9 23 24 public class CategoryBean implements EntityBean 25 { 26 private EntityContext entityContext; 27 private transient boolean isDirty; 29 30 31 public Integer id; 32 public String name; 33 34 35 41 public Integer getId() throws RemoteException 42 { 43 return id; 44 } 45 46 52 public String getName() throws RemoteException 53 { 54 return name; 55 } 56 57 63 public void setName(String newName) throws RemoteException 64 { 65 name = newName; 66 isDirty = true; } 68 69 70 82 public CategoryPK ejbCreate(String categoryName) throws CreateException, RemoteException, RemoveException 83 { 84 IDManagerHome home = null; 86 IDManager idManager = null; 87 88 try 89 { 90 InitialContext initialContext = new InitialContext (); 91 home = (IDManagerHome)PortableRemoteObject.narrow(initialContext.lookup( 92 "java:comp/env/ejb/IDManager"), IDManagerHome.class); 93 } 94 catch (Exception e) 95 { 96 throw new RemoteException("Cannot lookup IDManager: " +e); 97 } 98 try 99 { 100 IDManagerPK idPK = new IDManagerPK(); 101 idManager = home.findByPrimaryKey(idPK); 102 id = idManager.getNextCategoryID(); 103 name = categoryName; 104 } 105 catch (Exception e) 106 { 107 throw new RemoteException("Cannot create category: " +e); 108 } 109 return null; 110 } 111 112 113 115 public void ejbPostCreate(String categoryName) 116 { 117 isDirty = true; } 119 120 122 public void ejbLoad() throws RemoteException 123 { 124 isDirty = false; 125 } 126 127 129 public void ejbStore() throws RemoteException 130 { 131 isDirty = false; 132 } 133 134 135 public void ejbActivate() throws RemoteException {} 136 137 public void ejbPassivate() throws RemoteException {} 138 139 public void ejbRemove() throws RemoteException, RemoveException {} 140 141 158 public void setEntityContext(EntityContext context) throws RemoteException 159 { 160 entityContext = context; 161 } 162 163 180 public void unsetEntityContext() throws RemoteException 181 { 182 entityContext = null; 183 } 184 185 192 public String printCategory() throws RemoteException 193 { 194 return "<a HREF=\""+BeanConfig.context+"/servlet/edu.rice.rubis.beans.servlets.SearchItemsByCategory?category="+id+ 195 "&categoryName="+URLEncoder.encode(name)+"\">"+name+"</a><br>\n"; 196 } 197 198 205 public String printCategoryByRegion(int regionId) throws RemoteException 206 { 207 return "<a HREF=\""+BeanConfig.context+"/servlet/edu.rice.rubis.beans.servlets.SearchItemsByRegion?category="+id+ 208 "&categoryName="+URLEncoder.encode(name)+"®ion="+regionId+"\">"+name+"</a><br>\n"; 209 } 210 211 212 219 public boolean isModified() 220 { 221 return isDirty; 222 } 223 224 225 232 public String printCategoryToSellItem(int userId) throws RemoteException 233 { 234 return "<a HREF=\""+BeanConfig.context+"/servlet/edu.rice.rubis.beans.servlets.SellItemForm?category="+id+"&user="+userId+"\">"+name+"</a><br>\n"; 235 } 236 } 237 | Popular Tags |