KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > team > TeamBean


1 package team;
2
3 import javax.ejb.*;
4 import util.*;
5 import java.util.*;
6
7 /**
8  * This is the bean class for the TeamBean enterprise bean.
9  * Created Mar 23, 2005 1:48:50 PM
10  * @author honza
11  */

12 public abstract class TeamBean implements EntityBean, TeamLocalBusiness {
13     private EntityContext context;
14     
15     // <editor-fold defaultstate="collapsed" desc="EJB infrastructure methods. Click on the + sign on the left to edit the code.">
16
// TODO Consider creating Transfer Object to encapsulate data
17
// TODO Review finder methods
18
/**
19      * @see EntityBean#setEntityContext(EntityContext)
20      */

21     public void setEntityContext(EntityContext aContext) {
22         context = aContext;
23     }
24     
25     /**
26      * @see EntityBean#ejbActivate()
27      */

28     public void ejbActivate() {
29         
30     }
31     
32     /**
33      * @see EntityBean#ejbPassivate()
34      */

35     public void ejbPassivate() {
36         
37     }
38     
39     /**
40      * @see EntityBean#ejbRemove()
41      */

42     public void ejbRemove() {
43         
44     }
45     
46     /**
47      * @see EntityBean#unsetEntityContext()
48      */

49     public void unsetEntityContext() {
50         context = null;
51     }
52     
53     /**
54      * @see EntityBean#ejbLoad()
55      */

56     public void ejbLoad() {
57         
58     }
59     
60     /**
61      * @see EntityBean#ejbStore()
62      */

63     public void ejbStore() {
64         
65     }
66     // </editor-fold>
67

68     // <editor-fold desc="CMP fields and relationships.">
69

70     public abstract String JavaDoc getTeamId();
71     public abstract void setTeamId(String JavaDoc id);
72     
73     public abstract String JavaDoc getName();
74     public abstract void setName(String JavaDoc name);
75     
76     public abstract String JavaDoc getCity();
77     public abstract void setCity(String JavaDoc city);
78     
79     // </editor-fold>
80

81     public String JavaDoc ejbCreate(String JavaDoc teamId, String JavaDoc name, String JavaDoc city) throws CreateException {
82         if (teamId == null) {
83             throw new CreateException("The field \"id\" must not be null");
84         }
85        // if (leagueId == null) {
86
// throw new CreateException("The field \"leagueId\" must not be null");
87
//}
88

89         // TODO add additional validation code, throw CreateException if data is not valid
90
setTeamId(teamId);
91         setName(name);
92         setCity(city);
93         
94         return null;
95     }
96     
97     public void ejbPostCreate(String JavaDoc teamId, String JavaDoc name, String JavaDoc city) {
98         // TODO populate relationships here if appropriate
99
//setLeagueId(leagueId);
100

101     }
102     // Business methods
103
public ArrayList getCopyOfPlayers() {
104         Debug.print("TeamBean getCopyOfPlayers");
105
106         ArrayList playerList = new ArrayList();
107         Collection players = getPlayers();
108
109         Iterator i = players.iterator();
110
111         while (i.hasNext()) {
112             PlayerLocal player = (PlayerLocal) i.next();
113             PlayerDetails details =
114                 new PlayerDetails(player.getPlayerId(), player.getName(), player.getPosition(), 0.0);
115
116             playerList.add(details);
117         }
118
119         return playerList;
120     }
121
122     public void addPlayer(PlayerLocal player) {
123         Debug.print("TeamBean addPlayer");
124
125         try {
126             Collection players = getPlayers();
127
128             players.add(player);
129         } catch (Exception JavaDoc ex) {
130             throw new EJBException(ex.getMessage());
131         }
132     }
133
134     public void dropPlayer(PlayerLocal player) {
135         Debug.print("TeamBean dropPlayer");
136
137         try {
138             Collection players = getPlayers();
139
140             players.remove(player);
141         } catch (Exception JavaDoc ex) {
142             throw new EJBException(ex.getMessage());
143         }
144     }
145
146     public abstract Collection getPlayers();
147
148     public abstract void setPlayers(Collection players);
149
150     public abstract LeagueLocal getLeague();
151
152     public abstract void setLeague(LeagueLocal league);
153
154
155
156     
157     
158 }
159
Popular Tags