001: package team;
002:
003: import javax.ejb.*;
004: import util.*;
005: import java.util.*;
006:
007: /**
008: * This is the bean class for the TeamBean enterprise bean.
009: * Created Mar 23, 2005 1:48:50 PM
010: * @author honza
011: */
012: public abstract class TeamBean implements EntityBean, TeamLocalBusiness {
013: private EntityContext context;
014:
015: // <editor-fold defaultstate="collapsed" desc="EJB infrastructure methods. Click on the + sign on the left to edit the code.">
016: // TODO Consider creating Transfer Object to encapsulate data
017: // TODO Review finder methods
018: /**
019: * @see EntityBean#setEntityContext(EntityContext)
020: */
021: public void setEntityContext(EntityContext aContext) {
022: context = aContext;
023: }
024:
025: /**
026: * @see EntityBean#ejbActivate()
027: */
028: public void ejbActivate() {
029:
030: }
031:
032: /**
033: * @see EntityBean#ejbPassivate()
034: */
035: public void ejbPassivate() {
036:
037: }
038:
039: /**
040: * @see EntityBean#ejbRemove()
041: */
042: public void ejbRemove() {
043:
044: }
045:
046: /**
047: * @see EntityBean#unsetEntityContext()
048: */
049: public void unsetEntityContext() {
050: context = null;
051: }
052:
053: /**
054: * @see EntityBean#ejbLoad()
055: */
056: public void ejbLoad() {
057:
058: }
059:
060: /**
061: * @see EntityBean#ejbStore()
062: */
063: public void ejbStore() {
064:
065: }
066:
067: // </editor-fold>
068:
069: // <editor-fold desc="CMP fields and relationships.">
070:
071: public abstract String getTeamId();
072:
073: public abstract void setTeamId(String id);
074:
075: public abstract String getName();
076:
077: public abstract void setName(String name);
078:
079: public abstract String getCity();
080:
081: public abstract void setCity(String city);
082:
083: // </editor-fold>
084:
085: public String ejbCreate(String teamId, String name, String city)
086: throws CreateException {
087: if (teamId == null) {
088: throw new CreateException(
089: "The field \"id\" must not be null");
090: }
091: // if (leagueId == null) {
092: // throw new CreateException("The field \"leagueId\" must not be null");
093: //}
094:
095: // TODO add additional validation code, throw CreateException if data is not valid
096: setTeamId(teamId);
097: setName(name);
098: setCity(city);
099:
100: return null;
101: }
102:
103: public void ejbPostCreate(String teamId, String name, String city) {
104: // TODO populate relationships here if appropriate
105: //setLeagueId(leagueId);
106:
107: }
108:
109: // Business methods
110: public ArrayList getCopyOfPlayers() {
111: Debug.print("TeamBean getCopyOfPlayers");
112:
113: ArrayList playerList = new ArrayList();
114: Collection players = getPlayers();
115:
116: Iterator i = players.iterator();
117:
118: while (i.hasNext()) {
119: PlayerLocal player = (PlayerLocal) i.next();
120: PlayerDetails details = new PlayerDetails(player
121: .getPlayerId(), player.getName(), player
122: .getPosition(), 0.0);
123:
124: playerList.add(details);
125: }
126:
127: return playerList;
128: }
129:
130: public void addPlayer(PlayerLocal player) {
131: Debug.print("TeamBean addPlayer");
132:
133: try {
134: Collection players = getPlayers();
135:
136: players.add(player);
137: } catch (Exception ex) {
138: throw new EJBException(ex.getMessage());
139: }
140: }
141:
142: public void dropPlayer(PlayerLocal player) {
143: Debug.print("TeamBean dropPlayer");
144:
145: try {
146: Collection players = getPlayers();
147:
148: players.remove(player);
149: } catch (Exception ex) {
150: throw new EJBException(ex.getMessage());
151: }
152: }
153:
154: public abstract Collection getPlayers();
155:
156: public abstract void setPlayers(Collection players);
157:
158: public abstract LeagueLocal getLeague();
159:
160: public abstract void setLeague(LeagueLocal league);
161:
162: }
|