1 7 package org.jboss.test.foedeployer.ejb.m2mb; 8 9 import java.sql.Date ; 10 import java.util.Collection ; 11 import java.util.HashSet ; 12 import java.util.Set ; 13 import java.util.Iterator ; 14 import java.util.ArrayList ; 15 16 import java.rmi.RemoteException ; 17 18 import javax.ejb.SessionBean ; 19 import javax.ejb.SessionContext ; 20 import javax.ejb.EJBException ; 21 import javax.ejb.CreateException ; 22 import javax.ejb.FinderException ; 23 import javax.ejb.RemoveException ; 24 25 import javax.naming.Context ; 26 import javax.naming.InitialContext ; 27 import javax.naming.NamingException ; 28 29 import javax.rmi.PortableRemoteObject ; 30 31 import org.apache.log4j.Category; 32 33 52 public class M2MBManagerBean 53 implements SessionBean 54 { 55 static Category log = Category.getInstance( M2MBManagerBean.class ); 57 58 static String PROJECT_NAME = "java:comp/env/ejb/Project"; 59 static String DEVELOPER_NAME = "java:comp/env/ejb/Developer"; 60 61 private ProjectLocalHome projectHome; 62 private DeveloperLocalHome developerHome; 63 64 70 public void createProject( String projectName ) 71 { 72 try 73 { 74 projectHome.create( projectName ); 75 } 76 catch( CreateException ce ) 77 { 78 throw new EJBException ( ce ); 79 } 80 } 81 82 87 public void createDeveloper( String developerName ) 88 { 89 try 90 { 91 developerHome.create( developerName ); 92 } 93 catch( CreateException ce ) 94 { 95 throw new EJBException ( ce ); 96 } 97 } 98 99 104 public Collection getDevelopersForProject( String projectName ) 105 { 106 try 107 { 108 ProjectLocal project = projectHome.findByPrimaryKey( projectName ); 109 Collection devs = new ArrayList (); 110 for(Iterator iter=project.getDevelopers().iterator(); iter.hasNext();) 111 { 112 DeveloperLocal developer = (DeveloperLocal) iter.next(); 113 devs.add( developer.getName() ); 114 } 115 return devs; 116 } 117 catch( FinderException fe ) 118 { 119 throw new EJBException ( fe ); 120 } 121 } 122 123 128 public Collection getProjectsForDeveloper( String developerName ) 129 { 130 try 131 { 132 DeveloperLocal developer = developerHome.findByPrimaryKey( developerName ); 133 Collection prjs = new ArrayList (); 134 for(Iterator iter=developer.getProjects().iterator(); iter.hasNext();) 135 { 136 ProjectLocal project = (ProjectLocal) iter.next(); 137 prjs.add( project.getName() ); 138 } 139 return prjs; 140 } 141 catch( FinderException fe ) 142 { 143 throw new EJBException ( fe ); 144 } 145 } 146 147 148 153 public void addProjectToDeveloper( String developerName, 154 String projectName ) 155 { 156 try 157 { 158 DeveloperLocal dev = developerHome.findByPrimaryKey( developerName ); 159 ProjectLocal prj = projectHome.findByPrimaryKey( projectName ); 160 dev.getProjects().add( prj ); 161 } 162 catch( Exception e ) 163 { 164 throw new EJBException ( e ); 165 } 166 } 167 168 173 public void addDeveloperToProject( String projectName, 174 String developerName ) 175 { 176 try 177 { 178 DeveloperLocal dev = developerHome.findByPrimaryKey( developerName ); 179 ProjectLocal prj = projectHome.findByPrimaryKey( projectName ); 180 prj.getDevelopers().add( dev ); 181 } 182 catch( Exception e ) 183 { 184 throw new EJBException ( e ); 185 } 186 } 187 188 193 public void removeProjectIfExists( String projectName ) 194 { 195 try 196 { 197 ProjectLocal project = projectHome.findByPrimaryKey( projectName ); 198 project.remove(); 199 } 200 catch( Exception e ) 201 { 202 } 204 } 205 206 211 public void removeDeveloperIfExists( String developerName ) 212 { 213 try 214 { 215 DeveloperLocal developer = developerHome.findByPrimaryKey( developerName ); 216 developer.remove(); 217 } 218 catch( Exception e ) 219 { 220 } 222 } 223 224 225 227 public void setSessionContext(SessionContext c) 228 { 229 try 230 { 231 Context ic = new InitialContext (); 232 developerHome = (DeveloperLocalHome)ic.lookup(DEVELOPER_NAME); 233 projectHome = (ProjectLocalHome)ic.lookup(PROJECT_NAME); 234 } 235 catch(NamingException ne) 236 { 237 throw new EJBException (ne); 238 } 239 } 240 241 246 public void ejbCreate() { } 247 public void ejbActivate() { } 248 public void ejbPassivate() { } 249 public void ejbRemove() { } 250 } 251 | Popular Tags |